Skip to content

Commit

Permalink
chore: bump yaml version for security finding (#1193)
Browse files Browse the repository at this point in the history
We currently have a dependabot security finding not resolving due to a fixed yaml version in cdk8s. 

Finding: cdk8s-team/cdk8s-plus#1977

```
cdk8s@2.7.56 requires yaml@2.0.0-7
cdk8s-cli@1.3.20 requires yaml@2.0.0-7 via a transitive dependency on cdk8s@1.10.54
```

NOTE: 
* Looks like there are some more changes added when I run `npx projen`.
* Yaml `defaultOptions` for schema was removed in an update. Recommendation is to explicitly mention the version in `parse and document`. Related PR: eemeli/yaml#346
  • Loading branch information
vinayak-kukreja committed May 15, 2023
1 parent 190ea12 commit 3801c95
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 23 deletions.
1 change: 0 additions & 1 deletion .projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions .projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions .projenrc.js
Expand Up @@ -12,7 +12,7 @@ const project = new Cdk8sTeamJsiiProject({
],

bundledDeps: [
'yaml@2.0.0-7',
'yaml',
'follow-redirects',
'fast-json-patch',
],
Expand Down Expand Up @@ -42,9 +42,6 @@ const project = new Cdk8sTeamJsiiProject({
},
},
golangBranch: '2.x',
depsUpgradeOptions: {
exclude: ['yaml'],
},
});

// _loadurl.js is written in javascript so we need to commit it and also copy it
Expand Down
2 changes: 1 addition & 1 deletion package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/yaml.ts
Expand Up @@ -9,7 +9,7 @@ const MAX_DOWNLOAD_BUFFER = 10 * 1024 * 1024;
// Set default YAML schema to 1.1. This ensures saved YAML is backward compatible with other parsers, such as PyYAML
// It also ensures that octal numbers in the form `0775` will be parsed
// correctly on YAML load. (see https://github.com/eemeli/yaml/issues/205)
YAML.defaultOptions.version = '1.1';
const yamlSchemaVersion = '1.1';

/**
* YAML utilities.
Expand Down Expand Up @@ -72,7 +72,9 @@ export class Yaml {
public static load(urlOrFile: string): any[] {
const body = loadurl(urlOrFile);

const objects = YAML.parseAllDocuments(body);
const objects = YAML.parseAllDocuments(body, {
version: yamlSchemaVersion,
});
const result = new Array<any>();

for (const obj of objects.map(x => x.toJSON())) {
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/yaml.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion test/app.test.ts
Expand Up @@ -44,7 +44,9 @@ test('can hook into chart synthesis with during synthYaml', () => {
}

new MyChart(app, 'Chart');
const manifest = YAML.parseAllDocuments(app.synthYaml());
const manifest = YAML.parseAllDocuments(app.synthYaml(), {
version: '1.1',
});
expect(manifest.length).toEqual(1);
expect(manifest[0].get('kind')).toEqual('Kind2');

Expand Down
4 changes: 3 additions & 1 deletion test/include.test.ts
Expand Up @@ -11,7 +11,9 @@ test('Include can be used to load from YAML', () => {
new Include(chart, 'guestbook', { url: source });

// THEN
const expected = yaml.parseAllDocuments(fs.readFileSync(source, 'utf-8')).map(x => x.toJSON());
const expected = yaml.parseAllDocuments(fs.readFileSync(source, 'utf-8'), {
version: '1.1',
}).map(x => x.toJSON());
const actual = Testing.synth(chart);
expect(actual).toStrictEqual(expected);
});
Expand Down
7 changes: 1 addition & 6 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3801c95

Please sign in to comment.