Skip to content

Commit 5cea3bf

Browse files
committed
fix: validate entire cookie assignment values
Only nested-parse Cookie: name=value headers. cookie=opaque-production-secret=fixture is rejected as a whole RHS.
1 parent 73b44ec commit 5cea3bf

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

packages/evals/__tests__/sanitize.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,14 @@ describe("public eval text detection", () => {
193193
assert.includeMembers(kinds, ["header-credential"]);
194194
});
195195

196+
it("rejects a cookie assignment whose entire RHS is not synthetic", () => {
197+
const kinds = findPublicTextViolations("cookie=opaque-production-secret=fixture").map(
198+
({ kind }) => kind,
199+
);
200+
201+
assert.includeMembers(kinds, ["header-credential", "secret-assignment"]);
202+
});
203+
196204
it("allows negative prose and explicitly synthetic fixture values", () => {
197205
const text = [
198206
"tokenCount=3",

packages/evals/src/sanitize.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,7 @@ const isExplicitSyntheticCredential = (value: string): boolean => {
180180

181181
const isExplicitSyntheticHeaderCredential = (match: RegExpExecArray, value: string): boolean => {
182182
const header = match[0].toLowerCase();
183-
if (
184-
header.startsWith("cookie") ||
185-
header.startsWith("set-cookie") ||
186-
header.startsWith("set_cookie")
187-
) {
183+
if (/^(?:set[-_])?cookie\s*:/.test(header)) {
188184
const assignmentIndex = value.indexOf("=");
189185
if (assignmentIndex !== -1) {
190186
return isExplicitSyntheticCredential(value.slice(assignmentIndex + 1));

0 commit comments

Comments
 (0)