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

safely escape <script> injected code #3101

Merged
merged 3 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/@uppy/companion/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"request": "2.88.2",
"semver": "6.3.0",
"serialize-error": "^2.1.0",
"serialize-javascript": "^6.0.0",
"tus-js-client": "2.1.1",
"uuid": "8.1.0",
"validator": "^12.1.0",
Expand Down
6 changes: 4 additions & 2 deletions packages/@uppy/companion/src/server/controllers/send-token.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const { URL } = require('url')
const serialize = require('serialize-javascript')

const tokenService = require('../helpers/jwt')
const { hasMatch, sanitizeHtml } = require('../helpers/utils')
const { hasMatch } = require('../helpers/utils')
const oAuthState = require('../helpers/oauth-state')

/**
Expand All @@ -15,7 +17,7 @@ const htmlContent = (token, origin) => {
<head>
<meta charset="utf-8" />
<script>
window.opener.postMessage(${sanitizeHtml(JSON.stringify({ token }))}, ${sanitizeHtml(JSON.stringify(origin))})
window.opener.postMessage(${serialize({ token })}, ${serialize(origin)})
window.close()
</script>
</head>
Expand Down
9 changes: 0 additions & 9 deletions packages/@uppy/companion/src/server/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@ exports.jsonStringify = (data) => {
})
}

/**
* Does a simple html sanitization on the passed value
*
* @param {string} text
*/
exports.sanitizeHtml = (text) => {
return text ? text.replace(/<\/?[^>]+(>|$)/g, '') : text
}

// all paths are assumed to be '/' prepended
/**
* Returns a url builder
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/companion/test/__tests__/callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('test authentication callback', () => {
<head>
<meta charset="utf-8" />
<script>
window.opener.postMessage({"token":"${token}"}, "http://localhost:3020")
window.opener.postMessage({"token":"${token}"}, "http:\\u002F\\u002Flocalhost:3020")
window.close()
</script>
</head>
Expand Down