Skip to content

Commit

Permalink
Set Cookies to Secure if app baseUrl is https (#998)
Browse files Browse the repository at this point in the history
  • Loading branch information
scotttrinh authored May 3, 2024
1 parent 385949c commit 24f32df
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/auth-express/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export interface ExpressAuthOptions {
export class ExpressAuth {
private readonly options: Required<ExpressAuthOptions>;
private readonly core: Promise<Auth>;
private readonly isSecure: boolean;

constructor(protected readonly client: Client, options: ExpressAuthOptions) {
this.options = {
Expand All @@ -82,6 +83,7 @@ export class ExpressAuth {
options.pkceVerifierCookieName ?? "edgedb-pkce-verifier",
};
this.core = Auth.create(client);
this.isSecure = this.options.baseUrl.startsWith("https");
}

isPasswordResetTokenValid = (resetToken: string) => {
Expand All @@ -95,6 +97,7 @@ export class ExpressAuth {
path: "/",
sameSite: "strict",
expires,
secure: this.isSecure,
});
};

Expand All @@ -105,6 +108,7 @@ export class ExpressAuth {
path: "/",
sameSite: "strict",
expires: expires ?? undefined,
secure: this.isSecure,
});
};

Expand Down
2 changes: 2 additions & 0 deletions packages/auth-remix/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class RemixClientAuth {
> &
Pick<RemixAuthOptions, OptionalOptions>;
readonly webAuthnClient: WebAuthnClient;
protected readonly isSecure: boolean;

/** @internal */
constructor(options: RemixAuthOptions) {
Expand All @@ -39,6 +40,7 @@ export class RemixClientAuth {
signinUrl: `${this._authRoute}/webauthn/signin`,
verifyUrl: `${this._authRoute}/webauthn/verify`,
});
this.isSecure = this.options.baseUrl.startsWith("https");
}

protected get _authRoute() {
Expand Down
2 changes: 2 additions & 0 deletions packages/auth-remix/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export class RemixServerAuth extends RemixClientAuth {
sameSite: "strict",
path: "/",
expires,
secure: this.isSecure,
});
}

Expand All @@ -140,6 +141,7 @@ export class RemixServerAuth extends RemixClientAuth {
sameSite: "strict",
path: "/",
expires: expires ?? undefined,
secure: this.isSecure,
});
}

Expand Down
2 changes: 2 additions & 0 deletions packages/auth-sveltekit/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ export default function createClientAuth(options: AuthOptions) {

export class ClientAuth {
protected readonly config: AuthConfig;
protected readonly isSecure: boolean;

/** @internal */
constructor(options: AuthOptions) {
this.config = getConfig(options);
this.isSecure = this.config.baseUrl.startsWith("https");
}

getOAuthUrl(providerName: BuiltinOAuthProviderNames) {
Expand Down
2 changes: 2 additions & 0 deletions packages/auth-sveltekit/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export class ServerRequestAuth extends ClientAuth {
sameSite: "strict",
path: "/",
expires,
secure: this.isSecure,
});
}

Expand All @@ -149,6 +150,7 @@ export class ServerRequestAuth extends ClientAuth {
sameSite: "strict",
path: "/",
expires: expires ?? undefined,
secure: this.isSecure,
});
}

Expand Down

0 comments on commit 24f32df

Please sign in to comment.