user2939415
user2939415

Reputation: 894

How is JSONP any safer than JSON in cross-domain requests?

Why do browsers allow cross-origin JSONP requests and do not allow JSON requests? I know that JSON requests are not allowed to prevent XSS, but I don't see how JSONP is safer than JSON.

In fact, could JSONP be even more dangerous because it is technically a script, where JSON is just a text string?

Upvotes: 2

Views: 232

Answers (2)

user2939415
user2939415

Reputation: 894

Because cross-domain JSON is blocked, sensitive data can be transmitted using JSON, rather than JSONP. This prevents XSS. Additionally, a server should not send sensitive data using JSONP. Thus, sending data using JSON protects it from unauthorized observation. JSON is safer in this sense.

Upvotes: 0

Matt Ball
Matt Ball

Reputation: 359826

JSONP is not safer. It's a workaround/loophole/hack to get past the same origin policy.

CORS is the safer alternative to JSONP.

Upvotes: 3

Related Questions