Skip to content

Conversation

@AshishKumar4
Copy link
Contributor

Fixes token validation failure due to incorrect token extraction from url logic. The tokens for port are always generated to be 16 bytes, but the regex in extractSandboxRoute greedly extracts sandbox id and token from the url, and if the token has '-', it can parse it incorrectly. for example, here is a generated url:

8001-45sysyjmojksu4la7n4va-n_a-ydoam7w_32y5.vibecoder.cloudflare.dev

The original sandbox id provided was: 45sysyjmojksu4la7n4va

Before (incorrect parsing):
Port: 8001
Sandbox ID: 45sysyjmojksu4la7n4va-n_a ← absorbed part of token
Token: ydoam7w_32y5 ← only 12 chars (invalid)
Result: Token validation fails with "Invalid token" error

After (correct parsing):
Port: 8001
Sandbox ID: 45sysyjmojksu4la7n4va
Token: n_a-ydoam7w_32y5 ← full 16 chars (valid)
Result: Token validation succeeds

Changes:

  • Non-greedy sandbox ID pattern: [^.]? instead of [^.]
  • Exact token length: {16} matches generatePortToken() output
  • Lowercase only: [a-z] matches .toLowerCase() in token generation

Fixes token validation failure due to incorrect token extraction from url logic.
The tokens for port are always generated to be 16 bytes, but the regex in extractSandboxRoute
greedly extracts sandbox id and token from the url, and if the token has '-', it can parse it incorrectly.
for example, here is a generated url:
8001-45sysyjmojksu4la7n4va-n_a-ydoam7w_32y5.vibecoder.cloudflare.dev

Before (incorrect parsing):
  Port:       8001
  Sandbox ID: 45sysyjmojksu4la7n4va-n_a  ← absorbed part of token!
  Token:      ydoam7w_32y5              ← only 12 chars (invalid)
  Result:     Token validation fails with "Invalid token" error

After (correct parsing):
  Port:       8001
  Sandbox ID: 45sysyjmojksu4la7n4va
  Token:      n_a-ydoam7w_32y5          ← full 16 chars (valid)
  Result:     Token validation succeeds

Changes:
- Non-greedy sandbox ID pattern: [^.]*? instead of [^.]*
- Exact token length: {16} matches generatePortToken() output
- Lowercase only: [a-z] matches .toLowerCase() in token generation
@changeset-bot
Copy link

changeset-bot bot commented Oct 24, 2025

🦋 Changeset detected

Latest commit: bedd891

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cloudflare/sandbox Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ghostwriternr ghostwriternr merged commit 465ce06 into cloudflare:main Oct 24, 2025
1 of 3 checks passed
@threepointone threepointone mentioned this pull request Oct 24, 2025
@ghostwriternr ghostwriternr mentioned this pull request Oct 24, 2025
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