Files
openclaw/src/pairing/join-code.ts
T
Peter Steinberger 941b5240c6 fix: prevent random 404s on device-pairing join links (#123182)
* fix(gateway): route j-prefixed pairing shortcodes

The context-path parser used the last /j substring, so a random shortcode beginning with j displaced the actual route delimiter and fell through to the plain 404 handler.

Reproduced through the real HTTP server with a deterministic 22-character j-prefixed shortcode; the parser now matches the complete /j/ segment.

* fix(gateway): keep bare /j join route stable under j-containing context paths

Check the terminal /j before the /j/ marker so an advertised context path
containing a /j/ segment (e.g. /proxy/j/app) still parses its code-less
route as the bare join route. Pins the route-claim contract: /j answers
with the handler's JSON not_found, never the server default 404.
2026-08-13 19:16:49 -07:00

21 lines
859 B
TypeScript

// Shared shape for the public device-pairing join shortcode.
export const DEVICE_PAIRING_JOIN_CODE_BYTES = 16;
const DEVICE_PAIRING_JOIN_CODE_RE = /^[A-Za-z0-9_-]{22}$/u;
export function isDevicePairingJoinCode(value: string): boolean {
return DEVICE_PAIRING_JOIN_CODE_RE.test(value);
}
export function parseDevicePairingJoinRequestPath(pathname: string): string | null {
// Public endpoints may include an advertised context path. The final /j namespace
// is the stable route contract; preserving only root /j would mint unusable URLs.
// Terminal /j first: a context path may itself contain a /j/ segment
// (e.g. /proxy/j/app/j), and shortcodes never contain slashes.
if (pathname.endsWith("/j")) {
return "";
}
const markerIndex = pathname.lastIndexOf("/j/");
return markerIndex >= 0 ? pathname.slice(markerIndex + 3) : null;
}