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

USWDS | xss audit, standardization #4329

Merged
merged 34 commits into from
Oct 25, 2021
Merged

USWDS | xss audit, standardization #4329

merged 34 commits into from
Oct 25, 2021

Conversation

scottqueen-bixal
Copy link
Contributor

@scottqueen-bixal scottqueen-bixal commented Sep 23, 2021

Description

It was reported in our community channels that an XSS vulnerability exists in our combo-box.js script, and was resolved and deployed from pull request #4287 .

Similar vulnerabilities could be possible through other components that use innerHTML assignments.

Because of this, we have decided to set up a standard at which we should construct elements while limiting similar vulnerabilities, but without losing the ability to build with those methods.

We have included a new linter plugin eslint-plugin-no-unsanitized created by the folks at mozilla, which,

... disallows unsafe innerHTML, outerHTML, insertAdjacentHTML and alike

This linter will notify contributors when unsafe coding patterns have been used. As the plugin suggests, we recommend,

...to construct DOM nodes using createElement and changing their attributes (e.g., textContent, classList) instead.

When any of these approaches are properly resolved, the linter will no longer throw an error.

We have included the provided sanitizer.js library in our utils which will support fixing these errors. More information can be found in the plugin documentation

  • Follow the 18F Front End Coding Style Guide and Accessibility Guide.
  • Run npm test and make sure the tests for the files you have changed have passed.
  • Run your code through HTML_CodeSniffer and make sure it’s error free.
  • Title your pull request using this format: [Website] - [UI component]: Brief statement describing what this pull request solves.

@scottqueen-bixal scottqueen-bixal changed the title Gsq xss audit USWDS | xss audit, standardization Sep 27, 2021
Copy link
Contributor

@mejiaj mejiaj left a comment

Choose a reason for hiding this comment

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

Minor comment, but otherwise LGTM.


We have some cases of almost duplicate code when checking single or plural. We should refactor in the future.

Examples:
file-input.js:145
file-input.js:282
combobox.js:448

spec/unit/tooltip/tooltips.spec.js Show resolved Hide resolved
const defaultValue = comboBoxEl.dataset.defaultValue;
const placeholder = comboBoxEl.dataset.placeholder;
const {defaultValue} = comboBoxEl.dataset;
const {placeholder} = comboBoxEl.dataset;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we simplify this?

const { defaultValue, placeholder } = comboBoxEl.dataset

@scottqueen-bixal scottqueen-bixal marked this pull request as ready for review October 12, 2021 13:58
@thisisdano thisisdano mentioned this pull request Oct 25, 2021
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants