Skip to content

fix: catch dot segments hidden behind backslashes and whitespace - #1168

Merged
dielduarte merged 3 commits into
resend:mainfrom
Abhishek-B-R:fix/dot-segment-backslash-and-whitespace
Oct 30, 2026
Merged

dielduarte merged 3 commits into
resend:mainfrom
Abhishek-B-R:fix/dot-segment-backslash-and-whitespace

Conversation

@Abhishek-B-R

@Abhishek-B-R Abhishek-B-R commented Oct 18, 2026 •

Copy link
Copy Markdown

follow up to #1139. the dot segment check splits the path on / only, but the URL parser that fetch uses does a bit more before it resolves ..:

  • in http(s) URLs a \ is a path separator, same as /
  • tabs and newlines are removed from anywhere in the URL
  • control characters and spaces are trimmed off the end

so an id like ..\api-keys\key-id or .\t. passes hasDotSegment and still gets resolved into a different endpoint.

repro

built the sdk from main, swapped fetch for one that logs new Request(url, init).url (what fetch actually sends):

call main this branch
domains.remove('..\\api-keys\\key-id') DELETE /api-keys/key-id not sent, invalid_parameter
emails.cancel('.\t.') POST /cancel not sent, invalid_parameter
emails.get('..\n') GET / not sent, invalid_parameter

same idea as #1139: if an app passes user input as an id, these get out of the endpoint the call was meant for.

fix

hasDotSegment now strips tabs and newlines, trims trailing control characters and spaces, and splits segments on both / and \. the rest is unchanged. a space in the middle of a path is still percent encoded by the parser rather than dropped, so /emails/.. /cancel is still allowed, and there's a test for that.

tests

  • has-dot-segment.spec.ts: backslash separated .., tab and newline inside the dots, trailing \r, space and NUL
  • resend.spec.ts: domains.remove('..\\api-keys\\key-id') and emails.cancel('.\t.') return invalid_parameter and nothing is sent

both new specs fail on main and pass here. pnpm test (772 passed, 4 todo), pnpm typecheck, pnpm lint and pnpm build all pass.


Summary by cubic

Fixes hasDotSegment to catch dot segments hidden behind backslashes and whitespace that the URL parser strips before resolving .., so ids like ..\api-keys\key-id or .\t. no longer reach a different endpoint.

  • Splits segments on both / and \, and strips tabs, newlines, and trailing control characters before checking.
  • Preserves spaces in the middle of a path, which the parser percent-encodes rather than dropping.
  • Adds tests for backslash-separated dot segments, tab/newline variants, trailing whitespace, and corresponding SDK calls returning invalid_parameter without sending.
  • Bumps the package version to 6.36.1.

Written for commit 4927ba3. Summary will update on new commits.

View guided diff

The URL parser treats a backslash as a path separator in http(s) URLs,
drops tabs and newlines, and trims trailing control characters before
resolving dot segments, so ids like "..\api-keys" or ".\t." slipped past
hasDotSegment and reached another endpoint.
@Abhishek-B-R
Abhishek-B-R requested a review from a team as a code owner October 18, 2026 07:32
@Abhishek-B-R
Abhishek-B-R requested review from felipefreitag and removed request for a team October 18, 2026 07:32
@github-actions github-actions Bot added the linear-synced PR has been synced to Linear label Oct 18, 2026
@Abhishek-B-R

Copy link
Copy Markdown
Author

@felipefreitag friendly bump on this follow-up to #1139: hasDotSegment now also catches ids like ..\api-keys\key-id or .\t. that the URL parser resolves through backslashes, stripped tabs/newlines and trailing whitespace, with spec coverage for each case. It merges cleanly with main and there's no open review feedback. Happy to adjust anything if the approach doesn't fit.

@pkg-pr-new

pkg-pr-new Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/resend@1168

commit: 4927ba3

@dielduarte
dielduarte self-requested a review October 30, 2026 21:17

@dielduarte dielduarte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!

@dielduarte
dielduarte merged commit 68f0f52 into resend:main Oct 30, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

linear-synced PR has been synced to Linear

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants