Skip to content

Commit 61e4ab2

Browse files
authored
fix(core): use zkochan/js-yaml directly to avoid false audit errors (#25999)
Some of the audit tools have been falsely flagging the alias to `@zkochan/js-yaml` as `[email protected]` (which has security holes) so we decided to use the package explicitly. ## Current Behavior <!-- This is the behavior we have today --> ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
1 parent 12c6a73 commit 61e4ab2

File tree

13 files changed

+58
-61
lines changed

13 files changed

+58
-61
lines changed

e2e/utils/create-project-utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
import * as isCI from 'is-ci';
1919

2020
import { angularCliVersion as defaultAngularCliVersion } from '@nx/workspace/src/utils/versions';
21-
import { dump } from 'js-yaml';
21+
import { dump } from '@zkochan/js-yaml';
2222
import { execSync, ExecSyncOptions } from 'child_process';
2323

2424
import { performance, PerformanceMeasure } from 'perf_hooks';

nx-dev/ui-markdoc/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
Tokenizer,
77
transform,
88
} from '@markdoc/markdoc';
9-
import { load as yamlLoad } from 'js-yaml';
9+
import { load as yamlLoad } from '@zkochan/js-yaml';
1010
import React, { ReactNode } from 'react';
1111
import { Heading } from './lib/nodes/heading.component';
1212
import { heading } from './lib/nodes/heading.schema';

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
"@xstate/immer": "0.3.1",
137137
"@xstate/inspect": "0.7.0",
138138
"@xstate/react": "3.0.1",
139+
"@zkochan/js-yaml": "0.0.7",
139140
"ai": "^2.2.10",
140141
"ajv": "^8.12.0",
141142
"autoprefixer": "10.4.13",
@@ -206,7 +207,6 @@
206207
"jest-runtime": "^29.4.1",
207208
"jest-util": "^29.4.1",
208209
"js-tokens": "^4.0.0",
209-
"js-yaml": "npm:@zkochan/[email protected]",
210210
"jsonc-eslint-parser": "^2.1.0",
211211
"jsonc-parser": "3.2.0",
212212
"kill-port": "^1.6.1",

packages/eslint/.eslintrc.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939
"typescript",
4040
"eslint",
4141
"@angular-devkit/core",
42-
"@typescript-eslint/eslint-plugin",
43-
"js-yaml" // The rule is failing with alias dependencies see
42+
"@typescript-eslint/eslint-plugin"
4443
]
4544
}
4645
]

packages/eslint/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"generators": "./generators.json",
3232
"executors": "./executors.json",
3333
"peerDependencies": {
34-
"js-yaml": "npm:@zkochan/js-yaml@0.0.7"
34+
"@zkochan/js-yaml": "0.0.7"
3535
},
3636
"dependencies": {
3737
"@nx/devkit": "file:../devkit",
@@ -42,7 +42,7 @@
4242
"typescript": "~5.4.2"
4343
},
4444
"peerDependenciesMeta": {
45-
"js-yaml": {
45+
"@zkochan/js-yaml": {
4646
"optional": true
4747
}
4848
},

packages/eslint/src/generators/convert-to-flat-config/generator.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { ConvertToFlatConfigGeneratorSchema } from './schema';
1515
import { lintProjectGenerator } from '../lint-project/lint-project';
1616
import { Linter } from '../utils/linter';
1717
import { eslintrcVersion } from '../../utils/versions';
18-
import { dump } from 'js-yaml';
18+
import { dump } from '@zkochan/js-yaml';
1919

2020
describe('convert-to-flat-config generator', () => {
2121
let tree: Tree;

packages/eslint/src/generators/convert-to-flat-config/generator.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { join } from 'path';
1616
import { eslintrcVersion, eslintVersion } from '../../utils/versions';
1717
import { ESLint } from 'eslint';
1818
import { convertEslintJsonToFlatConfig } from './converters/json-converter';
19-
import { load } from 'js-yaml';
2019

2120
export async function convertToFlatConfigGenerator(
2221
tree: Tree,
@@ -182,6 +181,7 @@ function convertConfigToFlatConfig(
182181
}
183182
if (source.endsWith('.yaml') || source.endsWith('.yml')) {
184183
const originalContent = tree.read(`${root}/${source}`, 'utf-8');
184+
const { load } = require('@zkochan/js-yaml');
185185
const config = load(originalContent, {
186186
json: true,
187187
filename: source,

packages/nx/.eslintrc.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@
100100
"events", // This is coming from @storybook/builder-manager since it uses the browser polyfill
101101
"process", // This is coming from @storybook/builder-manager since it uses the browser polyfill
102102
"prettier", // This is coming from @storybook/builder-manager since it uses the browser polyfill
103-
"util", // This is coming from @storybook/builder-manager since it uses the browser polyfill
104-
"js-yaml" // The rule is failing with alias dependencies
103+
"util" // This is coming from @storybook/builder-manager since it uses the browser polyfill
105104
]
106105
}
107106
]

packages/nx/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"dependencies": {
4040
"@yarnpkg/lockfile": "^1.1.0",
4141
"@yarnpkg/parsers": "3.0.0-rc.46",
42+
"@zkochan/js-yaml": "0.0.7",
4243
"axios": "^1.6.0",
4344
"chalk": "^4.1.0",
4445
"cli-cursor": "3.1.0",
@@ -52,7 +53,6 @@
5253
"fs-extra": "^11.1.0",
5354
"ignore": "^5.0.4",
5455
"jest-diff": "^29.4.1",
55-
"js-yaml": "npm:@zkochan/[email protected]",
5656
"jsonc-parser": "3.2.0",
5757
"lines-and-columns": "~2.0.3",
5858
"minimatch": "9.0.3",

packages/nx/src/command-line/release/utils/github.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ export async function resolveGithubToken(): Promise<string | null> {
318318
);
319319
if (existsSync(ghCLIPath)) {
320320
const yamlContents = await fsp.readFile(ghCLIPath, 'utf8');
321-
const { load } = require('js-yaml');
321+
const { load } = require('@zkochan/js-yaml');
322322
const ghCLIConfig = load(yamlContents);
323323
if (ghCLIConfig['github.com']) {
324324
// Web based session (the token is already embedded in the config)

packages/nx/src/plugins/js/lock-file/utils/pnpm-normalizer.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function loadPnpmHoistedDepsDefinition() {
2222

2323
if (existsSync(fullPath)) {
2424
const content = readFileSync(fullPath, 'utf-8');
25-
const { load } = require('js-yaml');
25+
const { load } = require('@zkochan/js-yaml');
2626
return load(content)?.hoistedDependencies ?? {};
2727
} else {
2828
throw new Error(`Could not find ".modules.yaml" at "${fullPath}"`);
@@ -38,7 +38,7 @@ export function loadPnpmHoistedDepsDefinition() {
3838
* https://github.com/pnpm/pnpm/blob/af3e5559d377870d4c3d303429b3ed1a4e64fedc/lockfile/lockfile-file/src/read.ts#L91
3939
*/
4040
export function parseAndNormalizePnpmLockfile(content: string): Lockfile {
41-
const { load } = require('js-yaml');
41+
const { load } = require('@zkochan/js-yaml');
4242
const lockFileData = load(content);
4343
return revertFromInlineSpecifiersFormatIfNecessary(
4444
convertFromLockfileFileMutable(lockFileData)
@@ -87,7 +87,7 @@ export function stringifyToPnpmYaml(lockfile: Lockfile): string {
8787
const adaptedLockfile = isLockfileV6
8888
? convertToInlineSpecifiersFormat(lockfile)
8989
: lockfile;
90-
const { dump } = require('js-yaml');
90+
const { dump } = require('@zkochan/js-yaml');
9191
return dump(
9292
sortLockfileKeys(
9393
normalizeLockfile(adaptedLockfile as Lockfile, isLockfileV6)

packages/nx/src/utils/fileutils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export function readYamlFile<T extends object = any>(
7171
options?: YamlReadOptions
7272
): T {
7373
const content = readFileSync(path, 'utf-8');
74-
const { load } = require('js-yaml');
74+
const { load } = require('@zkochan/js-yaml');
7575
return load(content, { ...options, filename: path }) as T;
7676
}
7777

0 commit comments

Comments
 (0)