Redirect path captures double-encode percent-encoded reserved characters

Đang mở Phù hợp với người mới
#622 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 5 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
76/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
node.js, typescript
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu trong src/middleware/redirects.ts và theo dõi một segment đã được capture qua ba bước mà báo cáo nêu tên: decodeURI(rawPath), compileDestination(params) và lời gọi encodeURI(rawDestPath) trong formatDestination. Chạy repro.js được cung cấp với một bản build cục bộ để xác nhận bốn đầu ra %25XX, sau đó kiểm tra các test hiện có của middleware redirect để tìm pattern dùng để assert các header Location. Hoàn tất nghĩa là các escape dành riêng như %40 và %2B đi vào Location nguyên vẹn trong khi dấu cách thông thường vẫn được encode thành %20.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.0 and main (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/

Ngôn ngữ chính
TypeScript
Star
1.1k
Fork
90
Merge trung bình
3 ngày 19 giờ
Pull request đã merge (30 ngày)
13

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của firebase/superstatic

Tất cả issue của firebase/superstatic

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.