Skip to content

Commit f29e577

Browse files
committed
encrypt cookies containing callback state
1 parent 9d45077 commit f29e577

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

packages/common/src/cookie.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { sealData, unsealData } from "iron-session";
22

3-
type SameSite = 'Strict' | 'Lax' | 'None';
3+
export type SameSite = Lowercase<'Strict' | 'Lax' | 'None'>;
44

55
export interface Response {
6-
setCookie(name: string, value: string, options: CookieOptions): void;
7-
clearCookie(name: string, options: CookieOptions): void;
6+
cookie(name: string, value: string, options: CookieOptions): Response;
7+
clearCookie(name: string, options?: CookieOptions): Response;
88
}
99

1010
export interface Request {
@@ -49,7 +49,7 @@ export class CookieJar {
4949
cookie: {
5050
httpOnly: true,
5151
secure: !devMode,
52-
sameSite: "Lax" as const,
52+
sameSite: "lax" as const,
5353
path: "/",
5454
maxAge: ttl * 1000,
5555
},
@@ -62,7 +62,7 @@ export class CookieJar {
6262
ttl: this.options.ttl,
6363
});
6464

65-
resp.setCookie(name, sealed, this.options.cookie);
65+
resp.cookie(name, sealed, this.options.cookie);
6666
}
6767

6868
async get<T>(req: Request, name: string, onError: (...args: string[]) => void): Promise<T | null> {

packages/pds/src/api/com/atproto/sso/getCallback.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ export default function (server: Server, ctx: AppContext) {
5858
throw new InvalidRequestError(`Missing code in callback response`);
5959
}
6060

61-
const { code, state } = params;
62-
6361
const session: SessionData | null = await ctx.cookieJar.get(req, "atproto-callback", (msg, error) => {
6462
log.error(`Cookie error: ${msg} ${error}`);
6563
});
@@ -69,7 +67,7 @@ export default function (server: Server, ctx: AppContext) {
6967
}
7068

7169
// CSRF protection: compare state from URL with state from session
72-
if (session.state !== state) {
70+
if (session.state !== params.state) {
7371
await ctx.ssoManager.deleteAuthCallback(session.state);
7472
ctx.cookieJar.clear(res, "atproto-callback");
7573

@@ -114,7 +112,7 @@ export default function (server: Server, ctx: AppContext) {
114112

115113
const data = new URLSearchParams({
116114
grant_type: "authorization_code",
117-
code,
115+
code: params.code,
118116
redirect_uri: callback.redirectUri,
119117
client_id: idp.clientId,
120118
});

0 commit comments

Comments
 (0)