Commit Graph

34 Commits

Author SHA1 Message Date
John Bampton
eef63e05fb chore: fix case of CSS and JavaScript 2021-04-15 21:52:58 +10:00
Rafael Mendonça França
077c66d5d6
Rename master to main in all code references 2021-01-19 20:46:33 +00:00
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
George Claghorn
8f37e2555a Avoid Element.closest() for IE 9 compatibility
Fixes #37234.
2019-09-29 09:07:11 -04:00
Willian Gustavo Veiga
c3e786fc48 Issue #36728 - Inputs inside disabled fieldset are not submited on remote: true forms 2019-07-25 16:07:11 -03:00
Sudara
ab4ed8c786 Ensure non-mouse/programmatic clicks work with data-remote 2019-06-13 19:59:17 +02:00
razh
2674fe38eb Revert "Pass HTML responses as plain-text in rails-ujs"
This reverts commit 48e44edfd0a8a7a29aa8fad39638ac0ee5243f42.

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
George Claghorn
ceeef26fd4
Read the CSP nonce on page load
Turbolinks replaces the CSP nonce <meta> tag on page change, but inline scripts inserted by UJS need the nonce from the initial page load. In general, it doesn't matter to UJS if the nonce changes after the page loads: only the initial value is relevant.
2019-03-08 15:25:24 -05:00
alkesh26
955eac5a52 [ci skip] actionview typo fixes. 2019-02-21 01:33:14 +05:30
WoH
257a1a6373
Do not disable previously disabled elements 2018-12-06 09:02:07 +01:00
WoH
a2612622e8
Prevent unintended mouse keys from firing click events
Firefox fires click events on left-, right-
and scroll-wheel (any non-primary mouse key) clicks while other browsers don't.
2018-12-05 15:08:14 +01:00
Patrik Bóna
8e07711d65 Do not enable disabled elements for XHR redirects
Fixes #29473.
2018-09-27 10:59:56 +02:00
Kazuhiro NISHIYAMA
9df747c9f0 Throw if ujs loaded twice
I saw two posts of problem about ajax requesting twice on qiita.
So I think detecting double loaded earlier make easy to find the problem.

https://qiita.com/hot_study_man/items/56dc87ad734cfda68bb6
https://qiita.com/hisas/items/8399aec3a5377bf75017
2018-07-31 22:16:02 +09: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
Guillermo Iguaran
91f4e335b5
Merge pull request #32404 from mathieumahe/master
Extract the confirm call in its own, overridable method in rails_ujs
2018-04-02 10:50:10 -05:00
Mathieu
e9aa7ecdee Extract the confirm call in its own, overridable method in rails_ujs 2018-04-01 19:15:36 +07: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
Javan Makhmali
48de6e9bda Revert unintentional change in 41e3bbd 2018-01-01 13:24:51 -05:00
Javan Makhmali
41e3bbdee1 Improve preventDefault fix for rails-ujs
Improves 049a3374aa85f33091f0e7cba8635edd4b4786bd:

* Attempt native `preventDefault()` before stepping in
* Fix that calling `preventDefault()` more than once would throw an error
* Fix that non-cancelable events could be canceled
2018-01-01 13:02:07 -05:00
Yuri S
049a3374aa
Fix IE 10 and IE 11's broken preventDefault
https://github.com/turbolinks/turbolinks/issues/233
https://stackoverflow.com/questions/23349191/event-preventdefault-is-not-working-in-ie-11-for-custom-events
2017-12-27 18:39:44 +05:00
ta1kt0me
8b22725c78 Enable to call Rails.ajax without beforeSend 2017-10-28 12:13:19 +09:00
Akira Matsuda
731ea4e3fb Merge pull request #30513 from y-yagi/fix_30444
Does not include disabled element in params
2017-10-25 21:10:37 +09:00
Guillermo Iguaran
13132d8c32 Merge pull request #29710 from padi/rails-ujs-docs
Adds descriptions to rails-ujs methods [ci skip]
2017-10-22 07:55:44 -05:00
yuuji.yaginuma
a5d80d4a1c Does not include disabled element in params
In the case of remote, it should be the same behavior as submitting
HTML form.

Fixes #30444
2017-09-03 17:02:38 +09:00
Marc Rendl Ignacio
ff4b18358d Adds descriptions to rails-ujs methods [ci skip] 2017-07-07 15:34:35 +08:00
Vasin Dmitriy
19afeaf580 Fix callback in rails ujs 2017-06-07 08:33:33 +03:00
Guillermo Iguaran
cbf378bc27 Merge pull request #29151 from onemanstartup/jquery_slim_fix
Check for jQuery ajax
2017-05-29 13:37:53 -05:00
Dmitriy Plekhanov
f1a740ef3c Check for jQuery ajax
jQuery slim version doesn't have ajax, so if a person include this version ajaxFilter raises error.
2017-05-19 22:42:02 +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