Skip to content

Commit 465ce06

Browse files
authored
Fix: token parsing bug causing proxyToSandbox to fail (#147)
1 parent b597b66 commit 465ce06

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

.changeset/polite-kiwis-speak.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudflare/sandbox": minor
3+
---
4+
5+
Fix token extraction regex causing Invalid token errors

packages/sandbox/src/request-handler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ export async function proxyToSandbox<E extends SandboxEnv>(
105105

106106
function extractSandboxRoute(url: URL): RouteInfo | null {
107107
// Parse subdomain pattern: port-sandboxId-token.domain (tokens mandatory)
108-
const subdomainMatch = url.hostname.match(/^(\d{4,5})-([^.-][^.]*[^.-]|[^.-])-([a-zA-Z0-9_-]{12,20})\.(.+)$/);
108+
// Token is always exactly 16 chars (generated by generatePortToken)
109+
const subdomainMatch = url.hostname.match(/^(\d{4,5})-([^.-][^.]*?[^.-]|[^.-])-([a-z0-9_-]{16})\.(.+)$/);
109110

110111
if (!subdomainMatch) {
111112
return null;

0 commit comments

Comments
 (0)