Redirect path captures double-encode percent-encoded reserved characters
Maintainers usually reply within 5 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- node.js, typescript
- Domain
- backend
Research direction
Start in src/middleware/redirects.ts and follow one captured segment through the three hops the report names: decodeURI(rawPath), compileDestination(params) and the encodeURI(rawDestPath) call in formatDestination. Run the supplied repro.js against a local build to confirm the four %25XX outputs, then check the existing redirect middleware tests for the pattern used to assert Location headers. Done means reserved escapes like %40 and %2B survive into Location unchanged while plain spaces still encode as %20.
Written by the indexing model from the issue text.
Description
When a redirect destination uses captured path segments (such as :id or regex :1), percent-encoded reserved characters in the matched segment (%40, %2B, %2F, %3F, %23, %26, %3A, %3D, %2C, %3B, %24) are double-encoded into %25XX in the Location header.
Reproduction
Save as repro.js:
const http = require("node:http");
const superstatic = require("superstatic").server;
const app = superstatic({
port: 0,
host: "127.0.0.1",
config: {
redirects: [{ source: "/u/:id", destination: "/users/:id" }],
},
});
const server = app.listen(async () => {
const { port } = server.address();
for (const path of [
"/u/a%20b",
"/u/user%40example.com",
"/u/c%2B%2B",
"/u/a%3Fb",
]) {
await new Promise((resolve, reject) => {
http.get({ host: "127.0.0.1", port, path }, (res) => {
res.resume();
console.log(`${path} -> ${res.statusCode} ${res.headers.location}`);
resolve();
}).on("error", reject);
});
}
server.close();
});
Run:
npm install [email protected]
node repro.js
Actual output
/u/a%20b -> 301 /users/a%20b
/u/user%40example.com -> 301 /users/user%2540example.com
/u/c%2B%2B -> 301 /users/c%252B%252B
/u/a%3Fb -> 301 /users/a%253Fb
Expected output
/u/a%20b -> 301 /users/a%20b
/u/user%40example.com -> 301 /users/user%40example.com
/u/c%2B%2B -> 301 /users/c%2B%2B
/u/a%3Fb -> 301 /users/a%3Fb
Versions
superstatic:11.1.0andmain(a239edf)- Node.js:
v26.13.0
In src/middleware/redirects.ts, decodeURI(rawPath) leaves URI-reserved escapes (; / ? : @ & = + $ , #) percent-encoded, decodeURIComponent(this.compileDestination(params)) keeps them as %XX, and encodeURI(rawDestPath) in formatDestination encodes % again to %25.
Credit: https://ucsbplse.github.io/
- Dominant language
- TypeScript
- Stars
- 1.1k
- Forks
- 90
- Avg merge
- 3d 19h
- Merged PRs (30d)
- 13
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from firebase/superstatic
-
Difficulty 3/5 1-2 days Newbie friendliness 65/100
firebase/superstatic#573 · 2 comments ·
Maintainers usually reply within 5 days
-
superstatic always loads configs from existing `firebase.json` file on project rootPossibly taken @jabrailkhalil claimed this 45 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 45/100
firebase/superstatic#503 · 2 reactions ·
Maintainers usually reply within 5 days
-
Redirect inserting unexpected slash between index and parametersPossibly taken @sean0407 claimed this 28 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 45/100
firebase/superstatic#300 ·
Maintainers usually reply within 5 days
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
firebase/superstatic#286 ·
Maintainers usually reply within 5 days
-
Difficulty 4/5 3-5 days Newbie friendliness 32/100
firebase/superstatic#277 · 4 reactions ·
Maintainers usually reply within 5 days
All issues in firebase/superstatic
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
vercel-labs/ui#865 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
outline/outline#14638 · 1 comment ·
Maintainers usually reply within 1 day
-
wayfinder:grilling
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
patricktree/cup#484 ·
-
bot:ai-assisted component:platform-js status:untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
midnightntwrk/platform-js#69 ·
Maintainers usually reply within 1 day