Skip to content

Fix isSet() substring matching in ignoreCookie - #409

Merged
electerious merged 1 commit into
electerious:developfrom
Davidowi2:fix/ignore-cookie-substring-match
Oct 2, 2026
Merged

electerious merged 1 commit into
electerious:developfrom
Davidowi2:fix/ignore-cookie-substring-match

Conversation

@Davidowi2

Copy link
Copy Markdown
Contributor

Fixes #408

Problem

isSet() in src/utils/ignoreCookie.js detected the ackee_ignore cookie with a plain substring match:

export const isSet = (cookie = '') => cookie.includes(`${COOKIE_NAME}=1`)

That returns true for any cookie header containing ackee_ignore=1, regardless of where the text appears. isSet runs once per request in src/utils/createContext.js:22, and isIgnored gates the ignore path in createRecord (src/resolvers/records.js:50), updateRecord (src/resolvers/records.js:92) and createAction (src/resolvers/actions.js:21) — so an unrelated cookie silently discards visitor data.

Running the current implementation:

Cookie header isSet() Expected
ackee_ignore=1 true true
a=1; ackee_ignore=1; b=2 true true
ackee_ignore=10 true false
not_ackee_ignore=1 true false
x=ackee_ignore=1 true false
foo=bar; baz=ackee_ignore=1 true false
ackee_ignore=0 false false
(empty) false false

Change

Parse cookie name/value boundaries rather than matching a substring:

export const isSet = (cookie = '') =>
  cookie.split(';').some((part) => {
    const [key, ...rest] = part.trim().split('=')
    return key === COOKIE_NAME && rest.join('=') === '1'
  })

Adds test/utils/ignoreCookie.js. 15 of 30 modules in src/utils had no test, including this one — the new test fails against the previous implementation and passes with this change.

npm run lint and npm run test (41 unit tests) pass locally. Happy to adjust the approach if you'd prefer something different — this is a small correctness fix, so please treat it as a starting point for discussion rather than a finished contribution.

isSet() detected the ackee_ignore cookie with String.includes(), so any
cookie header containing "ackee_ignore=1" counted as an opt-out -
including unrelated cookies such as "x=ackee_ignore=1",
"not_ackee_ignore=1" or "ackee_ignore=10".

Since isSet() gates the ignore path in createRecord, updateRecord and
createAction, that silently discarded visitor data.

Parse cookie name/value boundaries instead, and add coverage for
test/utils/ignoreCookie.js, which had none.

Fixes electerious#408
@vercel

vercel Bot commented Oct 1, 2026

Copy link
Copy Markdown

@Davidowi2 is attempting to deploy a commit to the Tobias Reich's projects Team on Vercel.

A member of the Team first needs to authorize it.

@electerious

Copy link
Copy Markdown
Owner

Thanks a lot for the fix and help! :)

electerious added a commit that referenced this pull request Oct 2, 2026
@electerious
electerious merged commit 939b157 into electerious:develop Oct 2, 2026
6 of 7 checks passed
@Davidowi2

Copy link
Copy Markdown
Contributor Author

No probs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants