{"record":{"id":"85f7879a4b03776a","repo":"musistudio/claude-code-router","slug":"artifact-url-contains-an-invalid-identifier","errorCode":null,"errorMessage":"Artifact URL contains an invalid identifier.","messagePattern":"Artifact URL contains an invalid identifier\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/agents/codex/media-preview-bridge.ts","lineNumber":280,"sourceCode":"    await sleep(codexMediaPreviewPollIntervalMs);\n  }\n  throw new Error(`Codex App CDP page target was not available${lastError ? `: ${redactBridgeError(lastError)}` : \".\"}`);\n}\n\nfunction isCodexAppPageTarget(target: DevToolsTarget): boolean {\n  if (target.type !== \"page\" || !target.webSocketDebuggerUrl) return false;\n  const url = target.url || \"\";\n  return url.startsWith(\"app://codex\") || url.startsWith(\"app://chatgpt\") || /\\b(codex|chatgpt)\\b/i.test(target.title || \"\");\n}\n\nfunction validateCodexMediaArtifactUrl(value: string, endpoint: string): ValidatedArtifactUrl {\n  const expected = new URL(endpoint);\n  const url = new URL(value);\n  if (url.protocol !== \"http:\" || url.origin !== expected.origin) throw new Error(\"Artifact origin is not the configured CCR gateway.\");\n  if (url.username || url.password || url.hash) throw new Error(\"Artifact URL contains unsupported credentials or fragments.\");\n  if (!url.pathname.startsWith(MEDIA_ARTIFACT_PATH_PREFIX)) throw new Error(\"Artifact URL does not use the CCR media artifact path.\");\n  const encodedId = url.pathname.slice(MEDIA_ARTIFACT_PATH_PREFIX.length);\n  if (!encodedId || encodedId.includes(\"/\")) throw new Error(\"Artifact URL contains an invalid identifier.\");\n  const artifactId = decodeURIComponent(encodedId);\n  if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(artifactId)) {\n    throw new Error(\"Artifact URL contains an invalid identifier.\");\n  }\n  const keys = [...url.searchParams.keys()];\n  const token = url.searchParams.get(\"token\") || \"\";\n  if (keys.length !== 1 || keys[0] !== \"token\" || !/^[A-Za-z0-9_-]{32}$/.test(token)) {\n    throw new Error(\"Artifact URL contains an invalid access token.\");\n  }\n  return { artifactId, url };\n}\n\nasync function loadCodexMediaArtifact(validated: ValidatedArtifactUrl, signal: AbortSignal): Promise<LoadedMediaArtifact> {\n  let response: Response;\n  try {\n    response = await fetch(validated.url, {\n      headers: { accept: \"image/*, video/*\" },\n      redirect: \"error\",","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/musistudio/claude-code-router/blob/99f24806c6a2c660b16e53e95211c517448a6c90/packages/core/src/agents/codex/media-preview-bridge.ts#L262-L298","documentation":"After stripping the artifact path prefix, the remaining path segment must be non-empty and contain no '/'. This throw fires when encodedId is empty (URL ends exactly at the prefix) or when it still contains slash-separated segments (nested path).","triggerScenarios":"Calling validation with a URL like http://gw< prefix > (no id) or http://gw< prefix >abc/extra — a trailing slash after the id produces an empty second segment and encodedId.includes('/') is true.","commonSituations":"Trailing slash appended by a proxy or string concatenation bug; building the URL with a doubled path segment; template strings that leave the id slot empty.","solutions":["Ensure the URL contains exactly one non-empty id segment after the prefix with no trailing slash","Fix URL construction (template literal/concat) that adds '/' or omits the id","Normalize trailing slashes before validating"],"exampleFix":"// before\nvalidateCodexMediaArtifactUrl(`http://gw${MEDIA_ARTIFACT_PATH_PREFIX}${id}/`, endpoint);\n// after\nvalidateCodexMediaArtifactUrl(`http://gw${MEDIA_ARTIFACT_PATH_PREFIX}${id}`, endpoint);","handlingStrategy":"validation","validationCode":"const path = new URL(artifactUrl).pathname;\nconst tail = path.slice(MEDIA_ARTIFACT_PATH_PREFIX.length);\nif (!tail || tail.includes('/')) throw new Error('bad artifact id segment');","typeGuard":"function hasSingleIdSegment(value: string, prefix: string): boolean {\n  try { const tail = new URL(value).pathname.slice(prefix.length); return tail.length > 0 && !tail.includes('/'); } catch { return false; }\n}","tryCatchPattern":null,"preventionTips":["Build URLs from the id with strict template strings (no trailing slash)","Reject URLs with trailing slashes at ingestion","Log the URL tail when validation fails to catch construction bugs"],"tags":["url-validation","artifact-id"],"backgroundTag":"invalid-url-format","analyzedSha":"99f24806c6a2c660b16e53e95211c517448a6c90","analyzedAt":"2026-08-27T04:11:01.184Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}