fix: enable automated E2E test execution via Docker#5725
fix: enable automated E2E test execution via Docker#5725ruslanPL-EnvisionBlockchain wants to merge 5 commits intodevelopfrom
Conversation
910de95 to
f2b5f99
Compare
| const variables = FormulaImportExport.getItems(expression?.variables, []); | ||
| for (const item of variables) { | ||
| items.push({ | ||
| uuid: GenerateUUIDv4(), |
Check failure
Code scanning / CodeQL
Insecure randomness
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 days ago
In general, to fix this problem we must stop using Math.random to generate UUIDs and instead use a cryptographically secure source of randomness. In Node, this is typically crypto.randomUUID() (Node 14.17+/16+) or crypto.randomBytes; in browsers, crypto.getRandomValues. Since GenerateUUIDv4 is shared via @guardian/interfaces and used from Node code, we should implement it using a secure source that works in both environments or gracefully falls back where needed.
The best single change without altering existing behavior at call sites is to update interfaces/src/helpers/generate-uuid-v4.ts so that GenerateUUIDv4 (and, for completeness, GenerateID) use a CSPRNG. We will: (1) import Node’s crypto module; (2) implement a small helper that obtains random bytes using crypto.randomUUID() if available, otherwise crypto.randomBytes, and in a browser environment uses globalThis.crypto.getRandomValues if present; and (3) implement UUID v4 formatting and 32-hex ID formatting using those bytes instead of Math.random. The public API (GenerateUUIDv4() and GenerateID()) and their return types stay the same, so existing code like GenerateUUIDv4() in formula.ts continues to work while now being backed by secure randomness.
Concretely:
- Edit
interfaces/src/helpers/generate-uuid-v4.ts:- Add
import crypto from 'crypto';at the top. - Replace the
GenerateUUIDv4implementation to first trycrypto.randomUUID()when available, then otherwise generate 16 random bytes and set the version/variant bits per RFC 4122. - Replace
GenerateIDso it uses a buffer of random bytes (e.g., 16 bytes = 32 hex chars) and maps those to hex characters.
- Add
- No changes are required in
common/src/import-export/formula.ts, since it already imports and callsGenerateUUIDv4by name.
| const formulas = FormulaImportExport.getItems(expression?.formulas, []); | ||
| for (const item of formulas) { | ||
| items.push({ | ||
| uuid: GenerateUUIDv4(), |
Check failure
Code scanning / CodeQL
Insecure randomness
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 days ago
In general, to fix insecure randomness, any function that currently uses Math.random to generate security‑sensitive identifiers should instead use a cryptographically secure random source. In Node.js this is typically crypto.randomBytes, and in browsers it is crypto.getRandomValues. For a UUID v4 generator, we want 16 bytes of secure randomness and to set the version and variant bits according to RFC 4122, or equivalently, generate random hex digits using secure random numbers instead of Math.random.
The best targeted fix here is to change GenerateUUIDv4 (and, for completeness, the similar GenerateID) in interfaces/src/helpers/generate-uuid-v4.ts to use a CSPRNG while preserving the existing function signatures and return formats. We can do this by importing Node’s crypto module and using crypto.randomBytes when window.crypto (browser) is not available, and window.crypto.getRandomValues (or self.crypto) when in a browser context. To minimize functional changes, we keep the same UUID string pattern (xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx) and GenerateID’s 32‑hex‑character string; only the internal randomness source changes.
Concretely:
- Update
interfaces/src/helpers/generate-uuid-v4.tsto:- Import
randomBytesfrom Node’scryptomodule. - Add a small helper
getSecureRandomByte()that returns a number in[0, 255]usingwindow.crypto.getRandomValueswhen available, otherwiserandomBytes(1)[0]. - Rewrite
GenerateUUIDv4’s.replacecallback to usegetSecureRandomByte()(appropriately masked/scaled to 4‑bit values) instead ofMath.random. - Rewrite
GenerateIDsimilarly to use secure random nibbles, again replacingMath.randomwith the helper.
These changes are entirely confined tointerfaces/src/helpers/generate-uuid-v4.ts; the code incommon/src/import-export/formula.tscan stay as is, since onceGenerateUUIDv4is secure the use at line 270 (and others) is safe.
- Import
| @@ -1,23 +1,45 @@ | ||
| import { randomBytes } from 'crypto'; | ||
|
|
||
| /** | ||
| * Get a cryptographically secure random byte (0-255) | ||
| */ | ||
| function getSecureRandomByte(): number { | ||
| // Browser environments | ||
| const g: any = (typeof globalThis !== 'undefined') ? globalThis : (typeof window !== 'undefined' ? window : undefined); | ||
| if (g && g.crypto && typeof g.crypto.getRandomValues === 'function') { | ||
| const array = new Uint8Array(1); | ||
| g.crypto.getRandomValues(array); | ||
| return array[0]; | ||
| } | ||
|
|
||
| // Node.js fallback | ||
| return randomBytes(1)[0]; | ||
| } | ||
|
|
||
| /** | ||
| * Generate random UUID | ||
| */ | ||
| export function GenerateUUIDv4() { | ||
| return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => { | ||
| const randomByte = getSecureRandomByte(); | ||
| // use lower 4 bits | ||
| // tslint:disable-next-line:no-bitwise | ||
| const r = Math.random() * 16 | 0; | ||
| const r = randomByte & 0x0f; | ||
| // tslint:disable-next-line:no-bitwise | ||
| const v = c === 'x' ? r : (r & 0x3 | 0x8); | ||
| const v = c === 'x' ? r : ((r & 0x3) | 0x8); | ||
| return v.toString(16); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Generate random UUID | ||
| * Generate random ID (32 hex characters) | ||
| */ | ||
| export function GenerateID() { | ||
| return 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'.replace(/[x]/g, (c) => { | ||
| return 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'.replace(/[x]/g, () => { | ||
| const randomByte = getSecureRandomByte(); | ||
| // use lower 4 bits | ||
| // tslint:disable-next-line:no-bitwise | ||
| const v = Math.random() * 16 | 0; | ||
| const v = randomByte & 0x0f; | ||
| return v.toString(16); | ||
| }); | ||
| } |
f2b5f99 to
6908721
Compare
6908721 to
b359f1f
Compare
52722e3 to
2b222e9
Compare
- Corrected links in README and added sections for running tests with tags, Docker setup, and CI/CD integration. - Enhanced the entrypoint script to automatically prepend the 'preparing' tag for user account creation. - Updated docker-compose configuration to improve environment variable handling and image naming. - Adjusted GitHub Actions workflow to ensure proper Docker image building and test result handling.
423d79f to
3d86618
Compare
3d86618 to
abae97e
Compare
94e83ee to
297f850
Compare
Description:
This PR includes the following changes:
Related issue(s):
Fixes #
Notes for reviewer:
Checklist