<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=JSONP</id>
	<title>JSONP - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=JSONP"/>
	<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=JSONP&amp;action=history"/>
	<updated>2026-05-06T00:31:19Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>http://debianws.lexgopc.com/wiki143/index.php?title=JSONP&amp;diff=6895225&amp;oldid=prev</id>
		<title>imported&gt;IngeniousPachyderm: Added image and caption</title>
		<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=JSONP&amp;diff=6895225&amp;oldid=prev"/>
		<updated>2025-04-16T01:30:00Z</updated>

		<summary type="html">&lt;p&gt;Added image and caption&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Short description|JavaScript technique for loading data}}&lt;br /&gt;
{{Use dmy dates|date=November 2023}}&lt;br /&gt;
[[File:JSONP_logo.png | thumb | right | alt=Graphical logo for JSONP | Graphical logo for JSONP]]&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;JSONP&amp;#039;&amp;#039;&amp;#039;, or &amp;#039;&amp;#039;&amp;#039;JSON-P&amp;#039;&amp;#039;&amp;#039; (JSON with Padding), is a historical [[JavaScript]] technique for requesting data by loading a {{code|&amp;lt;script&amp;gt;}} element,&amp;lt;ref name=&amp;quot;JSON-P&amp;quot;/&amp;gt; which is an element intended to load ordinary JavaScript. It was proposed by Bob Ippolito in 2005.&amp;lt;ref&amp;gt;{{Cite web |url=http://bob.ippoli.to/archives/2005/12/05/remote-json-jsonp/ |title=Remote JSON - JSONP |last=Ippolito |first=Bob |date=December 5, 2005 |website=Bob Ippolito on Haskell, Python, Erlang, JavaScript, etc. |language=en |archive-url=https://web.archive.org/web/20120608162347/http://bob.ippoli.to/archives/2005/12/05/remote-json-jsonp/|archive-date=2012-06-08|url-status=dead|access-date=2017-02-10}}&amp;lt;/ref&amp;gt; JSONP enables sharing of data bypassing same-origin policy, which disallows running JavaScript code to read media [[Document Object Model|DOM]] elements or [[XMLHttpRequest]] data fetched from outside the page&amp;#039;s originating site. The originating site is indicated by a combination of [[URI scheme]], [[hostname]], and [[port number]].&lt;br /&gt;
&lt;br /&gt;
JSONP is vulnerable to the data source replacing the innocuous function call with malicious code, which is why it has been superseded by CORS ([[cross-origin resource sharing]], available since 2009&amp;lt;ref name=&amp;quot;caniuse-cors&amp;quot;&amp;gt;{{cite web |title=Cross-Origin Resource Sharing |url=https://caniuse.com/#feat=cors |website=Can I use... |access-date=4 May 2020}}&amp;lt;/ref&amp;gt;) in modern applications.&lt;br /&gt;
&lt;br /&gt;
== Functionality ==&lt;br /&gt;
The HTML &amp;lt;code&amp;gt;&amp;amp;lt;script&amp;amp;gt;&amp;lt;/code&amp;gt; element is generally allowed to execute JavaScript code retrieved from foreign origins. Services replying with pure [[JSON]] data, however, were not able to share data from foreign origins before the adoption of CORS (Cross-origin resource sharing).  &lt;br /&gt;
&lt;br /&gt;
For example, a request to a foreign service &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;http://server.example.com/Users/1234&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; may return a record for a person named Clem in the JSON format. JSON syntax is consistent with JavaScript&amp;#039;s object syntax. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;json&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;Name&amp;quot;: &amp;quot;Clem&amp;quot;,&lt;br /&gt;
    &amp;quot;Id&amp;quot;: 1234,&lt;br /&gt;
    &amp;quot;Rank&amp;quot;: 7&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Without support for CORS, an attempt to use the data across domains results in a JavaScript error.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;html&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;application/javascript&amp;quot;&lt;br /&gt;
        src=&amp;quot;http://server.example.com/Users/1234&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The browser will download the &amp;lt;code&amp;gt;&amp;amp;lt;script&amp;amp;gt;&amp;lt;/code&amp;gt; file, evaluate its contents, misinterpret the raw JSON data as a block, and throw a syntax error. Even if the data were interpreted as a JavaScript object literal, it could not be accessed by JavaScript running in the browser, since without a variable assignment, object literals are inaccessible.&lt;br /&gt;
&lt;br /&gt;
In the JSONP usage pattern, the URL request pointed to by the &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; attribute in the &amp;lt;code&amp;gt;&amp;amp;lt;script&amp;amp;gt;&amp;lt;/code&amp;gt; element returns JSON data, with JavaScript code (usually a function call) wrapped around it. This &amp;quot;wrapped payload&amp;quot; is then interpreted by the browser. In this way, a function that is already defined in the JavaScript environment can manipulate the JSON data. A typical JSONP request and response are shown below.&lt;br /&gt;
&lt;br /&gt;
The function call to parseResponse() is the &amp;quot;P&amp;quot; of JSONP—the &amp;quot;padding&amp;quot; or &amp;quot;prefix&amp;quot; around the pure JSON.&amp;lt;ref&amp;gt;{{cite web|url=https://epimorph-pubx1.appspot.com/help.html |title=Experimental RDF result set to JSON translator |access-date=February 20, 2012 |url-status=dead |archive-url=https://web.archive.org/web/20141115070803/http://epimorph-pubx1.appspot.com/help.html |archive-date=November 15, 2014 }}&amp;lt;/ref&amp;gt; For JSONP to work, a server must reply with a response that includes the JSONP function. JSONP does not work with JSON-formatted results. The JSONP function invocation that gets sent back, and the payload that the function receives, must be agreed upon by the client and server. By convention, the server providing the JSON data offers the requesting website to name the JSONP function, typically using the name jsonp or [[callback (computer programming)|callback]]  as the named query-string parameter, in its request to the server:  &amp;lt;code&amp;gt;&amp;lt;script src=&amp;quot;&amp;lt;nowiki&amp;gt;http://server.example.com/Users/1234?callback=parseResponse&amp;lt;/nowiki&amp;gt;&amp;quot;&amp;gt;&amp;lt;nowiki&amp;gt;&amp;lt;/script&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this example, the received payload would be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
parseResponse({&amp;quot;Name&amp;quot;: &amp;quot;Clem&amp;quot;, &amp;quot;Id&amp;quot;: 1234, &amp;quot;Rank&amp;quot;: 7});&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Script element injection ==&lt;br /&gt;
JSONP makes sense only when used with a script element.  For each new JSONP request, the browser must add a new &amp;lt;code&amp;gt;&amp;amp;lt;script&amp;amp;gt;&amp;lt;/code&amp;gt; element, or reuse an existing one.  The former option—adding a new script element—is done via dynamic DOM manipulation, and is known as &amp;#039;&amp;#039;script element injection&amp;#039;&amp;#039;.  The &amp;lt;code&amp;gt;&amp;amp;lt;script&amp;amp;gt;&amp;lt;/code&amp;gt; element is injected into the HTML DOM, with the URL of the desired JSONP endpoint set as the &amp;quot;src&amp;quot; attribute. This dynamic &amp;#039;&amp;#039;script element injection&amp;#039;&amp;#039; is usually done by a JavaScript helper library. [[jQuery]] and other frameworks have JSONP helper functions; there are also standalone options.&lt;br /&gt;
&lt;br /&gt;
An example of using jQuery to &amp;#039;&amp;#039;dynamically inject&amp;#039;&amp;#039; script element for a JSONP call looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
$.getScript(&amp;quot;http://server.example.com/Users/192.168.73.96?callback=parseResponse&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the element is injected, the browser evaluates the element, and performs an HTTP GET on the src URL, retrieving the content. Then the browser evaluates the return payload as JavaScript. This is typically a function invocation. In that way, the use of JSONP can allow browser pages to work around the [[same-origin policy]] via script element injection.&amp;lt;ref&amp;gt;{{Cite web|date=2013-02-05|title=So how does JSONP really work? Some simple examples.|url=http://schock.net/articles/2013/02/05/how-jsonp-really-works-examples/|access-date=2021-12-26|website=Jason Schock|language=en-US|archive-date=26 December 2021|archive-url=https://web.archive.org/web/20211226041501/http://schock.net/articles/2013/02/05/how-jsonp-really-works-examples/|url-status=dead}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The script runs within the scope of the including page and, as such, is still subject to cross-domain restrictions relative to the domain of the including page. This means that a web page cannot, for example, load a library hosted on another site via JSONP and then make XMLHttpRequest requests to that site (unless [[cross-origin resource sharing]] (CORS) is supported), although one could use such a library to make XMLHttpRequests to one&amp;#039;s own site.&lt;br /&gt;
&lt;br /&gt;
== Security concerns ==&lt;br /&gt;
&lt;br /&gt;
=== Untrusted third-party code ===&lt;br /&gt;
Including script elements from remote servers allows the remote servers to inject &amp;#039;&amp;#039;any&amp;#039;&amp;#039; content into a website. If the remote servers have vulnerabilities that allow JavaScript injection, the page served from the original server is exposed to an increased risk.  If an attacker can inject any JavaScript into the original web page, then that code can retrieve additional JavaScript from any domain, bypassing the [[same-origin policy]].&amp;lt;ref&amp;gt;{{cite web | url=https://www.blackhat.com/docs/eu-14/materials/eu-14-Hayak-Same-Origin-Method-Execution-Some-Exploiting-A-Callback-For-Same-Origin-Policy-Bypass.pdf | title=Same Origin Method Execution | date=2014-10-17 | access-date=2014-10-22 | author=Ben Hayak}}&amp;lt;/ref&amp;gt;  The Content Security Policy HTTP Header lets web sites tell web browsers which domain scripts may be included from.&lt;br /&gt;
&lt;br /&gt;
An effort was undertaken around 2011 to define a safer strict subset definition for JSONP&amp;lt;ref name=&amp;quot;JSON-P&amp;quot;&amp;gt;{{cite web |url=http://www.json-p.org/ |title=Safer cross-domain Ajax with JSON-P/JSONP |work=JSON-P.org |access-date=2011-10-30 |url-status=dead |archive-url=https://web.archive.org/web/20160304044218/http://www.json-p.org/ |archive-date=March 4, 2016}}&amp;lt;/ref&amp;gt; that browsers would be able to enforce on script requests with a specific [[MIME]] type such as &amp;quot;application/json-p&amp;quot;. If the response did not parse as strict JSONP, the browser could throw an error or just ignore the entire response. However, this approach was abandoned in favor of [[Cross-origin resource sharing|CORS]], and the correct MIME type for JSONP remains &amp;lt;code&amp;gt;application/javascript&amp;lt;/code&amp;gt;.&amp;lt;ref&amp;gt;{{cite web |url=https://stackoverflow.com/a/3128948/569447 |first=Eli |last=Grey |title=Is this safe for providing JSONP? |work=stackoverflow.com |date=2010-06-27 |access-date=2012-09-07 }}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Whitespace differences ===&lt;br /&gt;
&lt;br /&gt;
JSONP carried the same problems as resolving JSON with {{code|eval()}}: both interpret the JSON text as JavaScript, which meant differences in handling U+2028 ([[Newline#Unicode|Line Separator]]) and U+2029 ([[Newline#Unicode|Paragraph Separator]]) from JSON proper. This made some JSON strings non-legal in JSONP; servers serving JSONP had to escape these characters prior to transmission.&amp;lt;ref name=&amp;quot;Magnus Holm&amp;quot;&amp;gt;{{cite web|title=JSON: The JavaScript subset that isn&amp;#039;t|url=http://timelessrepo.com/json-isnt-a-javascript-subset|publisher=Magnus Holm|access-date=16 May 2011|archive-date=13 May 2012|archive-url=https://web.archive.org/web/20120513012409/http://timelessrepo.com/json-isnt-a-javascript-subset|url-status=dead}}&amp;lt;/ref&amp;gt; This issue has now been rectified in ES2019.&amp;lt;ref&amp;gt;{{cite web|title=Subsume JSON (a.k.a. JSON ⊂ ECMAScript)|website=[[GitHub]] |date=24 October 2022 |url=https://github.com/tc39/proposal-json-superset|access-date=24 Oct 2022}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Callback name manipulation and reflected file download attack ===&lt;br /&gt;
Unsanitized callback names may be used to pass malicious data to clients, bypassing the restrictions associated with &amp;lt;code&amp;gt;application/json&amp;lt;/code&amp;gt; content type, as demonstrated in reflected file download (RFD) attack from 2014.&amp;lt;ref&amp;gt;{{cite web | url=https://www.trustwave.com/Resources/SpiderLabs-Blog/Reflected-File-Download---A-New-Web-Attack-Vector/ | title=Reflected File Download - A New Web Attack Vector | publisher=TrustWave | date=2014 | access-date=2015-03-25 | author=Oren Hafif}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Insecure JSONP endpoints can be also injected with malicious data.&amp;lt;ref&amp;gt;{{cite web|url=https://securitycafe.ro/2017/01/18/practical-jsonp-injection/ |title=Practical JSONP injection|date=18 January 2017 }}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cross-site request forgery ===&lt;br /&gt;
Naive deployments of JSONP are subject to [[cross-site request forgery]] (CSRF or XSRF) attacks.&amp;lt;ref&amp;gt;{{cite web |url=http://jeremiahgrossman.blogspot.com/2006/01/advanced-web-attack-techniques-using.html |title=Advanced Web Attack Techniques using GMail |first=Jeremiah |last=Grossman |date=January 27, 2006 |access-date=July 3, 2009}}&amp;lt;/ref&amp;gt;  Because the HTML &amp;lt;code&amp;gt;&amp;amp;lt;script&amp;amp;gt;&amp;lt;/code&amp;gt; element does not respect the [[same-origin policy]] in web browser implementations, a malicious page can request and obtain JSON data belonging to another site.  This will allow the JSON-encoded data to be evaluated in the context of the malicious page, possibly divulging passwords or other sensitive data if the user is currently logged into the other site.&lt;br /&gt;
&lt;br /&gt;
=== Rosetta Flash ===&lt;br /&gt;
Rosetta Flash is an exploitation technique that allows an attacker to exploit servers with a vulnerable JSONP endpoint by causing [[Adobe Flash Player]] to believe that an attacker-specified Flash applet originated on the vulnerable server. Flash Player implements [[same-origin policy]] allowing one to make requests (with cookies) and receive responses from the hosting site. The applet can then send the retrieved data back to the attacker. This is a cross-origin exploit with an impact similar to embedding an arbitrary Flash applet in the vulnerable domain. The exploit uses an ActionScript payload compiled to an SWF file composed entirely of alphanumeric characters by crafting a [[zlib]] stream with a particular header and [[DEFLATE]] blocks with ad-hoc [[Huffman coding]]. The resulting alphanumeric-only SWF file is then used as the callback parameter of a JSONP call. High-profile sites such as Google, YouTube, Twitter, Yahoo!, Yandex, LinkedIn, eBay, GitHub, Instagram, and Tumblr were all vulnerable until July 2014.&amp;lt;ref&amp;gt;{{cite web|last1=Michele|first1=Spagnuolo|title=Abusing JSONP with Rosetta Flash|url=https://blog.miki.it/2014/7/8/abusing-jsonp-with-rosetta-flash/|access-date=July 20, 2014|archive-url=https://web.archive.org/web/20140721100312/http://miki.it/blog/2014/7/8/abusing-jsonp-with-rosetta-flash/|archive-date=July 21, 2014|url-status=dead}}&amp;lt;/ref&amp;gt; This vulnerability was initially discovered by Erling and Alok Menghrajani, with a public presentation at a security conference. The exploitation of the vulnerability was subsequently improved by Gábor Molnár. Google security engineer [[Michele Spagnuolo]] coined the term&amp;lt;ref&amp;gt;{{cite web |url=https://www.google.com/about/appsecurity/research/ |title=Google - list of software vulnerabilities discovered or fixed by Googlers|access-date=July 29, 2014}}&amp;lt;/ref&amp;gt; and has {{CVE|2014-4671}}&amp;lt;ref&amp;gt;{{cite web |url=https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-4671 |title=MITRE: CVE-2014-4671 |access-date=July 29, 2014}}&amp;lt;/ref&amp;gt; and {{CVE|2014-5333|link=no}}.&amp;lt;ref&amp;gt;{{cite web |url=https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-5333 |title=MITRE: CVE-2014-5333 |access-date=August 21, 2014}}&amp;lt;/ref&amp;gt; Adobe Flash Player release version 14.0.0.145, released on 8 July 2014, introduced stronger validation of Flash files,&amp;lt;ref&amp;gt;{{cite web |url=http://helpx.adobe.com/security/products/flash-player/apsb14-17.html |title=Adobe Security Bulletin APSB14-17 |access-date=July 29, 2014}}&amp;lt;/ref&amp;gt; and in version 14.0.0.176, released on 12 August 2014, finalized the fix,&amp;lt;ref&amp;gt;{{cite web |url=http://helpx.adobe.com/security/products/flash-player/apsb14-18.html |title=Adobe Security Bulletin APSB14-18 |access-date=August 21, 2014}}&amp;lt;/ref&amp;gt; preventing this exploit from working.&lt;br /&gt;
&lt;br /&gt;
Prior to Adobe&amp;#039;s fix, websites could protect themselves by prepending an empty JavaScript comment (/**/) or even just a newline as the first bytes of the JSONP response.&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
In July 2005, George Jempty suggested an optional variable assignment be prepended to JSON.&amp;lt;ref&amp;gt;{{cite web|url=http://htmatters.net/htm/1/2005/07/evaling-JSON.cfm |title=eval&amp;#039;ing JSON |date=July 19, 2005 |url-status=dead |archive-url=https://web.archive.org/web/20060212113746/http://htmatters.net/htm/1/2005/07/evaling-JSON.cfm |archive-date=February 12, 2006 }}&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;{{cite web |url=http://tech.groups.yahoo.com/group/json/message/82 |archive-url=https://archive.today/20120722213034/http://tech.groups.yahoo.com/group/json/message/82 |url-status=dead |archive-date=22 July 2012 |title=json: Message: Re: Comments |date=August 17, 2005}}&amp;lt;/ref&amp;gt;  The original proposal for JSONP, where the padding is a callback function, appears to have been made by Bob Ippolito in December 2005&amp;lt;ref&amp;gt;{{cite web |url=http://bob.pythonmac.org/archives/2005/12/05/remote-json-jsonp/ |work=from __future__ import * |title=Remote JSON - JSONP |publisher=Bob.pythonmac.org |date=December 5, 2005 |access-date=September 8, 2008 |archive-url=https://web.archive.org/web/20091204053053/http://bob.pythonmac.org/archives/2005/12/05/remote-json-jsonp/ |archive-date=December 4, 2009 |url-status=dead }}&amp;lt;/ref&amp;gt; and is now used by many [[Web 2.0]] applications such as [[Dojo Toolkit]] and [[Google Web Toolkit]].&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Cross-origin resource sharing]] (CORS)&lt;br /&gt;
* [[Web Messaging|Cross-document messaging]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
* [https://code.google.com/p/jsonp-java/ server side filter wraps any response into a jsonp callback]{{snd}}done with jsonp-java source code&lt;br /&gt;
* [http://quaxio.com/jsonp_handcrafted_flash_files/ Potential security issues related to JSON]&lt;br /&gt;
* [https://datatables.net/examples/server_side/jsonp.html JSONP data source for remote domains]&lt;br /&gt;
&lt;br /&gt;
[[Category:Ajax (programming)]]&lt;br /&gt;
[[Category:JSON]]&lt;/div&gt;</summary>
		<author><name>imported&gt;IngeniousPachyderm</name></author>
	</entry>
</feed>