Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(redirect): strip ASCII control characters in stripBasePath (#15014)

Harsh Kashyapacaaaf64b545
diff --git a/web/src/__tests__/redirect.clienttest.ts b/web/src/__tests__/redirect.clienttest.ts
index 21f5eb5221..3bbc2f1042 100644
--- a/web/src/__tests__/redirect.clienttest.ts
+++ b/web/src/__tests__/redirect.clienttest.ts
@@ -371,6 +371,27 @@ describe("stripBasePath", () => {
expect(stripBasePath("/apps/apps/dashboard")).toBe("/apps/dashboard");
});
+ it("strips ASCII control characters from the path", () => {
+ // Newline (header-injection vector)
+ expect(stripBasePath("/apps\n/dashboard")).toBe("/dashboard");
+ // CRLF
+ expect(stripBasePath("/apps\r\n/dashboard")).toBe("/dashboard");
+ // Null byte (path-extension confusion)
+ expect(stripBasePath("/apps\u0000/dashboard")).toBe("/dashboard");
+ // DEL (0x7F)
+ expect(stripBasePath("/apps\u007F/dashboard")).toBe("/dashboard");
+ // Multiple control chars in one path
+ expect(stripBasePath("/apps\n\r\u0000/dashboard")).toBe("/dashboard");
+ });
+
+ it("does NOT strip Unicode bidi-formatting characters outside the C0 range", () => {
+ // U+202E (RTL-override) is intentionally out of scope for this fix;
+ // it lives at 0x202E, beyond the 0x00-0x1F / 0x7F regex scope. The
+ // result still has a leading "/" so it survives the path-vs-leading-
+ // slash guard; downstream code decides whether to display it.
+ expect(stripBasePath("/apps\u202E/dashboard")).toBe("/\u202E/dashboard");
+ });
+
it("leaves paths without basePath untouched", () => {
expect(stripBasePath("/no-base")).toBe("/no-base");
});
diff --git a/web/src/utils/redirect.ts b/web/src/utils/redirect.ts
index ee39be4e25..dc9737699f 100644
--- a/web/src/utils/redirect.ts
+++ b/web/src/utils/redirect.ts
@@ -92,6 +92,10 @@ export function stripBasePath(path: string): string {
return path;
}
- const stripped = path.slice(basePath.length) || "/";
+ // Strip ASCII control characters (0x00-0x1F, 0x7F) before further
+ // processing. See getSafeRedirectPath for the rationale.
+ const cleaned = path.replace(/[\x00-\x1F\x7F]/g, "");
+
+ const stripped = cleaned.slice(basePath.length) || "/";
return stripped.startsWith("/") ? stripped : `/${stripped}`;
}