-
Notifications
You must be signed in to change notification settings - Fork 9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* `test/e2e-cypress/tests/features/xss/` -> `test/e2e-cypress/tests/security` * add tests * filter <style> tags out of Markdown fields * initialize OAuth inputs without applying `value` attribute
- Loading branch information
Showing
11 changed files
with
143 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// This component provides an interface that feels like an uncontrolled input | ||
// to consumers, while providing a `defaultValue` interface that initializes | ||
// the input's value using JavaScript value property APIs instead of React's | ||
// vanilla[0] implementation that uses HTML value attributes. | ||
// | ||
// This is useful in situations where we don't want to surface an input's value | ||
// into the HTML/CSS-exposed side of the DOM, for example to avoid sequential | ||
// input chaining attacks[1]. | ||
// | ||
// [0]: https://github.com/facebook/react/blob/baff5cc2f69d30589a5dc65b089e47765437294b/fixtures/dom/src/components/fixtures/text-inputs/README.md | ||
// [1]: https://github.com/d0nutptr/sic | ||
|
||
import React from "react" | ||
import PropTypes from "prop-types" | ||
|
||
export default class InitializedInput extends React.Component { | ||
componentDidMount() { | ||
// Set the element's `value` property (*not* the `value` attribute) | ||
// once, on mount, if an `initialValue` is provided. | ||
if(this.props.initialValue) { | ||
this.inputRef.value = this.props.initialValue | ||
} | ||
} | ||
|
||
render() { | ||
// Filter out `value` and `defaultValue`, since we have our own | ||
// `initialValue` interface that we provide. | ||
// eslint-disable-next-line no-unused-vars, react/prop-types | ||
const { value, defaultValue, ...otherProps } = this.props | ||
return <input {...otherProps} ref={c => this.inputRef = c} /> | ||
} | ||
} | ||
|
||
InitializedInput.propTypes = { | ||
initialValue: PropTypes.string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
test/e2e-cypress/static/documents/security/sequential-import-chaining/injection.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
* { | ||
color: red !important; /* for humans */ | ||
} | ||
|
||
h4 { | ||
display: none; /* for machines, used to trace whether this sheet is applied */ | ||
} |
10 changes: 10 additions & 0 deletions
10
test/e2e-cypress/static/documents/security/sequential-import-chaining/openapi.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
openapi: "3.0.0" | ||
|
||
info: | ||
title: Sequential Import Chaining | ||
description: > | ||
<h4>This h4 would be hidden by the injected CSS</h4> | ||
This document tests the ability of a `<style>` tag in a Markdown field to pull in a remote stylesheet using an `@import` directive. | ||
<style>@import url(/documents/security/sequential-import-chaining/injection.css);</style> |
10 changes: 10 additions & 0 deletions
10
test/e2e-cypress/static/documents/security/sequential-import-chaining/swagger.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
swagger: "2.0" | ||
|
||
info: | ||
title: Sequential Import Chaining | ||
description: > | ||
<h4>This h4 would be hidden by the injected CSS</h4> | ||
This document tests the ability of a `<style>` tag in a Markdown field to pull in a remote stylesheet using an `@import` directive. | ||
<style>@import url(/documents/security/sequential-import-chaining/injection.css);</style> |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
.../e2e-cypress/tests/features/xss/oauth2.js → test/e2e-cypress/tests/security/oauth2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
test/e2e-cypress/tests/security/sequential-import-chaining.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
describe("Security: CSS Sequential Import Chaining", () => { | ||
describe("in OpenAPI 3.0", () => { | ||
describe("CSS Injection via Markdown", () => { | ||
it("should filter <style> tags out of Markdown fields", () => { | ||
cy.visit("/?url=/documents/security/sequential-import-chaining/openapi.yaml") | ||
.get("div.information-container") | ||
.should("exist") | ||
.and("not.have.descendants", "style") | ||
}) | ||
it("should not apply `@import`ed CSS stylesheets", () => { | ||
cy.visit("/?url=/documents/security/sequential-import-chaining/openapi.yaml") | ||
.wait(500) // HACK: wait for CSS import to settle | ||
.get("div.info h4") | ||
.should("have.length", 1) | ||
.and("not.be.hidden") | ||
}) | ||
}) | ||
describe("Value Exfiltration via CSS", () => { | ||
it("should not allow OAuth credentials to be visible via HTML `value` attribute", () => { | ||
cy.visit("/?url=/documents/petstore-expanded.openapi.yaml") | ||
.get(".scheme-container > .schemes > .auth-wrapper > .btn > span") | ||
.click() | ||
.get("div > div > .wrapper > .block-tablet > #client_id") | ||
.clear() | ||
.type("abc") | ||
.should("not.have.attr", "value", "abc") | ||
}) | ||
}) | ||
}) | ||
describe("in Swagger 2.0", () => { | ||
describe("CSS Injection via Markdown", () => { | ||
it("should filter <style> tags out of Markdown fields", () => { | ||
cy.visit("/?url=/documents/security/sequential-import-chaining/swagger.yaml") | ||
.get("div.information-container") | ||
.should("exist") | ||
.and("not.have.descendants", "style") | ||
}) | ||
it("should not apply `@import`ed CSS stylesheets", () => { | ||
cy.visit("/?url=/documents/security/sequential-import-chaining/swagger.yaml") | ||
.wait(500) // HACK: wait for CSS import to settle | ||
.get("div.info h4") | ||
.should("have.length", 1) | ||
.and("not.be.hidden") | ||
}) | ||
}) | ||
describe("Value Exfiltration via CSS", () => { | ||
it("should not allow OAuth credentials to be visible via HTML `value` attribute", () => { | ||
cy.visit("/?url=/documents/petstore.swagger.yaml") | ||
.get(".scheme-container > .schemes > .auth-wrapper > .btn > span") | ||
.click() | ||
.get("div > div > .wrapper > .block-tablet > #client_id") | ||
.clear() | ||
.type("abc") | ||
.should("not.have.attr", "value", "abc") | ||
}) | ||
}) | ||
}) | ||
}) |