feat(sep10-auth): extract parseBearerToken from the Express middleware (closes #38) - #219
Open
dchaudhari7177 wants to merge 1 commit into
Open
Conversation
closes stellar-compliance-kit#38) The scheme/token split was hand-rolled inside createSep10Middleware, so any consumer wanting the same parsing outside Express (a Fastify or Koa adapter) had to duplicate it. Moved to an exported parseBearerToken(header) in sep10-auth/src and re-exported from the package index. Behaviour is preserved exactly, including the quirks: - scheme matching stays case-sensitive ("bearer" is rejected). RFC 7235 makes auth schemes case-insensitive, so relaxing this would be a genuine improvement - but it widens what authenticates, and that is not a change to smuggle into an extraction. Documented in the helper and pinned by a test. - 'Bearer x' (doubled separator) still reads as an empty token and is rejected, and trailing segments after the token are still ignored. The helper also accepts undefined/null so callers need no `?? ''` pre-check, which is why the middleware now passes req.header('Authorization') straight in. 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 #38.
The
scheme/tokensplit was hand-rolled insidecreateSep10Middleware, so a Fastify or Koa adapter would have had to duplicate it. Now an exportedparseBearerToken(header)insep10-auth/src/bearer.ts, re-exported from the package index.It accepts
undefined/nullso callers need no?? ''pre-check — which is why the middleware now passesreq.header('Authorization')straight in.Behaviour preserved exactly, quirks included
This is an extraction, not a fix, so I kept the existing semantics and documented them rather than quietly improving them:
bearer abcis rejected. RFC 7235 makes auth schemes case-insensitive, so relaxing this would be a real improvement, but it widens what authenticates and that is a security-relevant decision, not something to fold into a refactor. Happy to do it as a follow-up if you want it.Bearer x(doubled separator) still reads as an empty token and is rejected.npm ciis broken onmainWorth raising on its own: CI on
mainhas been failing since 2026-07-30, and it is not related to this PR.e2e-tests/package.jsondeclares"horizon-listener": "workspace:*"and"sanctions-oracle": "workspace:*", ande2e-testsis listed in the rootworkspacesarray. Theworkspace:protocol is a pnpm/yarn feature that npm does not support, sonpm ciandnpm installboth fail on a clean checkout — which also means CONTRIBUTING's documentednpm install && npm testsetup doesn't work today. (Reproduced locally on npm 11.13.0, and it is the exact error in the last CI run onmain.) The fix is probably"*"or"^x.y.z"ine2e-tests/package.json; happy to send that as a separate PR if useful — it would unblock every other PR in the queue.So: I have not executed
sep10-auth/test/bearer.test.ts. I'm not going to claim otherwise. What I did instead was verify the extraction is behaviourally identical to the code it replaces, by running both the old inline split and the new helper over 17 inputs in plain node:'Bearer abc123','Basic abc123','','Bearer','Bearer ',undefined,null,'abc123','bearer abc123','BEARER abc123','Bearer abc123','Bearer abc123 trailing', a real base64 XDR,' Bearer abc','Bearer\tabc','Bearer null','Bearer 0'→ identical result on all 17, so the middleware's observable behaviour is unchanged.
The 9 added jest cases cover the same ground and should pass once
npm ciworks again.🤖 Generated with Claude Code