Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

fix(tokens): Hash tokens in tokens module to resist ND2DB-style timing attack #83

Open
wants to merge 1 commit into
base: 06-07-chore_migrate_from_yaml_to_json
Choose a base branch
from

Conversation

Blckbrry-Pi
Copy link
Contributor

@Blckbrry-Pi Blckbrry-Pi commented May 1, 2024

Resolves OGB-53

Copy link
Contributor Author

Blckbrry-Pi commented May 1, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @Blckbrry-Pi and the rest of your teammates on Graphite Graphite

@Blckbrry-Pi Blckbrry-Pi marked this pull request as ready for review May 1, 2024 20:33
Copy link

@MasterPtato MasterPtato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too familiar with this kind if attack, is it possible to write a unit test that confirms this attack is no longer valid after this patch?

Copy link
Contributor Author

I'm not too familiar with this kind if attack, is it possible to write a unit test that confirms this attack is no longer valid after this patch?

Almost definitely not.
The theoretical timing attack I proposed would probably take about 3 days minimum to attempt, and that would be if the attacker was on the lucky side.

I can almost guarantee that this style of timing attack will be impossible until a method is released to manipulate SHA256 hashes bit by bit.

modules/tokens/utils/types.ts Outdated Show resolved Hide resolved
@Blckbrry-Pi Blckbrry-Pi force-pushed the 05-01-fix_tokens_hash_tokens_in_tokens_module_to_resist_nd2db-style_timing_attack branch from b2cefc7 to 3d5d946 Compare May 16, 2024 12:15
@Blckbrry-Pi Blckbrry-Pi requested a review from NathanFlurry May 16, 2024 12:17
@Blckbrry-Pi Blckbrry-Pi force-pushed the 05-01-fix_tokens_hash_tokens_in_tokens_module_to_resist_nd2db-style_timing_attack branch from 3d5d946 to 29dbcf2 Compare May 22, 2024 00:58
@@ -13,18 +13,22 @@ export async function run(
ctx: ScriptContext,
req: Request,
): Promise<Response> {
const hashed = await Promise.all(req.tokens.map(hash));
console.log(hashed);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

row: prisma.Prisma.TokenGetPayload<any>,
): Token {
return {
...withoutKeys(row, ["tokenHash"]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is more lines of code and harder to understand than just manually passing in each parameter from the row in to the response.

modules/tokens/utils/types.ts Show resolved Hide resolved
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants