Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cdk): cdk depends on a version of netmask impacted by cve-2021-28918 #13910

Closed
wants to merge 11 commits into from

Conversation

nija-at
Copy link
Contributor

@nija-at nija-at commented Mar 31, 2021

The fix here is to fork and vendor in the npm package proxy-agent.
Further, apply a patch to remove the support for 'pac' protocol.

The implication of this is that the 'pac' protocols are no longer
supported by the proxy feature of the AWS CDK.

This will be reverted once the upstream node packages upgrade
to netmask@2.0.1 or greater.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

Niranjan Jayakar and others added 10 commits March 30, 2021 15:17
netmask@1 is affected by CVE-2021-28918
GHSA-pch5-whg9-qr2r

netmask is a depdendency to the CDK via

  aws-cdk → proxy-agent@4.0.1 → pac-proxy-agent@4.1.0 →
  pac-resolver@4.1.0 → netmask@1.0.6

None of these dependencies have upgraded to netmask@2 as yet.

Use yarn's [selective dependency resolution], to explicitly pick
netmask@2. This upgrades yarn.lock and the CLI's npm-shrinkwrap.json.
With this fix, npm customers will no longer depend on netmask@2
transitively via the CDK.

For yarn customers, there is no clean resolution since yarn does not
respective the the 'resolutions' key in dependencies' package.json and
does not respect the shrinkwrap.
The init templates now ship the 'resolutions' key so that new customers
using yarn will be unaffected.

A different solution has to be devised for existing customers on yarn.

[selective dependency resolution]: https://classic.yarnpkg.com/en/docs/selective-version-resolutions/

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
see [CHANGELOG](https://github.com/aws/aws-cdk/blob/71a39b2955fa1ec40e5c8d138c78874c45f21e26/CHANGELOG.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
The 'requires' clause in the generated shrinkwrap still refers to
netmask@1. Hot patch this version.

This is being applied on the release branch, since it's terribly
hackery. A proper fix on master needs to be applied before the next
minor version release.
@nija-at nija-at requested review from rix0rrr and a team March 31, 2021 17:46
@nija-at nija-at self-assigned this Mar 31, 2021
@gitpod-io
Copy link

gitpod-io bot commented Mar 31, 2021

@nija-at nija-at added the pr/do-not-merge This PR should not be merged at this time. label Mar 31, 2021
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Mar 31, 2021
@nija-at
Copy link
Contributor Author

nija-at commented Mar 31, 2021

Testing

  • Verify that a normal http proxy works as expected
  • Verify that an error message is produced if the proxy uses one of the 'pac' protocols
  • Verify installation and proxy functionality
  • Verify npmignore is correctly recognized
  • Verify netmask dependency is removed from lock and shrinkwrap files

@nija-at nija-at force-pushed the nija-at/proxy-agent-fork branch from 7746fb5 to 00fec6e Compare March 31, 2021 17:52
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 00fec6e
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@nija-at nija-at changed the title fix(cdk): cdk depends on a version of netmas impacted by cve-2021-28918 fix(cdk): cdk depends on a version of netmask impacted by cve-2021-28918 Apr 1, 2021
Comment on lines +20 to +21
"resolutions": {
"netmask": "^2.0.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are those necessary? I mean they'll be shipping with a newer CLI that has a corrected dependency...

"http-proxy-agent",
"https-proxy-agent",
"lru-cache",
"pac-proxy-agent",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well technically - you're removing this one aren't you?

@@ -383,7 +383,7 @@ function parseHttpOptions(options: SdkHttpOptions) {
// https://aws.amazon.com/blogs/developer/using-the-aws-sdk-for-javascript-from-behind-a-proxy/
debug('Using proxy server: %s', proxyAddress);
// eslint-disable-next-line @typescript-eslint/no-require-imports
const ProxyAgent: any = require('proxy-agent');
const ProxyAgent: any = require('../../../proxy-agent');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would recommend making it such that it's:

Suggested change
const ProxyAgent: any = require('../../../proxy-agent');
const ProxyAgent: any = require('../../../vendor/proxy-agent');

@nija-at
Copy link
Contributor Author

nija-at commented Apr 1, 2021

superceded by #13914

@nija-at nija-at closed this Apr 1, 2021
@nija-at nija-at deleted the nija-at/proxy-agent-fork branch April 1, 2021 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS. pr/do-not-merge This PR should not be merged at this time.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants