Add allowInsecureUri opt-out to return_uri validation - #17
Merged
Conversation
Adds an explicit `ReturnUriOptions { allowInsecureUri?: boolean }` opt-out to
the https requirement on `return_uri`, for local/dev transports (e.g.
http://localhost). The library does not read NODE_ENV; the caller, which owns
its environment, opts in. Threaded through addReturnUri, decodePayload,
detectProofRequirement, and parseX401Payload via a shared assertReturnUri
helper so both sides apply the same rule.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Summary
Adds an explicit opt-out to the
https://requirement onreturn_uri, for local/dev transports (e.g.http://localhost). Prompted by the question of how to relax the check in dev mode.The library does not read
NODE_ENV— that reflects the consumer's runtime, not this library's. Instead, the caller (which owns its environment) passes an explicitReturnUriOptions { allowInsecureUri?: boolean }. This keeps the functions pure and testable without mutatingprocess.env, and leaves the dev/prod policy in the app that owns it.Changes
src/validate.ts— newReturnUriOptionstype and sharedassertReturnUri(returnUri, options)helper (always requires a string; only relaxes thehttps://prefix whenallowInsecureUriis set).parseX401Payloadnow takesoptionsand delegates to it, removing the previously duplicated inline check.src/agent.ts—addReturnUriuses the helper. Threaded the same option through the decode side (decodePayload,detectProofRequirement) so a dev URI actually round-trips.src/index.ts— exportedReturnUriOptionsas a public type.tests/x401.test.ts— round-trip test for anhttp://localhostURI under{ allowInsecureUri: true }, plus a test confirming a non-stringreturn_uriis still rejected even with the flag.Consumer usage
Testing
yarn check-allandyarn testpass (35 tests). No version bump.🤖 Generated with Claude Code