Repository navigation
capnweb-validate: export isValidationError to tell refusals from other errors - #280
Open
martijnwalraven wants to merge 1 commit into
Open
martijnwalraven wants to merge 1 commit into
martijnwalraven wants to merge 1 commit into
Conversation
…r errors The validator tags every error it throws when it refuses a value or a method missing from a validated surface, but exported nothing that reads the tag, so a server that wants to treat a refused call apart from its own failures (to report it, or to redact everything else) had to match the message prefix, which any error can carry. isValidationError(error) reads the tag, from capnweb-validate and capnweb-validate/capnweb. The tag stays on the error object in the process that refused, so it is readable where Cap'n Web hands a server the error it is about to send, in onSendError, and not on the caller's side, which receives a plain TypeError. It is now a Symbol.for symbol, as the wrapped-method marker already is, so that a second bundled copy of the package recognizes it too.
🦋 Changeset detectedLatest commit: e161971 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
|
I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
Author
|
I have read the CLA Document and I hereby sign the CLA. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
capnweb-validatetags every error it throws when it refuses a value, or a call to a method that a validated surface does not list, but exports nothing that reads the tag. A server that wants to treat a refused call apart from its own failures, to log it as a refusal and redact everything else, has to match the message prefixcapnweb-validate:, which any error can carry, including one a peer sends on purpose.This exports
isValidationError(error)fromcapnweb-validateandcapnweb-validate/capnweb. It reads the tag the validator already sets. The tag stays on the error object in the process that refused, so it is readable where Cap'n Web hands a server the error it is about to send, in a session'sonSendError, and not on the caller's side, which receives a plainTypeErrorwith the message and enumerable properties only. The tag is now aSymbol.forsymbol, as the wrapped-method marker already is, so a second bundled copy of the package recognizes it too; it is not a security boundary, since it never crosses the wire.Tested in
validation-error.test.ts: a refusal and a missing method are told from aTypeErrorwith the same message prefix, and a realMessageChannelsession'sonSendErrorsees the tag while the caller does not. Documented under Validation errors inguides/validation.mdx.Changeset: minor for
capnweb-validate.Context: we hold the untrusted side of a Cap'n Web session in a browser page and log its refusals as refused calls. We met this gap while telling those refusals by the message prefix; our code has since moved to marking the refusals it raises itself, so nothing of ours waits on this, but anyone who uses the package's own class wrapping still has only the prefix to go on.