Skip to content

fix(security): URL-encode path parameters in X API calls to prevent route corruption - #96

Closed
magqqgq wants to merge 1 commit into
tempoxyz:mainfrom
magqqgq:magqqgq-patch-1
Closed

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

Conversation

@magqqgq

@magqqgq magqqgq commented Oct 1, 2026

Copy link
Copy Markdown

Summary of Changes

Addresses the Section 4.12 (Low) finding from the workspace security audit in repository tip.bot by ensuring path parameters interpolated into X (Twitter) API endpoints are strictly URL-encoded[cite: 20].


Vulnerability Analysis

  • In src/lib/twitter.ts, getUserByUsername previously interpolated raw username strings directly into the API endpoint path (/2/users/by/username/${username})[cite: 20].
  • Usernames or handles containing slashes (/), question marks (?), hashes (#), or other RFC 3986 reserved characters could corrupt the request path or result in unexpected route traversal against the X API[cite: 20].

Key Remediations

  • src/lib/twitter.ts:
    • Encoded username path segments using encodeURIComponent(username.replace(/^@+/, '')) in getUserByUsername[cite: 20].
    • Encoded tweetId path segments in getTweet (/2/tweets/${encodeURIComponent(tweetId)}) for defense-in-depth.

Verification

  • tsgo -b: Typecheck executed cleanly with exit code 0.
  • Verified that usernames containing reserved characters (e.g., user/name) are properly escaped without altering URL structure[cite: 20].

…oute corruption

### Summary of Changes
Addresses the **Section 4.12 (Low)** finding from the workspace security audit in repository `tip.bot` by ensuring path parameters interpolated into X (Twitter) API endpoints are strictly URL-encoded[cite: 20].

---

### Vulnerability Analysis
- In `src/lib/twitter.ts`, `getUserByUsername` previously interpolated raw username strings directly into the API endpoint path (`/2/users/by/username/${username}`)[cite: 20].
- Usernames or handles containing slashes (`/`), question marks (`?`), hashes (`#`), or other RFC 3986 reserved characters could corrupt the request path or result in unexpected route traversal against the X API[cite: 20].

---

### Key Remediations
- **`src/lib/twitter.ts`:**
  - Encoded username path segments using `encodeURIComponent(username.replace(/^@+/, ''))` in `getUserByUsername`[cite: 20].
  - Encoded `tweetId` path segments in `getTweet` (`/2/tweets/${encodeURIComponent(tweetId)}`) for defense-in-depth.

---

### Verification
- `tsgo -b`: Typecheck executed cleanly with exit code 0.
- Verified that usernames containing reserved characters (e.g., `user/name`) are properly escaped without altering URL structure[cite: 20].
@magqqgq

magqqgq commented Nov 4, 2026

Copy link
Copy Markdown
Author

Hi @tmm, I noticed this PR was closed without being merged. Was this vulnerability addressed in another PR/commit, or is there something else you need from my end? Just wanted to clarify. Thanks!

This branch was previously deployed

1 inactive deployment
preview — 04263294 Deployed Nov 4, 2026 by tmm via Destroy #81
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.

2 participants