feat(system-config): add magic_link_redirect_uris - #58
Merged
Conversation
seamless-auth-api validates a requested magic link destination against origins, which covers a target whose host is already a WebAuthn origin. It cannot express the two cases that need this key: a custom application scheme such as myapp://auth, and a universal link on a host that should not also be a WebAuthn origin. Exact match, since neither has an origin worth comparing. Empty by default, so a deployment that sets nothing keeps comparing against origins exactly as it does now. Entries are validated with RedirectTargetSchema rather than z.url(), which is stricter on purpose. z.url() accepts anything the URL parser does, including javascript:alert(1) and data:text/html, and a magic link destination is rendered as an href in an email. Stored in config that would be a script-execution sink reachable through the admin system-config API. Denied rather than allowlisted because the point of the key is to permit arbitrary application schemes, which an allowlist of known-good schemes could not express. The patch schema takes the field too, so the guard covers the admin write path and not only what a server seeds at boot.
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.
First link in fells-code/seamless-auth-api#242. That issue is blocked on this key existing here, since
SystemConfigSchemalives in this package.What and why
An exact-match allowlist of destinations a magic link may be sent to, empty by default.
seamless-auth-apialready validates a requested destination, but againstorigins, which is the WebAuthn allowed-origins list. That covers a target whose host is already an origin and cannot express the two cases the feature exists for:myapp://auth/magichttps://links.example.comwhen passkeys are bound toapp.example.comNeither has an origin worth comparing, hence exact match. Empty by default, so a deployment that sets nothing keeps comparing against
originsexactly as it does today and nothing changes for it.The part worth reviewing: not a bare URL check
Entries use a new exported
RedirectTargetSchema, which is deliberately stricter thanz.url(). I checked whatz.url()actually accepts before using it:A magic link destination is rendered as an href in an email. A
javascript:ordata:entry stored in config would therefore be a script-execution sink, reachable by anyone who can write system config through the admin API. A barez.url()would have accepted it.javascript:,data:,vbscript:,file:,blob:andabout:are refused; everything else is allowed. Denied rather than allowlisted because the whole point of the key is to permit arbitrary application schemes, which an allowlist of known-good schemes cannot express.SystemConfigPatchSchematakes the field too, so the guard covers the admin write path and not only what a server seeds at boot. There is a test for both surfaces.Verification
226 tests passing across 16 files, 8 of them new: the default, an application scheme, a non-origin universal link, the three dangerous schemes, a non-URL, and the patch surface.
npm run typecheck,npm run lint,npm run format:checkandnpm run buildall clean.The repo's
schema-exportsconvention test caught thatRedirectTargetSchemaneeded a matchingRedirectTargettype alias, which it now has.What follows
Once this releases, seamless-auth-api#242 consumes the new version and passes the key into
resolveMagicLinkUrl, which already takes an allowlist argument and passes an empty one today purely because there was nothing to read.