Skip to content

Commit 34877ab

Browse files
committed
refactor: replace external uuid with crypto.randomUUID()
older versions of uuid have a security vulnerability. newer version are esm-only. replaced with node's built-in crypto.randomUUID()
1 parent ed5ab4d commit 34877ab

8 files changed

Lines changed: 46 additions & 65 deletions

File tree

package-lock.json

Lines changed: 1 addition & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/build/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@
114114
"terminal-link": "^4.0.0",
115115
"ts-node": "^10.9.1",
116116
"typescript": "^5.0.0",
117-
"uuid": "^11.0.0",
118117
"yaml": "^2.8.0",
119118
"yargs": "^17.6.0",
120119
"zod": "^3.25.76"

packages/build/src/plugins/ipc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import crypto from 'crypto'
12
import process from 'process'
23
import { promisify } from 'util'
34

45
import { pEvent } from 'p-event'
5-
import { v4 as uuidv4 } from 'uuid'
66

77
import { jsonToError, errorToJson } from '../error/build.js'
88
import { addErrorInfo } from '../error/info.js'
@@ -17,7 +17,7 @@ import {
1717
// We need to fire them in parallel because `process.send()` can be slow
1818
// to await, i.e. child might send response before parent start listening for it
1919
export const callChild = async function ({ childProcess, eventName, payload, logs, verbose }) {
20-
const callId = uuidv4()
20+
const callId = crypto.randomUUID()
2121
const [response] = await Promise.all([
2222
getEventFromChild(childProcess, callId),
2323
sendEventToChild({ childProcess, callId, eventName, payload, logs, verbose }),

packages/edge-bundler/node/bundler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import crypto from 'crypto'
12
import { promises as fs } from 'fs'
23
import { join } from 'path'
34

45
import commonPathPrefix from 'common-path-prefix'
5-
import { v4 as uuidv4 } from 'uuid'
66

77
import { importMapSpecifier } from '../shared/consts.js'
88

@@ -92,7 +92,7 @@ export const bundle = async (
9292
// The name of the bundle will be the hash of its contents, which we can't
9393
// compute until we run the bundle process. For now, we'll use a random ID
9494
// to create the bundle artifacts and rename them later.
95-
const buildID = uuidv4()
95+
const buildID = crypto.randomUUID()
9696

9797
// Loading any configuration options from the deploy configuration API, if it
9898
// exists.

packages/edge-bundler/node/server/server.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import crypto from 'crypto'
12
import { createWriteStream } from 'fs'
23
import { readFile } from 'fs/promises'
34
import { join } from 'path'
@@ -10,7 +11,6 @@ import process from 'process'
1011
import { getURL as getBootstrapURL } from '@netlify/edge-functions-bootstrap/version'
1112
import getPort from 'get-port'
1213
import tmp from 'tmp-promise'
13-
import { v4 as uuidv4 } from 'uuid'
1414
import { test, expect } from 'vitest'
1515

1616
import { fixturesDir } from '../../test/util.js'
@@ -73,7 +73,7 @@ test('Starts a server and serves requests for edge functions', async () => {
7373
headers: {
7474
'x-nf-edge-functions': 'echo_env',
7575
'x-ef-passthrough': 'passthrough',
76-
'X-NF-Request-ID': uuidv4(),
76+
'X-NF-Request-ID': crypto.randomUUID(),
7777
},
7878
})
7979
expect(response1.status).toBe(200)
@@ -83,7 +83,7 @@ test('Starts a server and serves requests for edge functions', async () => {
8383
headers: {
8484
'x-nf-edge-functions': 'greet',
8585
'x-ef-passthrough': 'passthrough',
86-
'X-NF-Request-ID': uuidv4(),
86+
'X-NF-Request-ID': crypto.randomUUID(),
8787
},
8888
})
8989
expect(response2.status).toBe(200)
@@ -93,7 +93,7 @@ test('Starts a server and serves requests for edge functions', async () => {
9393
headers: {
9494
'x-nf-edge-functions': 'global_netlify',
9595
'x-ef-passthrough': 'passthrough',
96-
'X-NF-Request-ID': uuidv4(),
96+
'X-NF-Request-ID': crypto.randomUUID(),
9797
},
9898
})
9999
expect(await response3.json()).toEqual({
@@ -166,7 +166,7 @@ test('Serves edge functions in a monorepo setup', async () => {
166166
headers: {
167167
'x-nf-edge-functions': 'func1',
168168
'x-ef-passthrough': 'passthrough',
169-
'X-NF-Request-ID': uuidv4(),
169+
'X-NF-Request-ID': crypto.randomUUID(),
170170
},
171171
})
172172

packages/edge-bundler/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
"semver": "^7.3.8",
7979
"tar": "^7.5.12",
8080
"tmp-promise": "^3.0.3",
81-
"urlpattern-polyfill": "8.0.2",
82-
"uuid": "^11.0.0"
81+
"urlpattern-polyfill": "8.0.2"
8382
}
8483
}

packages/js-client/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
"nock": "^13.0.0",
5353
"ts-node": "^10.9.1",
5454
"typescript": "^5.0.0",
55-
"uuid": "^11.0.0",
5655
"vitest": "^3.2.3"
5756
},
5857
"engines": {

0 commit comments

Comments
 (0)