{"record":{"id":"1f4565e0c43c6cf3","repo":"astrid-runtime/astrid","slug":"cors-origin-raw-has-a-trailing-slash-remove-i","errorCode":null,"errorMessage":"CORS origin {raw:?} has a trailing slash; remove it (browsers send `Origin:` without one)","messagePattern":"CORS origin (.+?) has a trailing slash; remove it \\(browsers send `Origin:` without one\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-gateway/src/config.rs","lineNumber":221,"sourceCode":"        anyhow::bail!(\n            \"CORS origin {raw:?} carries userinfo (user:password); browsers strip it before sending `Origin:` so this can never match\"\n        );\n    }\n    if parsed.path() != \"\" && parsed.path() != \"/\" {\n        anyhow::bail!(\n            \"CORS origin {raw:?} carries a path ({:?}); origins are scheme+host+port only\",\n            parsed.path()\n        );\n    }\n    if parsed.query().is_some() || parsed.fragment().is_some() {\n        anyhow::bail!(\n            \"CORS origin {raw:?} carries a query/fragment; origins are scheme+host+port only\"\n        );\n    }\n    // Disallow trailing-slash forms — browsers send `https://app.example`\n    // (no slash) in `Origin:` and the response header is byte-matched.\n    if raw.ends_with('/') {\n        anyhow::bail!(\n            \"CORS origin {raw:?} has a trailing slash; remove it (browsers send `Origin:` without one)\"\n        );\n    }\n    // Reject a raw IDN — browsers transmit the Punycode (ASCII)\n    // form in `Origin:`, so the bytes wouldn't match anyway. The\n    // `Url` parser already normalizes the host to its ASCII form on\n    // parse; if the *raw* string contained a non-ASCII character,\n    // the parsed `origin()` ASCII-serialization won't equal `raw`.\n    let parsed_ascii = parsed.origin().ascii_serialization();\n    if parsed_ascii != raw {\n        anyhow::bail!(\n            \"CORS origin {raw:?} must be ASCII-only (Punycode); browsers send the Punycoded form in `Origin:`. Use {parsed_ascii:?} instead.\"\n        );\n    }\n    Ok(())\n}\n\n#[cfg(test)]","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-gateway/src/config.rs#L203-L239","documentation":"Validation guard in validate_cors_origin: the entry ends with a trailing slash, but browsers send Origin: without one and the response header is byte-matched, so 'https://app.example/' would silently never match; the entry is rejected with a pointed fix.","triggerScenarios":"Thrown at crates/astrid-gateway/src/config.rs:221 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Delete the trailing slash from the origin entry","Use the exact form the browser sends, e.g. https://app.example","Re-test preflight after the fix"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"affd8760f44190dbdfbec23403f4c4b642c33112","analyzedAt":"2026-09-09T21:28:12.402Z","contentChangedAt":"2026-09-09T21:28:12.402Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}