Skip to content

Commit 8ac1a86

Browse files
authored
Merge pull request #103 from telemetryflow/alert-autofix-13
Potential fix for code scanning alert no. 13: Use of password hash with insufficient computational effort
2 parents 7ae103f + c40351e commit 8ac1a86

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

  • backend/src/modules/api-keys/domain/aggregates

backend/src/modules/api-keys/domain/aggregates/ApiKey.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ export class ApiKey extends AggregateRoot<ApiKeyId> {
149149
const keyHint = rawKeySecret.slice(-4);
150150

151151
// Hash the secret for storage (one-way) using a slow password hash
152-
const apiKeySecret = crypto.createHash('sha256').update(rawKeySecret).digest('hex');
152+
const secretSalt = crypto.randomBytes(16).toString('hex');
153+
const secretHash = crypto.scryptSync(rawKeySecret, secretSalt, 64).toString('hex');
154+
const apiKeySecret = `${secretSalt}:${secretHash}`;
153155

154156
const now = new Date();
155157
const apiKey = new ApiKey(id, {

0 commit comments

Comments
 (0)