G
YouTube TikTok Games
Skip to content

fix(security): strip sensitive credentials on cross-origin redirects in request command - #161

Open
mertcano wants to merge 1 commit into
tempoxyz:mainfrom
mertcano:mertcano-patch-1
Open

mertcano wants to merge 1 commit into
tempoxyz:mainfrom
mertcano:mertcano-patch-1

Conversation

@mertcano

@mertcano mertcano commented Oct 1, 2026

Copy link
Copy Markdown

Summary of Changes

Addresses the Section 4.7 (High) security finding in wallet-cli by preventing credential replay across origins during HTTP redirects.


Vulnerability Analysis

  • In src/commands/request.ts, redirectRequest previously replayed the entire original request payload and headers—including Authorization, Cookie, and payment tokens—to whatever destination an upstream Location header specified.
  • A responding server could issue a cross-origin redirect (HTTP 301, 302, 303, 307, or 308) pointing to an untrusted domain, thereby leaking bearer tokens, session cookies, and payment authorization credentials to third parties.

Key Remediations

  1. Cross-Origin Header Stripping (src/commands/request.ts):

    • Enforced removal of authorization, cookie, cookie2, payment-authorization, and proxy-authorization when nextUrl.origin !== currentUrl.origin.
    • Preserved credentials on same-origin redirects to maintain standard API navigation compatibility.
    • Maintained existing RFC 7231 method rewriting semantics (converting POST/PUT to GET for 301, 302, and 303 redirects).
  2. Regression Testing (test/request.test.ts):

    • Added test "does not forward credentials to a different origin" asserting that credentials evaluate as credentials-stripped when following cross-origin redirects.
    • Added test "keeps credentials on same-origin redirects" verifying that credentials remain attached for local path redirects.

Verification

  • pnpm typecheck: Clean compilation with zero diagnostics.
  • vitest run test/request.test.ts: Both redirect credential tests pass reliably.

…in request command

### Summary of Changes
Addresses the **Section 4.7 (High)** security finding in `wallet-cli` by preventing credential replay across origins during HTTP redirects.

---

### Vulnerability Analysis
- In `src/commands/request.ts`, `redirectRequest` previously replayed the entire original request payload and headers—including `Authorization`, `Cookie`, and payment tokens—to whatever destination an upstream `Location` header specified.
- A responding server could issue a cross-origin redirect (HTTP 301, 302, 303, 307, or 308) pointing to an untrusted domain, thereby leaking bearer tokens, session cookies, and payment authorization credentials to third parties.

---

### Key Remediations
1. **Cross-Origin Header Stripping (`src/commands/request.ts`):**
   - Enforced removal of `authorization`, `cookie`, `cookie2`, `payment-authorization`, and `proxy-authorization` when `nextUrl.origin !== currentUrl.origin`.
   - Preserved credentials on same-origin redirects to maintain standard API navigation compatibility.
   - Maintained existing RFC 7231 method rewriting semantics (converting POST/PUT to GET for 301, 302, and 303 redirects).

2. **Regression Testing (`test/request.test.ts`):**
   - Added test `"does not forward credentials to a different origin"` asserting that credentials evaluate as `credentials-stripped` when following cross-origin redirects.
   - Added test `"keeps credentials on same-origin redirects"` verifying that credentials remain attached for local path redirects.

---

### Verification
- `pnpm typecheck`: Clean compilation with zero diagnostics.
- `vitest run test/request.test.ts`: Both redirect credential tests pass reliably.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant