Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion valhalla/jawn/src/lib/requestWrapper/requestWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const HELICONE_API_KEY_REGEX = [
/^pk-helicone-[a-z0-9]{7}-[a-z0-9]{7}-[a-z0-9]{7}-[a-z0-9]{7}$/,
/^pk-helicone-eu-[a-z0-9]{7}-[a-z0-9]{7}-[a-z0-9]{7}-[a-z0-9]{7}$/,
/^sk-helicone-eu-[a-z0-9]{7}-[a-z0-9]{7}-[a-z0-9]{7}-[a-z0-9]{7}$/,
/^[sp]k(-helicone)?(-eu)?(-cp)?-\w{7}-\w{7}-\w{7}-\w{7}$/,
/^[sp]k(-helicone)?(-eu)?(-cp)?(-gov)?(-rl)?-\w{7}-\w{7}-\w{7}-\w{7}$/,
...HELICONE_RATE_LIMITED_API_KEY_REGEX,
];

Expand Down
2 changes: 1 addition & 1 deletion worker/src/lib/util/apiKeyRegex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export const HELICONE_API_KEY_REGEX = [
/^pk-helicone-[a-z0-9]{7}-[a-z0-9]{7}-[a-z0-9]{7}-[a-z0-9]{7}$/,
/^pk-helicone-eu-[a-z0-9]{7}-[a-z0-9]{7}-[a-z0-9]{7}-[a-z0-9]{7}$/,
/^sk-helicone-eu-[a-z0-9]{7}-[a-z0-9]{7}-[a-z0-9]{7}-[a-z0-9]{7}$/,
/^[sp]k(-helicone)?(-eu)?(-cp)?-\w{7}-\w{7}-\w{7}-\w{7}$/,
/^[sp]k(-helicone)?(-eu)?(-cp)?(-gov)?(-rl)?-\w{7}-\w{7}-\w{7}-\w{7}$/,
...HELICONE_RATE_LIMITED_API_KEY_REGEX,
];
26 changes: 26 additions & 0 deletions worker/test/security/outboundHeaders.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,32 @@ describe("containsHeliconeKey", () => {
).toBe(true);
});

it("detects customer-portal keys with -rl and -gov prefixes", () => {
// generated by buildHeliconeApiKey: [sp]k(-eu)?-cp(-gov)?(-rl)?-<4x7>
expect(
containsHeliconeKey("Bearer sk-cp-rl-abcdefg-hijklmn-opqrstu-vwxyz12")
).toBe(true);
expect(
containsHeliconeKey("Bearer sk-cp-gov-abcdefg-hijklmn-opqrstu-vwxyz12")
).toBe(true);
expect(
containsHeliconeKey("pk-cp-gov-rl-abcdefg-hijklmn-opqrstu-vwxyz12")
).toBe(true);
expect(
containsHeliconeKey("Bearer sk-eu-cp-rl-abcdefg-hijklmn-opqrstu-vwxyz12")
).toBe(true);
expect(
containsHeliconeKey("pk-eu-cp-gov-abcdefg-hijklmn-opqrstu-vwxyz12")
).toBe(true);
// governance / rate-limited org keys
expect(
containsHeliconeKey("Bearer sk-helicone-gov-abcdefg-hijklmn-opqrstu-vwxyz12")
).toBe(true);
expect(
containsHeliconeKey("Bearer sk-helicone-eu-gov-rl-abcdefg-hijklmn-opqrstu-vwxyz12")
).toBe(true);
});

it("does not flag provider keys", () => {
expect(containsHeliconeKey("Bearer sk-proj-abc123DEF456")).toBe(false);
expect(containsHeliconeKey("sk-ant-api03-xyz")).toBe(false);
Expand Down