Last active
September 27, 2019 13:50
-
-
Save buroz/2caf957a076913390b69ab63943f122e to your computer and use it in GitHub Desktop.
CSRF checker on memory with Typescript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import crypto from "crypto"; | |
class CSRF { | |
private store: string[] = []; | |
constructor() {} | |
createToken() { | |
const token = crypto.randomBytes(64).toString("hex"); | |
this.store.push(token); | |
return token; | |
} | |
checkToken(token: string): Promise<boolean> { | |
return new Promise((resolve, reject) => { | |
let i = this.store.indexOf(token); | |
i > -1 | |
? (() => { | |
delete this.store[i]; | |
resolve(true); | |
})() | |
: reject(false); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment