Skip to content

Commit ab1d9e4

Browse files
committed
Patch puppeteer to not rely on code generation from strings
Changes from security: 3rd-party dependencies Changes from node scripts/eslint_all_files --no-cache --fix
1 parent 1f9e556 commit ab1d9e4

9 files changed

Lines changed: 114 additions & 9 deletions

File tree

.buildkite/scripts/steps/security/third_party_packages.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
patch-package
12
safe-stable-stringify
23
ajv-draft-04
34
ajv-formats

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2159,6 +2159,7 @@
21592159
"oboe": "2.1.7",
21602160
"openapi-types": "12.1.3",
21612161
"oxlint": "1.56.0",
2162+
"patch-package": "8.0.1",
21622163
"peggy": "4.2.0",
21632164
"picomatch": "4.0.4",
21642165
"pirates": "4.0.7",
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
diff --git a/node_modules/puppeteer-core/lib/cjs/puppeteer/util/Function.js b/node_modules/puppeteer-core/lib/cjs/puppeteer/util/Function.js
2+
index b5bf30a..81e5f50 100644
3+
--- a/node_modules/puppeteer-core/lib/cjs/puppeteer/util/Function.js
4+
+++ b/node_modules/puppeteer-core/lib/cjs/puppeteer/util/Function.js
5+
@@ -18,7 +18,10 @@ const createFunction = (functionValue) => {
6+
if (fn) {
7+
return fn;
8+
}
9+
- fn = new Function(`return ${functionValue}`)();
10+
+ fn = function puppeteerBackendPlaceholder() {
11+
+ throw new Error('This function is a serialization placeholder. It should not be called directly in the Node.js process -- it exists only to carry source code to the browser via CDP.');
12+
+ };
13+
+ fn.toString = () => functionValue;
14+
createdFunctions.set(functionValue, fn);
15+
return fn;
16+
};
17+
diff --git a/node_modules/puppeteer-core/lib/esm/puppeteer/util/Function.js b/node_modules/puppeteer-core/lib/esm/puppeteer/util/Function.js
18+
index 0ec5465..55c4cc1 100644
19+
--- a/node_modules/puppeteer-core/lib/esm/puppeteer/util/Function.js
20+
+++ b/node_modules/puppeteer-core/lib/esm/puppeteer/util/Function.js
21+
@@ -14,7 +14,10 @@ export const createFunction = (functionValue) => {
22+
if (fn) {
23+
return fn;
24+
}
25+
- fn = new Function(`return ${functionValue}`)();
26+
+ fn = function puppeteerBackendPlaceholder() {
27+
+ throw new Error('This function is a serialization placeholder. It should not be called directly in the Node.js process -- it exists only to carry source code to the browser via CDP.');
28+
+ };
29+
+ fn.toString = () => functionValue;
30+
createdFunctions.set(functionValue, fn);
31+
return fn;
32+
};

renovate.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2446,6 +2446,15 @@
24462446
"minimumReleaseAge": "14 days",
24472447
"enabled": true
24482448
},
2449+
{
2450+
"groupName": "patch-package",
2451+
"matchDepNames": ["patch-package"],
2452+
"reviewers": ["team:kibana-security"],
2453+
"matchBaseBranches": ["main"],
2454+
"addLabels": ["Team:Security"],
2455+
"minimumReleaseAge": "7 days",
2456+
"enabled": true
2457+
},
24492458
{
24502459
"groupName": "@xyflow/react",
24512460
"matchPackageNames": ["@xyflow/react"],

src/dev/build/tasks/install_dependencies_task.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,9 @@ export const InstallDependencies: Task = {
3535
cwd: build.resolvePath(),
3636
}
3737
);
38+
39+
await exec(log, 'npx', ['patch-package', '--error-on-fail'], {
40+
cwd: build.resolvePath(),
41+
});
3842
},
3943
};

src/dev/kbn_pm/src/commands/bootstrap/bootstrap_command.mjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,20 @@ export const command = {
141141
await runInstallScripts(log, { quiet });
142142
})
143143
: undefined,
144+
shouldInstall
145+
? time('apply node_modules patches', async () => {
146+
log.info('applying node_modules patches via patch-package');
147+
// The patch-package command is used to apply patches to the node_modules directory.
148+
// At the time of writing, the following packages are patched:
149+
// - zod@4.3.6 => memory regression introduced in 4.x (see https://github.com/colinhacks/zod/issues/5760)
150+
// The libraries above should not be updated, as doing so would break the patches.
151+
await run('node', ['node_modules/.bin/patch-package', '--error-on-fail'], {
152+
pipe: !quiet,
153+
description: 'patch-package',
154+
});
155+
log.success('node_modules patches applied');
156+
})
157+
: undefined,
144158
]);
145159

146160
await time('sort package json', async () => {

src/dev/precommit_hook/exceptions.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@
229229
"x-pack/platform/plugins/shared/index_management/public/application/components/mappings_editor/components/document_fields/common/listItemStyle.ts": "'listItemStyle.ts' should be snake_case"
230230
},
231231
"@elastic/kibana-operations": {
232+
"patches/puppeteer-core+24.42.0.patch": "'puppeteer-core+24.42.0.patch' should be snake_case",
232233
"packages/kbn-ts-projects/config-paths.json": "'config-paths.json' should be snake_case",
233234
"src/platform/packages/private/kbn-repo-packages/package-map.json": "'package-map.json' should be snake_case",
234235
"src/platform/packages/shared/kbn-test/jest_integration_node/jest-preset.js": "'jest-preset.js' should be snake_case",

x-pack/platform/plugins/shared/screenshotting/server/browsers/chromium/driver.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,6 @@ export class HeadlessChromiumDriver {
196196
* statically.
197197
*/
198198
private async injectScreenshottingErrorHeader(error: Error, containerSelector: string) {
199-
// FIXME This relies on code generation from strings.
200-
if (true) {
201-
return;
202-
}
203199
await this.page.evaluate(
204200
(selector: string, text: string) => {
205201
let container = document.querySelector(selector);

yarn.lock

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18500,7 +18500,7 @@ chromium-bidi@14.0.0:
1850018500
mitt "^3.0.1"
1850118501
zod "^3.24.1"
1850218502

18503-
ci-info@^3.2.0:
18503+
ci-info@^3.2.0, ci-info@^3.7.0:
1850418504
version "3.8.0"
1850518505
resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-3.8.0.tgz#81408265a5380c929f0bc665d62256628ce9ef91"
1850618506
integrity sha512-eXTggHWSooYhq49F2opQhuHWgzucfF2YgODK4e1566GQs5BIfP30B0oenwBJHfWxAs2fyPB1s7Mg949zLf61Yw==
@@ -22613,6 +22613,13 @@ find-up@^8.0.0:
2261322613
locate-path "^8.0.0"
2261422614
unicorn-magic "^0.3.0"
2261522615

22616+
find-yarn-workspace-root@^2.0.0:
22617+
version "2.0.0"
22618+
resolved "https://registry.yarnpkg.com/find-yarn-workspace-root/-/find-yarn-workspace-root-2.0.0.tgz#f47fb8d239c900eb78179aa81b66673eac88f7bd"
22619+
integrity sha512-1IMnbjt4KzsQfnhnzNd8wUEgXZ44IzZaZmnLYx7D5FZlaHt2gW20Cri8Q+E/t5tIj4+epTBub+2Zxu/vNILzqQ==
22620+
dependencies:
22621+
micromatch "^4.0.2"
22622+
2261622623
fix-esm@1.0.1:
2261722624
version "1.0.1"
2261822625
resolved "https://registry.yarnpkg.com/fix-esm/-/fix-esm-1.0.1.tgz#e0e2199d841e43ff7db9b5f5ba7496bc45130ebb"
@@ -23477,7 +23484,7 @@ gpt-tokenizer@2.6.2:
2347723484
resolved "https://registry.yarnpkg.com/gpt-tokenizer/-/gpt-tokenizer-2.6.2.tgz#90e6932c7b5f73df7c13d360802edb43a2776586"
2347823485
integrity sha512-OznIET3z069FiwbLtLFXJ9pVESYAa8EnX0BMogs6YJ4Fn2FIcyeZYEbxsp2grPiK0DVaqP1f+0JR/8t9R7/jlg==
2347923486

23480-
graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.10, graceful-fs@^4.2.11, graceful-fs@^4.2.4, graceful-fs@^4.2.6, graceful-fs@^4.2.8, graceful-fs@^4.2.9:
23487+
graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.10, graceful-fs@^4.2.11, graceful-fs@^4.2.4, graceful-fs@^4.2.6, graceful-fs@^4.2.8, graceful-fs@^4.2.9:
2348123488
version "4.2.11"
2348223489
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3"
2348323490
integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==
@@ -25265,7 +25272,7 @@ is-word-character@^1.0.0:
2526525272
resolved "https://registry.yarnpkg.com/is-word-character/-/is-word-character-1.0.1.tgz#5a03fa1ea91ace8a6eb0c7cd770eb86d65c8befb"
2526625273
integrity sha1-WgP6HqkazopusMfNdw64bWXIvvs=
2526725274

25268-
is-wsl@^2.2.0:
25275+
is-wsl@^2.1.1, is-wsl@^2.2.0:
2526925276
version "2.2.0"
2527025277
resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-2.2.0.tgz#74a4c76e77ca9fd3f932f290c17ea326cd157271"
2527125278
integrity sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==
@@ -26100,7 +26107,7 @@ json-stable-stringify-without-jsonify@^1.0.1:
2610026107
resolved "https://registry.yarnpkg.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651"
2610126108
integrity sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=
2610226109

26103-
json-stable-stringify@^1.0.1:
26110+
json-stable-stringify@^1.0.1, json-stable-stringify@^1.0.2:
2610426111
version "1.3.0"
2610526112
resolved "https://registry.yarnpkg.com/json-stable-stringify/-/json-stable-stringify-1.3.0.tgz#8903cfac42ea1a0f97f35d63a4ce0518f0cc6a70"
2610626113
integrity sha512-qtYiSSFlwot9XHtF9bD9c7rwKjr+RecWT//ZnPvSmEjpV5mmPOCN4j8UjY5hbjNkOwZ/jQv3J6R1/pL7RwgMsg==
@@ -26329,6 +26336,13 @@ kind-of@^6.0.0, kind-of@^6.0.2, kind-of@^6.0.3:
2632926336
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.3.tgz#07c05034a6c349fa06e24fa35aa76db4580ce4dd"
2633026337
integrity sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==
2633126338

26339+
klaw-sync@^6.0.0:
26340+
version "6.0.0"
26341+
resolved "https://registry.yarnpkg.com/klaw-sync/-/klaw-sync-6.0.0.tgz#1fd2cfd56ebb6250181114f0a581167099c2b28c"
26342+
integrity sha512-nIeuVSzdCCs6TDPTqI8w1Yre34sSq7AkZ4B3sfOBbI2CgVSB4Du4aLQijFU2+lhAFCwt9+42Hel6lQNIv6AntQ==
26343+
dependencies:
26344+
graceful-fs "^4.1.11"
26345+
2633226346
kleur@^3.0.3:
2633326347
version "3.0.3"
2633426348
resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e"
@@ -29115,6 +29129,14 @@ open@^10.0.3:
2911529129
is-inside-container "^1.0.0"
2911629130
is-wsl "^3.1.0"
2911729131

29132+
open@^7.4.2:
29133+
version "7.4.2"
29134+
resolved "https://registry.yarnpkg.com/open/-/open-7.4.2.tgz#b8147e26dcf3e426316c730089fd71edd29c2321"
29135+
integrity sha512-MVHddDVweXZF3awtlAS+6pgKLlm/JgxZ90+/NBurBoQctVOOB/zDdVjcyPzQ+0laDGbsWgrRkflI65sQeOgT9Q==
29136+
dependencies:
29137+
is-docker "^2.0.0"
29138+
is-wsl "^2.1.1"
29139+
2911829140
open@^8.0.4, open@^8.4.0, open@~8.4.0:
2911929141
version "8.4.2"
2912029142
resolved "https://registry.yarnpkg.com/open/-/open-8.4.2.tgz#5b5ffe2a8f793dcd2aad73e550cb87b59cb084f9"
@@ -29684,6 +29706,26 @@ patch-console@^2.0.0:
2968429706
resolved "https://registry.yarnpkg.com/patch-console/-/patch-console-2.0.0.tgz#9023f4665840e66f40e9ce774f904a63167433bb"
2968529707
integrity sha512-0YNdUceMdaQwoKce1gatDScmMo5pu/tfABfnzEqeG0gtTmd7mh/WcwgUjtAeOU7N8nFFlbQBnFK2gXW5fGvmMA==
2968629708

29709+
patch-package@8.0.1:
29710+
version "8.0.1"
29711+
resolved "https://registry.yarnpkg.com/patch-package/-/patch-package-8.0.1.tgz#79d02f953f711e06d1f8949c8a13e5d3d7ba1a60"
29712+
integrity sha512-VsKRIA8f5uqHQ7NGhwIna6Bx6D9s/1iXlA1hthBVBEbkq+t4kXD0HHt+rJhf/Z+Ci0F/HCB2hvn0qLdLG+Qxlw==
29713+
dependencies:
29714+
"@yarnpkg/lockfile" "^1.1.0"
29715+
chalk "^4.1.2"
29716+
ci-info "^3.7.0"
29717+
cross-spawn "^7.0.3"
29718+
find-yarn-workspace-root "^2.0.0"
29719+
fs-extra "^10.0.0"
29720+
json-stable-stringify "^1.0.2"
29721+
klaw-sync "^6.0.0"
29722+
minimist "^1.2.6"
29723+
open "^7.4.2"
29724+
semver "^7.5.3"
29725+
slash "^2.0.0"
29726+
tmp "^0.2.4"
29727+
yaml "^2.2.2"
29728+
2968729729
path-browserify@1.0.1, path-browserify@^1.0.0, path-browserify@^1.0.1:
2968829730
version "1.0.1"
2968929731
resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-1.0.1.tgz#d98454a9c3753d5790860f16f68867b9e46be1fd"
@@ -34751,7 +34793,7 @@ tmp@^0.0.33:
3475134793
dependencies:
3475234794
os-tmpdir "~1.0.2"
3475334795

34754-
tmp@^0.2.5, tmp@~0.2.4:
34796+
tmp@^0.2.4, tmp@^0.2.5, tmp@~0.2.4:
3475534797
version "0.2.5"
3475634798
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.2.5.tgz#b06bcd23f0f3c8357b426891726d16015abfd8f8"
3475734799
integrity sha512-voyz6MApa1rQGUxT3E+BK7/ROe8itEx7vD8/HEvt4xwXucvQ5G5oeEiHkmHZJuBO21RpOf+YYm9MOivj709jow==
@@ -37088,6 +37130,11 @@ yaml@^2.0.0, yaml@^2.2.1:
3708837130
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.3.4.tgz#53fc1d514be80aabf386dc6001eb29bf3b7523b2"
3708937131
integrity sha512-8aAvwVUSHpfEqTQ4w/KMlf3HcRdt50E5ODIQJBw1fQ5RL34xabzxtUlzTXVqc4rkZsPbvrXKWnABCD7kWSmocA==
3709037132

37133+
yaml@^2.2.2:
37134+
version "2.9.0"
37135+
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.9.0.tgz#78274afd93598a1dfdd6130df6a566defcbf9aa4"
37136+
integrity sha512-2AvhNX3mb8zd6Zy7INTtSpl1F15HW6Wnqj0srWlkKLcpYl/gMIMJiyuGq2KeI2YFxUPjdlB+3Lc10seMLtL4cA==
37137+
3709137138
yargs-parser@^18.1.2:
3709237139
version "18.1.3"
3709337140
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-18.1.3.tgz#be68c4975c6b2abf469236b0c870362fab09a7b0"

0 commit comments

Comments
 (0)