-
-
Notifications
You must be signed in to change notification settings - Fork 146
Use the configured secret when signing and verifying CSRF tokens #584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
afc620e
d35b1a5
7973fee
e8b052c
9e9c227
c96353b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -173,7 +173,8 @@ | |
| * @author [Sergio Xalambrí](https://sergiodxa.com) | ||
| * @module Server/CSRF | ||
| */ | ||
| import { sha256 } from "@oslojs/crypto/sha2"; | ||
| import { hmac } from "@oslojs/crypto/hmac"; | ||
| import { SHA256 } from "@oslojs/crypto/sha2"; | ||
| import { encodeBase64url } from "@oslojs/encoding"; | ||
| import type { Cookie } from "react-router"; | ||
| import { randomString } from "../common/crypto.js"; | ||
|
|
@@ -343,7 +344,8 @@ export class CSRF { | |
|
|
||
| private sign(token: string) { | ||
| if (!this.secret) return token; | ||
| return encodeBase64url(sha256(new TextEncoder().encode(token))); | ||
| let encoder = new TextEncoder(); | ||
| return encodeBase64url(hmac(SHA256, encoder.encode(this.secret), encoder.encode(token))); | ||
|
Comment on lines
+358
to
+359
|
||
| } | ||
|
|
||
| private verifySignature(token: string) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.