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

aws-lambda-nodejs: banner and footer values are not escaped #13576

Closed
moltar opened this issue Mar 13, 2021 · 15 comments · Fixed by #14743
Closed

aws-lambda-nodejs: banner and footer values are not escaped #13576

moltar opened this issue Mar 13, 2021 · 15 comments · Fixed by #14743
Assignees
Labels
@aws-cdk/aws-lambda-nodejs bug This issue is a bug. effort/small Small work item – less than a day of effort needs-triage This issue or PR still needs to be triaged. p1

Comments

@moltar
Copy link
Contributor

moltar commented Mar 13, 2021

Source:

...this.props.banner ? [`--banner='${this.props.banner}'`] : [],
...this.props.footer ? [`--footer='${this.props.footer}'`] : [],

The values for banner and footer are not properly escaped for shell execution, resulting in errors, and potentially a command injection!

❯ cdk synth
Bundling asset ACPipelineStack/Staging/AtlanticCoreApp/.../Code/Stage...
 > error: Invalid build flag: "--banner=// Source: ./src/modules/foo/index.ts\n\n"

Reproduction Steps

    const defaultProperties: NodejsFunctionProps = {
      bundling: {
        banner: `// Source: ./src/modules/foo/index.ts`,
      },
    }

What did you expect to happen?

Values to be escaped.

What actually happened?

Ran as is, without escaping.

Environment

  • CDK CLI Version: 1.93.0
  • Framework Version: 1.93.0
  • Node.js Version: v14.15.5
  • OS : macOS
  • Language (Version): TypeScript (3.8.3)

Other

    "@aws-cdk/aws-lambda-nodejs": "1.93.0",

This is 🐛 Bug Report

@moltar moltar added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 13, 2021
@jogold
Copy link
Contributor

jogold commented Mar 14, 2021

+ --banner is now --banner:js and --banner:css (https://github.com/evanw/esbuild/blob/master/CHANGELOG.md#090)

@eladb
Copy link
Contributor

eladb commented Mar 18, 2021

Can this be closed?

@moltar
Copy link
Contributor Author

moltar commented Mar 18, 2021

@eladb Has it been fixed?

@eladb
Copy link
Contributor

eladb commented Mar 18, 2021

No, apologies I misunderstood @jogold's comment.

Contributions are welcome.

Keeping open

@eladb eladb added p1 effort/small Small work item – less than a day of effort labels Mar 18, 2021
@eladb eladb removed their assignment Mar 18, 2021
@jogold
Copy link
Contributor

jogold commented Mar 18, 2021

@eladb it's an easy fix here but what do you suggest for the breaking change? how should we handle esbuild breaking changes since we don't depend on it?

@eladb
Copy link
Contributor

eladb commented Mar 18, 2021

Aren't we checking that we use a compatible major version?

@jogold
Copy link
Contributor

jogold commented Mar 18, 2021

Aren't we checking that we use a compatible major version?

Yes but esbuild is currently on 0.x... meaning that we need to check the minor, should I do that? This is very restrictive.

@eladb
Copy link
Contributor

eladb commented Mar 18, 2021

I don't see any other reliable way. Perhaps we can add a switch to opt-out of version check if people insist they want to use a newer version

@gurshafriri
Copy link

👋 @eladb, do you see this as a valid potential security issue?
If it is, we (at snyk) would like to add it to our vulnerability DB, better with a fixed version at hand.

@eladb
Copy link
Contributor

eladb commented Apr 11, 2021

@gurshafriri Are you on CDK.dev slack? I'd like to discuss this with you directly

@nihalgonsalves
Copy link

nihalgonsalves commented Apr 13, 2021

@eladb would you accept a pull request to switch to the esbuild JavaScript API? This would eliminate bugs such as this and #13842 / #14065, and would enable the construct to allow custom config overrides for the esbuild settings.

@eladb
Copy link
Contributor

eladb commented Apr 13, 2021

@nihalgonsalves we have considered this in the past and decided that this is not the best approach. @jogold can shed some light.

@eladb
Copy link
Contributor

eladb commented May 18, 2021

@jogold let's first escape the shell command. I think JSON.stringify(x) should do the trick, correct?

As for breaking changes in esbuild, I believe in this case, we don't have to break the construct API, correct? Just use the new API from esbuild.

@eladb eladb self-assigned this May 18, 2021
@jogold
Copy link
Contributor

jogold commented May 18, 2021

@jogold let's first escape the shell command. I think JSON.stringify(x) should do the trick, correct?

Will have a look.

As for breaking changes in esbuild, I believe in this case, we don't have to break the construct API, correct? Just use the new API from esbuild.

Correct because we don't care about --banner:css here.

@mergify mergify bot closed this as completed in #14743 May 18, 2021
mergify bot pushed a commit that referenced this issue May 18, 2021
Escape values and use the new CLI options.

Closes #13576 

BREAKING CHANGE: using `banner` and `footer` now requires `esbuild` >= 0.9.0


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

hollanddd pushed a commit to hollanddd/aws-cdk that referenced this issue Aug 26, 2021
Escape values and use the new CLI options.

Closes aws#13576 

BREAKING CHANGE: using `banner` and `footer` now requires `esbuild` >= 0.9.0


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda-nodejs bug This issue is a bug. effort/small Small work item – less than a day of effort needs-triage This issue or PR still needs to be triaged. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants