Skip to content

Commit

Permalink
fix(core): Replace insecure randomness with secure randomBytes
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Sep 18, 2024
1 parent 2a817cb commit cb556d8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/core/src/config/default-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
SUPER_ADMIN_USER_PASSWORD,
DEFAULT_CHANNEL_TOKEN_KEY,
} from '@vendure/common/lib/shared-constants';
import { randomBytes } from 'crypto';

import { TypeORMHealthCheckStrategy } from '../health-check/typeorm-health-check-strategy';
import { InMemoryJobQueueStrategy } from '../job-queue/in-memory-job-queue-strategy';
Expand Down Expand Up @@ -89,7 +90,7 @@ export const defaultConfig: RuntimeVendureConfig = {
disableAuth: false,
tokenMethod: 'cookie',
cookieOptions: {
secret: Math.random().toString(36).substr(3),
secret: randomBytes(16).toString('base64url'),
httpOnly: true,
sameSite: 'lax',
},
Expand Down
5 changes: 3 additions & 2 deletions packages/create/src/gather-user-responses.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { cancel, intro, isCancel, outro, select, text } from '@clack/prompts';
import { cancel, isCancel, select, text } from '@clack/prompts';
import { SUPER_ADMIN_USER_IDENTIFIER, SUPER_ADMIN_USER_PASSWORD } from '@vendure/common/lib/shared-constants';
import { randomBytes } from 'crypto';
import fs from 'fs-extra';
import Handlebars from 'handlebars';
import path from 'path';
Expand Down Expand Up @@ -205,7 +206,7 @@ async function generateSources(
isSQLite: answers.dbType === 'sqlite',
isSQLjs: answers.dbType === 'sqljs',
requiresConnection: answers.dbType !== 'sqlite' && answers.dbType !== 'sqljs',
cookieSecret: Math.random().toString(36).substr(2),
cookieSecret: randomBytes(16).toString('base64url'),
};

async function createSourceFile(filename: string, noEscape = false): Promise<string> {
Expand Down

0 comments on commit cb556d8

Please sign in to comment.