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

Specify the content type of the 404 response #33502

Merged
merged 2 commits into from Mar 9, 2020
Merged

Conversation

bethanyaconnor
Copy link
Contributor

@bethanyaconnor bethanyaconnor commented Mar 6, 2020

Currently if you go to studio.code.org/foo.js you get a 500 when you should get a 404 error.

I turned off consider_all_requests_local in development.rb and could reproduce the 500 error. The error message I got:

Error during failsafe response: Security warning: an embedded <script> tag on another site requested protected JavaScript. If you know what you're doing, go ahead and disable forgery protection on this action to permit cross-origin JavaScript embedding.

Because the requested file is *.js, the return type is inferred to be text/javascript so Rails throws an InvalidCrossOriginRequest exception. The fix is just to specify the return type as text/html.

Sources

  1. https://die-antwort.eu/techblog/2018-08-avoid-invalid-cross-origin-request-with-catch-all-route/
  2. https://gitlab.com/gitlab-org/gitlab-foss/-/issues/40771

Links

Reviewer Checklist:

  • Tests provide adequate coverage
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

Copy link
Member

@davidsbailey davidsbailey left a comment

Choose a reason for hiding this comment

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

Nice find, nice fix!

@bethanyaconnor bethanyaconnor merged commit 734ed3e into staging Mar 9, 2020
@bethanyaconnor bethanyaconnor deleted the 404-on-unknown-js branch March 9, 2020 16:46
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.

None yet

2 participants