Our cookie policy names three cookies, the code sets eight, and a one-line grep finds the five it forgot

2026-12-05来源 dev.toEnglish

A cookie policy is a sentence about your code, and unlike most sentences about code, no test fails when it goes stale. Ours has a "Last updated" date at the top, and I wanted to know what that date was vouching for.

The audit is one grep

Cookies leave a codebase in three ways: response.cookies.set(...) on the server, document.cookie = ... in the browser, and a constant holding the cookie's name. Search for all three and list the names:

grep -rnE "cookies?\.set\(|_COOKIE\s*=|document\.cookie" app lib components proxy.ts 

Eight cookies came out. The Supabase session cookies, which the policy names. Then seven of ours:

Cookie What it does Lifetime
cp_country two-letter country, so prices show in a matching currency 30 days
landing_intent the page you arrived on, so signup can send you back to it 30 minutes
cp_signed_in a readable hint that a session cookie exists, so public pages can say "My account" long lived
cp_welcome tells the welcome overlay to play once after sign-in 2 minutes
cp_exercise_spelling UK or US spelling for written exercises 1 year
cp_region_opt_out a price display preference 30 days
cp_gcal_oauth carries OAuth state across the Google Calendar consent screen 10 minutes, scoped to two routes

The live policy names three of the eight: authentication, country, and landing intent. Five are missing.

When each one arrived

Git can date the first appearance of a name, which is the useful number here:

git log -S"'cp_welcome'" --format='%ad %h' --date=short --reverse -- lib | head -1 

cp_exercise_spelling on 13 October, cp_gcal_oauth on 29 October, cp_region_opt_out on 3 November, cp_signed_in and cp_welcome together on 13 November. The policy page says it was last updated on 30 November, after all five existed. So the date is a record of when someone touched the page, not of when the page was checked against the code.

Why it is easy to miss

None of the five is about tracking, and every one of them is plausibly "strictly necessary" for something the visitor asked for. That is exactly why they slipped through: each was added in a commit about a feature, and the feature's author was right that it was harmless. Nobody added a cookie and thought "this is a cookie policy change". Three of them only exist after an action (toggling a spelling, connecting a calendar, being bounced at checkout), so you will not see them by loading the home page and looking at the cookie jar.

The page also makes a promise that depends on the list being complete. It has a section titled "Why There Is No Cookie Banner", and the argument in it is that everything we set is needed for the site to work. That argument is only as good as the list it is made about.

See it

Open the cookie policy and read the "Cookies We Set" list: three items. Then open the home page in a private window with the Network tab open and look at the response headers. A fresh visit sets cp_country and nothing else, which matches the policy. The other cookies show up when you sign in, change a setting or connect a calendar, which is the point: the page is accurate for a first visit and incomplete for a used account.

I have not tested every cookie in a real browser session. The table comes from reading the code, and only cp_country is something I watched arrive.

What I would do about it

The fix is a list, not a rewrite: add the five. The better fix is a test that greps for cookie names the way the command above does and fails if a name is not in the policy page's source. It is about twenty lines, and it turns the "Last updated" date from a promise into something that is checked on every commit.

CogniPrep is a practice site for employer assessments. The pricing page is where the country cookie does its job, if you want to watch it change a currency.

原文:https://www.a8q9.cn/en/article/our-cookie-policy-names-three-cookies-the-code-sets-eight-and-a-one-line-grep-fi-4bca26.html

相关文章