Skip to content

Commit 0bad8d5

Browse files
committed
non conflicting cookie name
1 parent fa74c48 commit 0bad8d5

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

apps/connect/worker/lib/session.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('set + fromRequest', () => {
6464
})
6565
const res = await app.request('http://localhost:3000/')
6666
const cookie = res.headers.get('set-cookie')!
67-
expect(cookie).toContain('session=')
67+
expect(cookie).toContain('connect-session=')
6868
expect(cookie).toContain('HttpOnly')
6969
expect(cookie).toContain('SameSite=None')
7070
expect(cookie).toContain('Secure')
@@ -80,7 +80,7 @@ describe('set + fromRequest', () => {
8080
})
8181
const res = await app.request('https://connect.tempo.xyz/')
8282
const cookie = res.headers.get('set-cookie')!
83-
expect(cookie).toContain('__Secure-session=')
83+
expect(cookie).toContain('__Secure-connect-session=')
8484
expect(cookie).toContain('Domain=.tempo.xyz')
8585
expect(cookie).toContain('Secure')
8686
})
@@ -93,7 +93,7 @@ describe('set + fromRequest', () => {
9393
})
9494
const res = await app.request('http://connect.tempo.local/')
9595
const cookie = res.headers.get('set-cookie')!
96-
expect(cookie).toContain('session=')
96+
expect(cookie).toContain('connect-session=')
9797
expect(cookie).toContain('Domain=.tempo.local')
9898
expect(cookie).not.toContain('__Secure-')
9999
})
@@ -111,10 +111,10 @@ describe('set + fromRequest', () => {
111111

112112
const setRes = await app.request('http://localhost:3000/set')
113113
const cookie = setRes.headers.get('set-cookie')!
114-
const tokenMatch = cookie.match(/session=([^;]+)/)!
114+
const tokenMatch = cookie.match(/connect-session=([^;]+)/)!
115115

116116
const getRes = await app.request('http://localhost:3000/get', {
117-
headers: { cookie: `session=${tokenMatch[1]}` },
117+
headers: { cookie: `connect-session=${tokenMatch[1]}` },
118118
})
119119
const session = (await getRes.json()) as Session.Session
120120
expect(session.address).toMatchInlineSnapshot(`"user-1"`)
@@ -140,7 +140,7 @@ describe('clear', () => {
140140
})
141141
const res = await app.request('http://localhost:3000/')
142142
const cookie = res.headers.get('set-cookie')!
143-
expect(cookie).toContain('session=')
143+
expect(cookie).toContain('connect-session=')
144144
expect(cookie).toContain('Max-Age=0')
145145
})
146146
})

apps/connect/worker/lib/session.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ export async function cookies(
124124
/** Extracts and verifies the session from a Hono context's cookies. */
125125
export async function fromRequest(c: Context, publicKeyJwk: string) {
126126
const token =
127-
getCookie(c, 'session', 'secure') ?? getCookie(c, 'session', 'host') ?? getCookie(c, 'session')
127+
getCookie(c, 'connect-session', 'secure') ??
128+
getCookie(c, 'connect-session', 'host') ??
129+
getCookie(c, 'connect-session')
128130
if (!token) return null
129131
return verify(publicKeyJwk, token)
130132
}
@@ -152,5 +154,5 @@ function cookieEnv(hostname: string): CookieEnv {
152154
}
153155

154156
function cookieName(env: CookieEnv) {
155-
return env.kind === 'production' ? '__Secure-session' : 'session'
157+
return env.kind === 'production' ? '__Secure-connect-session' : 'connect-session'
156158
}

0 commit comments

Comments
 (0)