Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajax: Drop the json to jsonp auto-promotion logic #4754

Merged
merged 2 commits into from Jul 27, 2020

Conversation

mgol
Copy link
Member

@mgol mgol commented Jul 18, 2020

Summary

Previously, jQuery.ajax with dataType: 'json' with a provided callback was
automatically converted to a jsonp request unless one also specified
jsonp: false. Today the preferred way of interacting with a cross-domain
backend is CORS which works in all browsers jQuery 4 will support.

Auto-promoting JSON requests to JSONP ones introduces a security issue as the
developer may be unaware they're not just downloading data but executing code
from a remote domain.

This commit disables the auto-promoting logic.

BREAKING CHANGE: to trigger a JSONP request, it's now required to specify
dataType: "jsonp"; previously some requests with dataType: "json" were
auto-promoted to JSONP.

Fixes gh-1799
Fixes gh-3376

Checklist

@Krinkle
Copy link
Member

Krinkle commented Jul 18, 2020

Is this something the migrate plugin could feasilby detect, fix, and warn about without false positives?

@dmethvin
Copy link
Member

@Krinkle I think it should be possible to detect and warn about this.

Previously, `jQuery.ajax` with `dataType: 'json'` with a provided callback was
automatically converted to a jsonp request unless one also specified
`jsonp: false`. Today the preferred way of interacting with a cross-domain
backend is CORS which works in all browsers jQuery 4 will support.

Auto-promoting JSON requests to JSONP ones introduces a security issue as the
developer may be unaware they're not just downloading data but executing code
from a remote domain.

This commit disables the auto-promoting logic.

BREAKING CHANGE: to trigger a JSONP request, it's now required to specify
`dataType: "jsonp"`; previously some requests with `dataType: "json"` were
auto-promoted to JSONP.

Fixes jquerygh-1799
Fixes jquerygh-3376
@mgol
Copy link
Member Author

mgol commented Jul 22, 2020

I added tests for issue #1799 since the logic will now be skipped for regular JSON requests.

@mgol mgol added the Discuss in Meeting Reserved for Issues and PRs that anyone would like to discuss in the weekly meeting. label Jul 22, 2020
mgol added a commit to mgol/jquery-migrate that referenced this pull request Jul 22, 2020
@mgol
Copy link
Member Author

mgol commented Jul 22, 2020

I've also just submitted a Migrate PR: jquery/jquery-migrate#376.

test/data/json.json Outdated Show resolved Hide resolved
@timmywil timmywil removed the Discuss in Meeting Reserved for Issues and PRs that anyone would like to discuss in the weekly meeting. label Jul 27, 2020
@mgol mgol removed the Needs review label Jul 27, 2020
@mgol mgol merged commit e7b3bc4 into jquery:master Jul 27, 2020
@mgol mgol deleted the no-jsonp-auto-promotion branch July 27, 2020 17:16
mgol added a commit to mgol/jquery that referenced this pull request Jul 29, 2020
This aligns the Node.js server with the previous PHP one in accepting `mock.php`
as a callback which is triggered by a recently added test. This prevents the
request crashing on that Node.js server and printing a JS error:
```
TypeError: Cannot read property '1' of null
```

Ref jquerygh-4754
mgol added a commit to mgol/jquery-migrate that referenced this pull request Aug 25, 2020
mgol added a commit to jquery/jquery-migrate that referenced this pull request Aug 31, 2020
mgol added a commit to mgol/jquery that referenced this pull request Sep 2, 2020
This aligns the Node.js server with the previous PHP one in accepting `mock.php`
as a callback which is triggered by a recently added test. This prevents the
request crashing on that Node.js server and printing a JS error:
```
TypeError: Cannot read property '1' of null
```

Ref jquerygh-4754
mgol added a commit that referenced this pull request Sep 2, 2020
This aligns the Node.js server with the previous PHP one in sending `mock.php`
as a callback if there's no `callback` parameter in the query string which is
triggered by a recently added test. This prevents the request crashing on that
Node.js server and printing a JS error:
```
TypeError: Cannot read property '1' of null
```

Closes gh-4764
Ref gh-4754
mgol added a commit to mgol/jquery that referenced this pull request Sep 2, 2020
This aligns the Node.js server with the previous PHP one in sending `mock.php`
as a callback if there's no `callback` parameter in the query string which is
triggered by a recently added test. This prevents the request crashing on that
Node.js server and printing a JS error:
```
TypeError: Cannot read property '1' of null
```

Closes jquerygh-4764
Ref jquerygh-4754

(cherry picked from commit df6858d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
5 participants