detached 063dc5a

fix(security): Improve Cloudflare clearance cookie parsing

commit
063dc5a40f41baa4c9b7c905a1b647d4536726ac
author
Kit · · 2025-02-18 07:32 UTC
parent
c487b81
signature
SSH UnverifiedSHA256:H91DFuEG4jpk5edzLA4aUKkpv4zv9Q339ipRmkph6Tk The key is unknown
1 file · +3 -2
M src/routes/api/session/login/+server.ts +3 -2
@@ -28,11 +28,12 @@ setInterval(() => {
2828 }
2929 }, 60 * 60 * 1000);
3030
31-// cf_clearance:"Qwq0fwt23w"
3231 // Helper to parse clearance cookie from headers
3332 function getClearanceCookie(cookieHeader: string | null): string | null {
3433 if (!cookieHeader) return null;
35- const match = cookieHeader.match(/cf-clearance=([^;]+)/);
34+ // Use a case-insensitive regex to match either "cf-clearance" or "cf_clearance"
35+ const regex = /cf[-_]clearance=([^;]+)/i;
36+ const match = cookieHeader.match(regex);
3637 return match ? match[1] : null;
3738 }
3839
@@ -28,11 +28,12 @@ setInterval(() => {
28 }28 }
29 }, 60 * 60 * 1000);29 }, 60 * 60 * 1000);
30 30
31-// cf_clearance:"Qwq0fwt23w"
32 // Helper to parse clearance cookie from headers31 // Helper to parse clearance cookie from headers
33 function getClearanceCookie(cookieHeader: string | null): string | null {32 function getClearanceCookie(cookieHeader: string | null): string | null {
34 if (!cookieHeader) return null;33 if (!cookieHeader) return null;
35- const match = cookieHeader.match(/cf-clearance=([^;]+)/);34+ // Use a case-insensitive regex to match either "cf-clearance" or "cf_clearance"
35+ const regex = /cf[-_]clearance=([^;]+)/i;
36+ const match = cookieHeader.match(regex);
36 return match ? match[1] : null;37 return match ? match[1] : null;
37 }38 }
38 39

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 3

Tags 8

↑↓ moveenter openesc close