feat(sep10-auth): validate middleware options at creation time (closes #39) - #220
Open
dchaudhari7177 wants to merge 1 commit into
Open
Conversation
…stellar-compliance-kit#39) createSep10Middleware accepted VerifyChallengeOptions but never checked them until the first request, so an empty homeDomains or serverAccountId silently 401'd every request with a reason that reads like the CLIENT's challenge was bad rather than the server being misconfigured. assertValidOptions now throws a TypeError from the factory for an empty or blank serverAccountId, and for a homeDomains/webAuthDomain that is empty or contains a blank entry (both the string and array forms). Messages are prefixed "createSep10Middleware: " so the misconfigured call site is obvious. Deliberately only emptiness is checked: whether serverAccountId is a real Stellar key, or a home domain resolves, stays verifyChallenge's business. A test pins that a non-key string is still accepted, so this does not quietly become a second validation layer. No existing test or example passes empty options, so nothing regresses. Note the examples build options from env vars - an unset var now fails at wiring time instead of on every request, which is the intended improvement. Co-Authored-By: Claude Opus 5 <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.
Closes #39.
createSep10MiddlewareacceptedVerifyChallengeOptionsbut never checked them until the first request came in. An emptyhomeDomainsorserverAccountIdsilently 401'd every request — with areasonthat reads like the client's challenge was bad, rather than the server being misconfigured.assertValidOptionsnow throws aTypeErrorfrom the factory for:serverAccountIdhomeDomains/webAuthDomainthat is empty, or contains a blank entry — in both the string and array formsMessages are prefixed
createSep10Middleware:so the misconfigured call site is obvious in the stack.Scope kept narrow on purpose
Only emptiness is checked. Whether
serverAccountIdis a real Stellar key, or a home domain resolves, staysverifyChallenge's business — otherwise this quietly becomes a second, drifting validation layer.test('does not validate the shape of a serverAccountId, only that it is present')pins that a non-key string is still accepted.Blast radius
No existing test or example passes empty options, so nothing regresses (checked every
createSep10Middleware(call site insep10-auth/test,sep10-auth/examples, andexamples/).One behaviour change worth naming:
examples/full-stack-demoandexamples/sep10-sanctions-gatebuild their options from env vars. With this change an unset var throws at wiring time instead of 401ing every request — which is the intended improvement, but it is a startup-time failure where there wasn't one before.npm ciis broken onmainSame blocker as #219:
npm ciandnpm installboth fail on a clean checkout withbecause
e2e-tests/package.jsonuses the pnpm/yarn-onlyworkspace:protocol ande2e-testsis in the rootworkspacesarray. CI onmainhas been red with this since 2026-07-30, so I could not run jest.Instead I transliterated
assertValidOptionsinto plain node and ran the full case matrix — valid options, array forms, empty/blankserverAccountId, empty/blank/blank-entryhomeDomainsandwebAuthDomain, and the non-key-but-present case — confirming all 10 behave as intended and that every thrown error is aTypeErrorwhose message starts withcreateSep10Middleware:.The 11 added jest cases cover the same matrix and should pass once
npm ciworks again.🤖 Generated with Claude Code