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

@tus/server: add allowedCredentials and allowedOrigins options #636

Merged
merged 12 commits into from
Sep 5, 2024

Conversation

idanto
Copy link
Contributor

@idanto idanto commented Jul 25, 2024

Hi,

Uppy client supports withCredentials parameter to allow sending tokens in cookie
https://uppy.io/docs/tus/#withcredentials

Tus Server doesn't allow any way to configure it; it seems like a missing configuration, and this MR is a suggestion on how to implement it.

Copy link

changeset-bot bot commented Jul 25, 2024

🦋 Changeset detected

Latest commit: 43549b7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@tus/server Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Acconut
Copy link
Member

Acconut commented Jul 25, 2024

Should the user also be able to enable this only for requests from certain origins? Allowing it from arbitrary origins is potentially dangerous.

@idanto
Copy link
Contributor Author

idanto commented Jul 25, 2024

Should the user also be able to enable this only for requests from certain origins? Allowing it from arbitrary origins is potentially dangerous.

@Acconut, isn't that what Access-Control-Allow-Origin should do in the CORS policy?

TBH, I don't see a way to limit it in Tus code. I see the opposite which looks like the client can override it by sending an origin header.

@Acconut
Copy link
Member

Acconut commented Jul 25, 2024

If tus-node-server does not yet have a way to restrict CORS access to certain origins, then we should probably add that as well.

@idanto
Copy link
Contributor Author

idanto commented Jul 25, 2024

@Acconut I have also added support for allowedOrigin, which implements a better logic to validate the origin header and prevent some potential XSS attacks.

I'm not quite sure how the tests for this project work and why the failure of the s3 upload test, although I didn't change anything that should affect that. If one of the creators of this project can help figure this out, it will be great.

Copy link
Member

@Murderlon Murderlon left a comment

Choose a reason for hiding this comment

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

Instead of creating an option for some new header every time, we could expose a headers function?

Implementers can sent whatever they want (but we override headers we want to control)

new Server({
  headers(req) {
    return { 'Access-Control-Allow-Credentials': true }
  }
})

@idanto
Copy link
Contributor Author

idanto commented Jul 29, 2024

@Murderlon I agree in general, but this is a special case. Those are CORS options, which is a well-defined standard. In most of the server implementations, I know you usually have specific options to configure your CORS to prevent people from making mistakes (like typos and so on).

@Murderlon
Copy link
Member

My experience is that sooner or later people run into the limitations of these locked down options. For example, people with preview deployments, where the subdomain is dynamic, will not be able to use string[] for their origins.

If we make it RegExp | string[] I'm okay with keeping the options as proposed 👍

@Murderlon
Copy link
Member

@idanto are you still interested in getting this over the finish line?

@Murderlon Murderlon changed the title feat: allow set CORS allow credentials header @tus/server: add allowedCredentials and allowedOrigins options Aug 27, 2024
@idanto
Copy link
Contributor Author

idanto commented Aug 27, 2024 via email

@idanto
Copy link
Contributor Author

idanto commented Sep 3, 2024

@Murderlon looks like after you merge master everything is green

@Murderlon
Copy link
Member

Only this needs to be resolved: #636 (comment).

I can take a look later this week if you don't have time before then.

* main:
  @tus/server: make test less flaky
  Correctly ignore dist/ in biome.json
  Replace Prettier and Eslint with Biome (tus#647)
  Revert "Bump rimraf from 3.0.2 to 6.0.1 (tus#649)"
  Bump sinon from 17.0.1 to 18.0.0 (tus#648)
  Bump rimraf from 3.0.2 to 6.0.1 (tus#649)
@Murderlon Murderlon merged commit ca03351 into tus:main Sep 5, 2024
3 checks passed
@Murderlon
Copy link
Member

Thanks for the contribution

Murderlon added a commit that referenced this pull request Sep 5, 2024
* main:
  [ci] release (#644)
  @tus/server: add allowedCredentials and allowedOrigins options (#636)
  Bump micromatch from 4.0.5 to 4.0.8 (#653)
  @tus/server: make test less flaky
  Correctly ignore dist/ in biome.json
  Replace Prettier and Eslint with Biome (#647)
  Revert "Bump rimraf from 3.0.2 to 6.0.1 (#649)"
  Bump sinon from 17.0.1 to 18.0.0 (#648)
  Bump rimraf from 3.0.2 to 6.0.1 (#649)
  Change name of CI workflow
  Remove turbo (#646)
@idanto
Copy link
Contributor Author

idanto commented Sep 5, 2024

thanks for the help pushing it to the finish line @Murderlon

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