fix(issuer): validate the credential id before it reaches the query - #153
Open
crazywriter1 wants to merge 1 commit into
Open
fix(issuer): validate the credential id before it reaches the query#153crazywriter1 wants to merge 1 commit into
crazywriter1 wants to merge 1 commit into
Conversation
`GET /credentials/controller/:id` and `GET /credentials/receipts/:id` read the id with `parseInt`. A parameter with no leading digits becomes `NaN`, which reaches the query and fails it, so `/credentials/controller/abc` answers 500 with the failed statement in the response body rather than 404. A parameter with trailing characters keeps its leading digits, so `/1abc`, `/0x1`, `/1e3` and `/1.9` all return credential 1. `status.ts` already parses its route parameter for this reason. Move that parse into `parseIdParam` and use it in all three routes, so the three do not drift apart.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
WalkthroughChangesIssuer ID validation
Estimated code review effort: 3 (Moderate) | ~20 minutes Mergeability Score: ⚪ Minimal · up to The change validates credential route IDs before querying and adds coverage for accepted and rejected inputs; no actionable merge-blocking risk remains beyond normal checks and review. Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
What's wrong
GET /credentials/controller/:idandGET /credentials/receipts/:idread the route parameter withparseInt, and that goes wrong in two directions.An id with no leading digits becomes
NaNand reaches the query, which fails on it. The shared error handler has no branch for a driver error, so it falls through to returning the message verbatim, andGET /credentials/controller/abcanswers 500 with the statement in the body:An id with trailing characters keeps its leading digits, so
/1abc,/0x1,/1e3and/1.9all resolve to credential 1.parseIntreads0x1as hexadecimal and stops at theein1e3, so neither is the number the URL appears to name.Nothing caller-supplied reaches the signed credential —
buildSignedCredentialbuilds the id fromcredential.id— so this is a wrong status code and a wrong row, not a forgery.What changed
status.tsalready parses its route parameter for exactly this reason and says so in a comment. Rather than copy that pipe into two more files, I moved it intoparseIdParamand used it in all three routes. Three copies of a parse that guards a query is how these two fell out of step to begin with.The status route keeps its behaviour: same schema, same
notFoundon a bad parameter, andstatus.test.tspasses untouched.A leading zero is still accepted and normalised, so
/01returns credential 1. That is deliberate: the parsed number is what the handler goes on to use, so the id it builds is canonical either way.Tests
parse-id-param.test.tscovers what the parse accepts and what it rejects, and both route test files gained aGET /:idblock. Reverting only the route change makes six of them fail —abcwith 500 instead of 404, the rest with 200 and the wrong credential.No changeset:
.changeset/config.jsonignores@examples/*.AI usage
Per AI_POLICY.md, Cursor (Claude Opus 5) did the work: it measured the
NaNfailure against a real libsql database, then wrote the fix and the tests. I read the diff before opening this.Summary by CodeRabbit
Bug Fixes
Tests