From ddb9ca301efc8fb37aede6044bc17c294d074fdf Mon Sep 17 00:00:00 2001 From: Ian Fox Date: Thu, 17 Aug 2017 11:15:47 -0700 Subject: [PATCH] fix(tokens): increase hash size to 512 bits --- models/token.js | 10 +++++----- test/data/token.yaml | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/models/token.js b/models/token.js index 202e0272..170cfdaa 100644 --- a/models/token.js +++ b/models/token.js @@ -2,11 +2,11 @@ const Joi = require('joi'); const mutate = require('../lib/mutate'); -// Token length, measured in bits -const TOKEN_LENGTH = 256; -// Calculate the character length of the base64 string representing TOKEN_LENGTH bits +// Token hash length, measured in bits +const HASH_LENGTH = 512; +// Calculate the character length of the base64 string representing HASH_LENGTH bits // Each base64 character represents 6 bits of data -const HASH_LENGTH = Math.ceil(TOKEN_LENGTH / 6); +const HASH_BASE64_LENGTH = Math.ceil(HASH_LENGTH / 6); const MODEL = { id: Joi @@ -18,7 +18,7 @@ const MODEL = { .string() // Using https://www.npmjs.com/package/base64url .regex(/[a-zA-Z0-9_-]+/) - .length(HASH_LENGTH) + .length(HASH_BASE64_LENGTH) .description('Hashed token value'), userId: Joi diff --git a/test/data/token.yaml b/test/data/token.yaml index e560442c..c43145cf 100644 --- a/test/data/token.yaml +++ b/test/data/token.yaml @@ -1,6 +1,6 @@ # Base Token Example userId: 1234 -hash: 'aHashedTokenValueMustBe43CharactersLong_-_-' +hash: 'aHashedTokenValueMustBe86CharactersLong_______________________________________________' id: 1111 name: 'Auth token' description: 'A token for authentication'