Repository navigation
fix(server): read a percent-encoded path id as the route does in the demo brand guard - #1963
Merged
Merged
Conversation
…demo brand guard Express hands a route its params decoded, while the demo brand guard read them raw: /content/%34a0…/brief named no id the guard knew, so a session could start a write on the demo brand. The guard now decodes path params the same way, and answers 400 to one that isn't valid percent-encoding, as Express does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… too The acting-member check (ansvisor#1949) reads the brand through the demo brand guard's `brandsNamedBy`, which now throws BadPathParam for a path param that isn't valid percent-encoding. Answer 400 "Invalid path" there as well, instead of a 500. Test: an encoded row id is read as the route reads it (another workspace's brand is refused), and a bad one is a 400. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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
The demo brand guard now reads a percent-encoded path id the way the route does. The guard read the raw param, while Express hands the route the decoded one. For example,
PATCH /api/content/%34a0…/statusreaches the route as4a0…, but the guard'sguidOf('%34a…')found no id, sobrandsNamedBychecked no brand. A normal session could get past the demo brand's read-only guard this way, for example to start AI cost on the demo brand withPOST /content/%xx…/brief. Each route's own access check still stopped any write to another workspace; only the demo guard was skipped. Found in the pre-push security review of #1949.What changes
server/src/middleware/demo-brand.js:valueAtdecodes a path param withdecodeURIComponent. A param that isn't valid percent-encoding throwsBadPathParam, and the guard answers 400 "Invalid path", as Express refuses it too.server/src/middleware/acting-user.js(feat(server): let internal requests act as a member on allowed routes, checked like a session #1949) reads brands through the samebrandsNamedBy, so it gets the same fix. It mapsBadPathParamto 400 there too, instead of a 500.No migration, no web change.
Related issue
None. Follow-up from the security review of #1949.
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
PATCH /api/content/%34a…/status. It is now refused like the plain id (402 for the demo brand).%E0%A4%A: 400 "Invalid path".demo-brand.test.js: an encoded demo brand or row is refused, and a real brand passes.acting-user.test.js: an encoded row id is read as the route reads it (another workspace's brand is refused), and a bad encoding is a 400.Checklist
npm run lintpassesnpm run format:checkpasseshelp/(or no user-visible change)CI passed on this branch (1d6be35), run on the fork (https://github.com/cihan-gyk/ansvisor/actions/runs/41349154341): schema is up to date; web
format:check, lint, typecheck, all tests andyarn buildpass; server lint,format:checkand all tests pass.🤖 Generated with Claude Code