Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Avoid inline script execution for injecting CSRF token#7016

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
juspence merged 1 commit intoencode:masterfromlukaw3d:csp-unsafe-script
Nov 29, 2022

Conversation

@lukaw3d
Copy link
Contributor

@lukaw3dlukaw3d commentedOct 24, 2019
edited
Loading

Description

Scripts with type="application/json" or "text/plain" are not executed, so we can use them to inject dynamic CSRF data, without allowing inline-script execution in Content-Security-Policy.

This helps towards fixing#6069 a bit.

@Farisiimoet3
Copy link

Unsubscribe

lukaw3d reacted with thumbs down emoji

@stale
Copy link

stalebot commentedJun 23, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stalestalebot added the stale labelJun 23, 2022
@stalestalebot removed the stale labelJun 25, 2022
@lukaw3dlukaw3d changed the titleSeparate CSRF data from executed javascript code to support CSPAvoid inline script execution for injecting CSRF tokenJun 25, 2022
Scripts with type="application/json" or "text/plain" are not executed, so we canuse them to inject dynamic CSRF data, without allowing inline-script executionin Content-Security-Policy.
@stale
Copy link

stalebot commentedOct 16, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stalestalebot added the stale labelOct 16, 2022
@juspence
Copy link
Contributor

@tomchristie Is there any way I can help get this PR (as well as#5740 and#7960) merged? I'm happy to help test and provide feedback. Merging any of these would help to resolve#6069, which is blocking me from using stricter Cross-Site Scripting (XSS) protections.

@twbagustin
Copy link

Replying on this one seems more up to date, since#5740 seems a bit outdated (shows conflicts),#7960 does seem a bit off becauserequest.csp_nonce is something added by another package (https://github.com/mozilla/django-csp)
Here it's missing the ajax form submission thinghttps://github.com/encode/django-rest-framework/blob/3.14.0/rest_framework/templates/rest_framework/base.html#L302
What I've done locally is moving this$('form').ajaxForm(); insidestatic/rest_framework/default.js (seems like the right place)
and updatingstatic/rest_framework/crsf.js exactly as you are doing here, reading JSON from the template thus the update ontemplates/rest_framework/base.html
Subscribing for the notifications :D

@lovelydinosaur
Copy link
Contributor

@tomchristie Is there any way I can help get this PR (as well as#5740 and#7960) merged?

I'm happy to add collaborators to the @encode/django-rest-framework team if asked.
That'll give folks review and merge permissions on pull requests.

@juspence
Copy link
Contributor

@tomchristie I can't commit to spending any effort beyond this one feature. If that's still OK, please add me to the encode/drf team, and I'll review, test, and merge these three PRs (#5740,#7016, and#7960). Thank you!

@auvipy
Copy link
Collaborator

auvipy commentedNov 29, 2022
edited
Loading

@tomchristie I can't commit to spending any effort beyond this one feature. If that's still OK, please add me to the encode/drf team, and I'll review, test, and merge these three PRs (#5740,#7016, and#7960). Thank you!

you can handle this one and I can help you review and merge this. we now have 3 more new maintainers. can you test and share your feedback on this PR? after your confirmation I can merge it. the other open PR's need more works before merge.

@auvipyauvipy self-requested a reviewNovember 29, 2022 07:57
@lovelydinosaur
Copy link
Contributor

@juspence - Invite sent.

juspence reacted with thumbs up emojijuspence reacted with heart emoji

@juspence
Copy link
Contributor

juspence commentedNov 29, 2022
edited
Loading

@auvipy This looks good to me. I tested Django-REST-Framework without this change in Firefox 102.4.0esr and Chrome 106.0.5249.119, using a Content-Security-Policy like "script-src: 'self'" that doesn't allow inline scripts.

I saw the below error for the CSRF script in the developer console, like I expected:

Content Security Policy: The page’s settings blocked the loading of a resource at inline (“script-src”). [components:334:1](http://localhost:8008/api/v1/components)Uncaught TypeError: window.drf is undefined    <anonymous> http://localhost:8008/static/rest_framework/js/csrf.js:41[csrf.js:41:17](http://localhost:8008/static/rest_framework/js/csrf.js)    <anonymous> http://localhost:8008/static/rest_framework/js/csrf.js:41

Then I tested again with this change, and the above error went away.

@lovelydinosaur
Copy link
Contributor

@juspence - Great. You're welcome to approve pull requests that you're happy with.

@juspencejuspence self-assigned thisNov 29, 2022
@juspencejuspence self-requested a reviewNovember 29, 2022 16:08
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@auvipyauvipyAwaiting requested review from auvipy

1 more reviewer

@juspencejuspencejuspence approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

@juspencejuspence

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

6 participants

@lukaw3d@Farisiimoet3@juspence@twbagustin@lovelydinosaur@auvipy

[8]ページ先頭

©2009-2025 Movatter.jp