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

[Snyk: High] Arbitrary Code Execution in sanitize-html (due 10/9/20) #4026

Closed
1 task
Tracked by #137
lbeaufort opened this issue Sep 9, 2020 · 9 comments · Fixed by #4500
Closed
1 task
Tracked by #137

[Snyk: High] Arbitrary Code Execution in sanitize-html (due 10/9/20) #4026

lbeaufort opened this issue Sep 9, 2020 · 9 comments · Fixed by #4500
Assignees
Labels
Security: high Remediate within 30 days
Milestone

Comments

@lbeaufort
Copy link
Member

lbeaufort commented Sep 9, 2020

Vulnerable module: sanitize-html

Introduced through: sanitize-html@1.18.4
No known exploit
Fixed in: 2.0.0-beta

Detailed paths
Introduced through: fec-cms@1.0.0 › sanitize-html@1.18.4
Remediation: No remediation path available.

Overview
sanitize-html is a library that allows you to clean up user-submitted HTML, preserving whitelisted elements and whitelisted attributes on a per-element basis

Affected versions of this package are vulnerable to Arbitrary Code Execution. Tag transformations which turn an attribute value into a text node using transformTags could be vulnerable to code execution.

Completion criteria:

  • Verify that this is an issue and if it is take appropriate to address the vulnerability
@johnnyporkchops
Copy link
Contributor

johnnyporkchops commented Sep 23, 2020

html-sanitize is used in helpers.js to build the sanitizeValue() function:

This is currently used in typeahead.js here:

And. in filter-typeahead.js:

While the Snyk alert says "No remediation paths available", it says "Fixed in Beta 2.0". Clicking through to "More about this issue" link, then confusingly says "Remediation Upgrade sanitize-html to version 2.0.0-beta or higher"

Attempts to upgrade to the 2.0 release candidate (or any of the 2.0 Beta versions)fails JS tests.

There are other possible alternatives which I was unsuccessful in using as a replacement, but need more research on their usage:
https://github.com/cure53/DOMPurify
-For DOMPurify We need to figure out how to require and use them in the scripts. DOMPurify is not as straightforward as requiring as a variable and replacing html-sanitize.
https://github.com/yahoo/xss-filters
-To use xss-filters requires that we choose the filter we want to use along with the require variable (i.e: xssFilters.inHTMLData(value)

@johnnyporkchops
Copy link
Contributor

johnnyporkchops commented Sep 24, 2020

SInce the above comment, version 2.0.0 of sanitize-html has been released and Snyk remediation path has been updated to Upgrade to sanitize-html@2.0.0. However, this upgrade still fails test related to postcss module
Upgrade PR: #4069

@johnnyporkchops
Copy link
Contributor

In package-.lock.json, we have postcss 8.0.9, sanitize-html has 8.0.2 listed there as requirement. Tried downgrading to 8.0.2 locally and get same errors.

@dorothyyeager
Copy link
Contributor

No remediation path at this time.

@jason-upchurch
Copy link
Contributor

jason-upchurch commented Oct 6, 2020

Hi @johnnyporkchops, I was looking at other vulnerabilities in fec-cms and saw this changelog from sanitize-html in case it's useful at all:

Backwards compatibility breaks:
There is no build. You should no longer directly link to a sanitize-html file directly in the browser as it is using modern Javascript that is not fully supported by all major browsers (depending on your definition). You should now include sanitize-html in your project build for this purpose if you have one.
On the server side, Node.js 10 or higher is required.
The default allowedTags array was updated significantly. This mostly added HTML tags to be more comprehensive by default. You should review your projects and consider the allowedTags defaults if you are not already overriding them.

(ref: https://github.com/apostrophecms/sanitize-html/blob/main/CHANGELOG.md)

@johnnyporkchops
Copy link
Contributor

The recommended remediation path , upgrade to 2.0.0, now fails upon npm run build, whereas before it was only failing pytest.
Still no remediation path available.

Error related to postcss, research has been unfruitful in targeting the error related to this module:

ERROR in ../node_modules/postcss/lib/lazy-result.js
    Module parse failed: Unexpected token (107:21)
    You may need an appropriate loader to handle this file type.
    | 
    |     this.result = new Result(processor, root, opts)
    |     this.helpers = { ...postcss, result: this.result, postcss }
    |     this.plugins = this.processor.plugins.map(plugin => {
    |       if (typeof plugin === 'object' && plugin.prepare) {
     @ ../node_modules/postcss/lib/postcss.js 5:17-41
     @ ../node_modules/sanitize-html/index.js
     @ ./fec/static/js/modules/helpers.js
     @ ./fec/static/js/widgets/aggregate-totals-box.js
    
    ERROR in ../node_modules/postcss/lib/declaration.js
    Module parse failed: Unexpected token (12:19)
    You may need an appropriate loader to handle this file type.
    |       typeof defaults.value !== 'string'
    |     ) {
    |       defaults = { ...defaults, value: String(defaults.value) }
    |     }
    |     super(defaults)
     @ ../node_modules/postcss/lib/postcss.js 4:18-42
     @ ../node_modules/sanitize-html/index.js
     @ ./fec/static/js/modules/helpers.js
     @ ./fec/static/js/widgets/aggregate-totals-box.js

@rfultz rfultz modified the milestones: Sprint 13.9, Sprint 13.10 Dec 11, 2020
@rfultz
Copy link
Contributor

rfultz commented Dec 15, 2020

Moving to Blocked since this is a lower risk vulnerability for us and has so many other hurdles

@rfultz rfultz removed this from the Sprint 13.10 milestone Dec 15, 2020
@lbeaufort lbeaufort assigned lbeaufort and unassigned lbeaufort Dec 17, 2020
@JonellaCulmer JonellaCulmer added this to the Sprint 14.1 milestone Feb 17, 2021
@JonellaCulmer JonellaCulmer modified the milestones: Sprint 14.1, Sprint 14.2 Mar 9, 2021
@lbeaufort
Copy link
Member Author

We removed sanitize-html with this PR: #4500

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Security: high Remediate within 30 days
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants