Skip to content

fix(request): verify signed URLs with percent-encoded params - #155

Merged
thetutlage merged 1 commit into
adonisjs:9.xfrom
bardrop-oss:fix/signed-url-encoded-params
Nov 23, 2026
Merged

thetutlage merged 1 commit into
adonisjs:9.xfrom
bardrop-oss:fix/signed-url-encoded-params

Conversation

@bardrop

@bardrop bardrop commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

🔗 Linked issue

Fixes #154

❓ Type of change

  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

createURL runs encodeURIComponent on each route param, so a signed URL for { name: 'my invoice.pdf' } signs /files/my%20invoice.pdf. hasValidSignature() compared that string with this.url(), which safeDecodeURI has already decoded to /files/my invoice.pdf. So the check was always false for params with spaces or non-ASCII characters.

param             signed path            request.url()          before   after
'1'               /files/1               /files/1               true     true
'my invoice.pdf'  /files/my%20invoice.pdf /files/my invoice.pdf false    true
'café'            /files/caf%C3%A9       /files/café            false    true
'a/b'             /files/a%2Fb           /files/a%2Fb           true     true

hasValidSignature() now runs the signed URL through the same safeDecodeURI and compares pathname and query string separately. Both sides are then in the form the router matches on. A changed path (my%20invoice → other%20invoice) is still rejected. If the signed value is not a string or can't be decoded, the method returns false instead of throwing.

Tests: added two tests in tests/router/url_builder.spec.ts. The percent-encoded one fails on 9.x and passes with the fix. npm run lint, npm run typecheck and npm run quick:test (673 tests) pass.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly. (no docs change needed)

createURL encodes each route param with encodeURIComponent, so the
signed URL holds "/files/my%20invoice.pdf". hasValidSignature compared
it with this.url(), which safeDecodeURI has already decoded to
"/files/my invoice.pdf", so the check always failed for params with
spaces or non-ASCII characters.

Decode the signed pathname with the same safeDecodeURI before comparing.

Fixes #154
@fleet-panda fleet-panda Bot added the status: incoming The status of the hub task label Nov 17, 2026
@thetutlage thetutlage added status: draft The status of the hub task status: review The status of the hub task and removed status: incoming The status of the hub task status: draft The status of the hub task labels Nov 23, 2026
@bardrop

bardrop commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Friendly ping. This fixes hasValidSignature() for signed URLs with percent-encoded params (#154): they verify as invalid today. No conflicts, happy to adjust.

@fleet-panda

fleet-panda Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Triage: nothing to do. The comment is a ping and asks for no change to the code. The checks did not run yet: the workflow run of this fork waits for a maintainer to approve it (action_required).

@thetutlage
thetutlage merged commit 2c7477e into adonisjs:9.x Nov 23, 2026
4 checks passed
@thetutlage

Copy link
Copy Markdown
Member

Thanks for the fix :)

@fleet-panda fleet-panda Bot added status: accepting The status of the hub task status: done The status of the hub task and removed status: review The status of the hub task status: accepting The status of the hub task labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: done The status of the hub task

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hasValidSignature() is false for signed URLs with params like spaces or non-ASCII

2 participants