-
Notifications
You must be signed in to change notification settings - Fork 2k
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
@uppy/companion: add oauthOrigin
option
#5297
Merged
Merged
Conversation
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
Diff output filesdiff --git a/packages/@uppy/companion/lib/server/controllers/connect.js b/packages/@uppy/companion/lib/server/controllers/connect.js
index ceac203..49b0c5c 100644
--- a/packages/@uppy/companion/lib/server/controllers/connect.js
+++ b/packages/@uppy/companion/lib/server/controllers/connect.js
@@ -14,11 +14,24 @@ const queryString = (params, prefix = "?") => {
*/
module.exports = function connect(req, res) {
var _a;
- const { secret } = req.companion.options;
+ const { secret, oauthOrigin } = req.companion.options;
const stateObj = oAuthState.generateState();
- if (req.query.state) {
+ // not sure if we need to store origin in the session state (e.g. we could've just gotten it directly inside send-token)
+ // but we're afraid to change the logic there
+ if (oauthOrigin && !Array.isArray(oauthOrigin)) {
+ // If the server only allows a single origin, we ignore the client-supplied
+ // origin from query because we don't need it.
+ stateObj.origin = oauthOrigin;
+ } else if (oauthOrigin && oauthOrigin.length < 2) {
+ // eslint-disable-next-line prefer-destructuring
+ stateObj.origin = oauthOrigin[0];
+ } else {
+ // If we have multiple allowed origins, we need to check the client-supplied origin from query.
+ // If the client provides an untrusted origin,
+ // we want to send `undefined`. `undefined` means `/`, which is the same origin when passed to `postMessage`.
+ // https://html.spec.whatwg.org/multipage/web-messaging.html#dom-window-postmessage-options-dev
const { origin } = JSON.parse(atob(req.query.state));
- stateObj.origin = origin;
+ stateObj.origin = oauthOrigin ? oauthOrigin.find(o => o === origin) : origin;
}
if (req.companion.options.server.oauthDomain) {
stateObj.companionInstance = req.companion.buildURL("", true);
diff --git a/packages/@uppy/companion/lib/standalone/helper.js b/packages/@uppy/companion/lib/standalone/helper.js
index 6a83a86..d42c91c 100644
--- a/packages/@uppy/companion/lib/standalone/helper.js
+++ b/packages/@uppy/companion/lib/standalone/helper.js
@@ -62,6 +62,7 @@ const defaultStandaloneGetKey = (...args) => `${s3Prefix}${utils.defaultGetKey(.
* @returns {object}
*/
const getConfigFromEnv = () => {
+ var _a;
const uploadUrls = process.env.COMPANION_UPLOAD_URLS;
const domains = process.env.COMPANION_DOMAINS || process.env.COMPANION_DOMAIN || null;
const validHosts = domains ? domains.split(",") : [];
@@ -180,6 +181,9 @@ const getConfigFromEnv = () => {
corsOrigins: getCorsOrigins(),
testDynamicOauthCredentials: process.env.COMPANION_TEST_DYNAMIC_OAUTH_CREDENTIALS === "true",
testDynamicOauthCredentialsSecret: process.env.COMPANION_TEST_DYNAMIC_OAUTH_CREDENTIALS_SECRET,
+ oauthOrigin: ((_a = process.env.COMPANION_OAUTH_ORIGIN) === null || _a === void 0 ? void 0 : _a.includes(","))
+ ? process.env.COMPANION_OAUTH_ORIGIN.split(",")
+ : process.env.COMPANION_OAUTH_ORIGIN,
};
};
/** |
Murderlon
reviewed
Jul 2, 2024
Co-authored-by: Merlijn Vos <[email protected]>
aduh95
commented
Jul 2, 2024
aduh95
commented
Jul 2, 2024
This was referenced Jul 2, 2024
github-actions bot
added a commit
that referenced
this pull request
Jul 2, 2024
| Package | Version | Package | Version | | ---------------------- | ------- | ---------------------- | ------- | | @uppy/companion | 4.15.0 | @uppy/drag-drop | 3.1.1 | | @uppy/companion-client | 3.8.2 | @uppy/form | 3.2.2 | | @uppy/core | 3.13.1 | uppy | 3.27.2 | - @uppy/form: do not emit `'submit'` event more than once (Merlijn Vos / #5299) - @uppy/companion: add `s3.forcePathStyle` option (Nadeem Reinhardt / #5066) - meta: fix broken workflow status badges in README (Alexander Zaytsev / #5298) - @uppy/core: add `clearUploadedFiles` to type definition (Augustine Smith / #5295) - @uppy/companion: add `oauthOrigin` option (Antoine du Hamel / #5297) - meta: add dark-mode Transloadit logo in README (Alexander Zaytsev / #5291) - docs,@uppy/drag-drop: `uppy.io/docs` - fix typos/broken links (Evgenia Karunus / #5296) - meta: Bump docker/build-push-action from 6.1.0 to 6.2.0 (dependabot[bot] / #5290)
6 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.