1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
Commit graph

12 commits

Author SHA1 Message Date
Jack McCracken
a20fbf9bc5
Check that request is same-origin prior to including CSRF token in XHRs
[CVE-2020-8167]
2020-05-15 16:15:00 -07:00
aminamos
7bb0706f2c update from PR #36222 2020-02-12 13:31:43 -05:00
razh
2674fe38eb Revert "Pass HTML responses as plain-text in rails-ujs"
This reverts commit 48e44edfd0.

See discussion in #32287

For HTML content in `ajax:success` handlers, `event.detail[0]` should
be an `HTMLDocument` instance.
2019-03-17 14:50:39 -04:00
yuuji.yaginuma
1694b02909 Make JS views rendered work with content security policy
As of now,  `HTMLElement.nonce` seems to work only in Chrome.
So, it should not be used now.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/nonce#Browser_compatibility

Fixes #32577.
2018-04-20 15:41:56 +09:00
Raymond Zhou
48e44edfd0 Pass HTML responses as plain-text in rails-ujs
Running HTML responses through `DOMParser#parseFromString` results in
complete `HTMLDocument` instances with unnecessary surrounding tags.

For example:

    new DOMParser().parseFromString('<p>hello</p>', 'text/html')

Will output:

    <html>
      <head></head>
      <body>
        <p>hello</p>
      </body>
    </html>

This is passed to the `ajax:success` handler as `event.detail[0]`
(`data`), but cannot be used directly without first traversing the
document.

To resolve this, only XML content is passed through `parseFromString`,
while HTML content is treated as plain-text.

This matches the behavior of jquery-ujs, which relied on jQuery's
response-type inference.
2018-03-19 03:24:56 -04:00
Andrew White
31abee0341 Add support for automatic nonce generation for Rails UJS
Because the UJS library creates a script tag to process responses it
normally requires the script-src attribute of the content security
policy to include 'unsafe-inline'.

To work around this we generate a per-request nonce value that is
embedded in a meta tag in a similar fashion to how CSRF protection
embeds its token in a meta tag. The UJS library can then read the
nonce value and set it on the dynamically generated script tag to
enable it to execute without needing 'unsafe-inline' enabled.

Nonce generation isn't 100% safe - if your script tag is including
user generated content in someway then it may be possible to exploit
an XSS vulnerability which can take advantage of the nonce. It is
however an improvement on a blanket permission for inline scripts.

It is also possible to use the nonce within your own script tags by
using `nonce: true` to set the nonce value on the tag, e.g

    <%= javascript_tag nonce: true do %>
      alert('Hello, World!');
    <% end %>

Fixes #31689.
2018-02-19 15:59:34 +00:00
ta1kt0me
8b22725c78 Enable to call Rails.ajax without beforeSend 2017-10-28 12:13:19 +09:00
Vasin Dmitriy
19afeaf580 Fix callback in rails ujs 2017-06-07 08:33:33 +03:00
Josh Goodall
4be50a4a45 Fix server-generated JS response processing on IE9 when using rails-ujs and remote: true 2017-05-17 08:40:54 +10:00
Dmytro Vasin
db65f73f2e Fix mistake in JS response parser:
-
  Restore ability to accept ecmascript
  JS response should not modify DOM.
2017-04-13 16:58:36 +03:00
Dmytro Vasin
dc8ddea563 Set current page as default for ajax requests 2017-04-11 06:56:52 +03:00
Javan Makhmali
11341fdb3a Reorganize rails-ujs files 2017-03-30 14:41:17 -04:00
Renamed from actionview/app/assets/javascripts/utils/ajax.coffee (Browse further)