Review main Abandoned

77376[BUGFIX] Add `X-Requested-With` by default in AJAX requests

Andreas Kienast CR 0 V 0 Easy +19 −14 updated 01/15/23, 12:06

Commit message

In major JavaScript frameworks, it's a de-facto standard to send the
header `X-Requested-With` valued to `XMLHttpRequest`. The TYPO3 AJAX
implementation now sends this header by default for all requests.

This patch fixes another bug that had no negative effects yet that
concerns merging objects. Now, there's a child object in
`defaultOptions` that revealed the bug. Previously, the objects were
merged by using the spread operator, creating shallow merges only.
TYPO3 luckily already provides API to allow deep merges of objects,
that is now used to merge configurations.

Review

  • Code review CR 0
  • Verified V 0

Issues 1

Files 8

Review log 912

  1. Andreas Kienast uploaded patch set 1 01/13/23, 12:45

  2. Andreas Kienast commented on patch set 1 CR -1 01/13/23, 12:48

    need to check something
  3. core-ci voted on patch set 1 V -1 01/13/23, 13:02 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/35760

  4. Andreas Kienast uploaded patch set 2 CR -1 V -1 01/13/23, 13:07

  5. core-ci voted on patch set 2 V -1 01/13/23, 13:22 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/35765

  6. Andreas Kienast uploaded patch set 3 V -1 01/13/23, 13:29

  7. core-ci voted on patch set 3 V +1 01/13/23, 13:37 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/35766

  8. Stefan Bürk commented on patch set 3 01/13/23, 13:46

    Just had a quick read on the commit message and brief scroll through. `X-Requested-With` may be a problem for cross domain requests, if not explicitly allowed for/by "CORS". Do you think we are issue free here ? https://markitzeroday.com/x-requested-with/cors/2017/06/29/csrf-mitigation-for-ajax-requests.html
  9. Christian Kuhn commented on patch set 3 01/13/23, 14:56

  10. Oliver Hader commented on patch set 3 01/13/23, 14:57

    Reply Unresolved

    In general, adding the header would not be a security problem for the TYPO3 site, since we have other mechanisms to mitigate CSRF (same-site cookie, request-token, referrer-check). For most of the JavaScript resources in this patch, this won't be a problem in terms of CORS preflight, since most request targets are on the same TYPO3 site (same-origin). However, the change for `AjaxRequest` is indeed a breaking change when used on cross-origin resources (e.g. calling some Google API from the TYPO3 backend) - this would now trigger a preflight request. Example 1) ``` fetch('https://dotmaui.com/my-ip/raw/';); // no additional header ``` → no preflight request, all good Example 2) ``` fetch('https://dotmaui.com/my-ip/raw/';, {headers: {'X-Requested-With': 'XMLHttpRequest'}}); // sending additional header ``` → triggers preflight request → no `Access-Control-Allow-Headers` header in response from dotmaui.com → fetch/XHR fails, since `X-Requested-With` header is not allowed for that resource --- → suggestion: only send `X-Requested-With` header in `AjaxRequest` for same-origin resources, or make that somehow™ configurable/optional
  11. Oliver Hader commented on patch set 3 CR -1 01/13/23, 15:22

    -1 for the breaking behavior in AjaxRequest
  12. Andreas Kienast abandoned the change 01/15/23, 12:06