aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/security.md
diff options
context:
space:
mode:
authorJeremy Daer <jeremydaer@gmail.com>2015-09-16 08:52:21 -0700
committerJeremy Daer <jeremydaer@gmail.com>2015-09-16 08:56:16 -0700
commit4d77e02d344349e899d6c4c5e10b1879867b72eb (patch)
treecc8a0bfb52de2b1af05f45f672f0a616d82cd91d /guides/source/security.md
parent7a93952287e4638063fb88ff0138febb6079c778 (diff)
downloadrails-4d77e02d344349e899d6c4c5e10b1879867b72eb.tar.gz
rails-4d77e02d344349e899d6c4c5e10b1879867b72eb.tar.bz2
rails-4d77e02d344349e899d6c4c5e10b1879867b72eb.zip
Clarify CSRF <script> purpose and protection. Note how to deal with your own <script> tags.
Ref #21618 [ci skip]
Diffstat (limited to 'guides/source/security.md')
-rw-r--r--guides/source/security.md4
1 files changed, 3 insertions, 1 deletions
diff --git a/guides/source/security.md b/guides/source/security.md
index 772a0b474c..5a6ac9446a 100644
--- a/guides/source/security.md
+++ b/guides/source/security.md
@@ -245,7 +245,9 @@ Or the attacker places the code into the onmouseover event handler of an image:
<img src="http://www.harmless.com/img" width="400" height="400" onmouseover="..." />
```
-There are many other possibilities, like using a `<script>` tag to make a cross-site request to a URL with a JSONP or JavaScript response. The response is executable code that the attacker can find a way to run, possibly extracting sensitive data. To protect against this data leakage, we disallow dynamic JS responses for anything other than ajax requests irrespective of the origin. Only Ajax requests may have JavaScript responses since `XmlHttpRequest` is subject to the browser Same-Origin policy - meaning only your site can initiate ajax requests.
+There are many other possibilities, like using a `<script>` tag to make a cross-site request to a URL with a JSONP or JavaScript response. The response is executable code that the attacker can find a way to run, possibly extracting sensitive data. To protect against this data leakage, we must disallow cross-site `<script>` tags. Ajax requests, however, obey the browser's same-origin policy (only your own site is allowed to initiate `XmlHttpRequest`) so we can safely allow them to return JavaScript responses.
+
+Note: We can't distinguish a `<script>` tag's origin—whether it's a tag on your own site or on some other malicious site—so we must block all `<script>` across the board, even if it's actually a safe same-origin script served from your own site. In these cases, explicitly skip CSRF protection on actions that serve JavaScript meant for a `<script>` tag.
To protect against all other forged requests, we introduce a _required security token_ that our site knows but other sites don't know. We include the security token in requests and verify it on the server. This is a one-liner in your application controller, and is the default for newly created rails applications: