Share to: share facebook share twitter share wa share telegram print page
Available for Advertising

Cross-origin resource sharing

Cross-origin resource sharing (CORS) is a mechanism to safely bypass the Same-origin policy, that is, it allows a web page to access restricted resources from a server on a domain different than the domain that served the web page.

A web page may freely embed cross-origin images, stylesheets, scripts, iframes, and videos. Certain "cross-domain" requests, notably Ajax requests, are forbidden by default by the same-origin security policy. CORS defines a way in which a browser and server can interact to determine whether it is safe to allow the cross-origin request.[1] It allows for more freedom and functionality than purely same-origin requests, but is more secure than simply allowing all cross-origin requests.

The specification for CORS is included as part of the WHATWG's Fetch Living Standard.[2] This specification describes how CORS is currently implemented in browsers.[3] An earlier specification was published as a W3C Recommendation.[4]

Technical overview

Path of an XMLHttpRequest (XHR) through CORS.

For HTTP requests made from JavaScript that can't be made by using a <form> tag pointing to another domain or containing non-safelisted headers, the specification mandates that browsers "preflight" the request, soliciting supported methods from the server with an HTTP OPTIONS request method, and then, upon "approval" from the server, sending the actual request with the actual HTTP request method. Servers can also notify clients whether "credentials" (including Cookies and HTTP Authentication data) should be sent with requests.[5]

Simple request example

Suppose a user visits http://www.example.com and the page attempts a cross-origin request to fetch data from http://service.example.com. A CORS-compatible browser will attempt to make a cross-origin request to service.example.com as follows.

  1. The browser sends the GET request with an extra Origin HTTP header to service.example.com containing the domain that served the parent page:
    Origin: http://www.example.com
  2. The server at service.example.com sends one of these three responses:
    • The requested data along with an Access-Control-Allow-Origin (ACAO) header in its response indicating the requests from the origin are allowed. For example in this case it should be:
      Access-Control-Allow-Origin: http://www.example.com
    • The requested data along with an Access-Control-Allow-Origin (ACAO) header with a wildcard indicating that the requests from all domains are allowed:
      Access-Control-Allow-Origin: *
    • An error page if the server does not allow a cross-origin request[6]

A wildcard same-origin policy is appropriate when a page or API response is intended to be accessible to any code on any site. A freely available web font on a public hosting service like Google Fonts is an example.

A wildcard same-origin policy is also widely and appropriately used in the object-capability model, where pages have unguessable URLs and are meant to be accessible to anyone who knows the secret.[original research?]

The value of "*" is special in that it does not allow requests to supply credentials, meaning that it does not allow HTTP authentication, client-side SSL certificates, or cookies to be sent in the cross-domain request.[7]

Note that in the CORS architecture, the Access-Control-Allow-Origin header is being set by the external web service (service.example.com), not the original web application server (www.example.com). Here, service.example.com uses CORS to permit the browser to authorize www.example.com to make requests to service.example.com.

If a site specifies the header "Access-Control-Allow-Credentials:true", third-party sites may be able to carry out privileged actions and retrieve sensitive information.

Preflight example

When performing certain types of cross-domain Ajax requests, modern browsers that support CORS will initiate an extra "preflight" request to determine whether they have permission to perform the action. Cross-origin requests are preflighted this way because they may have implications to user data.

OPTIONS /
Host: service.example.com
Origin: http://www.example.com
Access-Control-Request-Method: PUT

If service.example.com is willing to accept the action, it may respond with the following headers:

Access-Control-Allow-Origin: http://www.example.com
Access-Control-Allow-Methods: PUT

The browser will then make the actual request. If service.example.com does not accept cross-site requests from this origin then it will respond with error to the OPTIONS request and the browser will not make the actual request.

Headers

The HTTP headers that relate to CORS are:

Request headers

  • Origin
  • Access-Control-Request-Method
  • Access-Control-Request-Headers

Response headers

  • Access-Control-Allow-Origin
  • Access-Control-Allow-Credentials
  • Access-Control-Expose-Headers
  • Access-Control-Max-Age
  • Access-Control-Allow-Methods
  • Access-Control-Allow-Headers

Browser support

CORS is supported by all browsers based on the following layout engines:

History

Cross-origin support was originally proposed by Matt Oshry, Brad Porter, and Michael Bodell of Tellme Networks in March 2004 for inclusion in VoiceXML 2.1[19] to allow safe cross-origin data requests by VoiceXML browsers. The mechanism was deemed general in nature and not specific to VoiceXML and was subsequently separated into an implementation NOTE.[20] The WebApps Working Group of the W3C with participation from the major browser vendors began to formalize the NOTE into a W3C Working Draft on track toward formal W3C Recommendation status.

In May 2006 the first W3C Working Draft was submitted.[21] In March 2009 the draft was renamed to "Cross-Origin Resource Sharing"[22] and in January 2014 it was accepted as a W3C Recommendation.[23]

CORS vs JSONP

CORS can be used as a modern alternative to the JSONP pattern. The benefits of CORS are:

  • While JSONP supports only the GET request method, CORS also supports other types of HTTP requests.
  • CORS enables a web programmer to use regular XMLHttpRequest, which supports better error handling than JSONP.
  • While JSONP can cause cross-site scripting (XSS) issues when the external site is compromised, CORS allows websites to manually parse responses to increase security.[1]

The main advantage of JSONP was its ability to work on legacy browsers which predate CORS support (Opera Mini and Internet Explorer 9 and earlier). CORS is now supported by most modern web browsers.[24]

See also

References

  1. ^ a b "Cross-domain Ajax with Cross-Origin Resource Sharing". NCZOnline. 25 May 2010. Retrieved 2012-07-05.
  2. ^ "Fetch Living Standard".
  3. ^ "WebAppSec Working Group Minutes".
  4. ^ "Cross-Origin Resource Sharing".
  5. ^ "Cross-Origin Resource Sharing (CORS) - HTTP | MDN". developer.mozilla.org. 10 May 2023. Retrieved 7 June 2023.
  6. ^ "CORS errors - HTTP | MDN". developer.mozilla.org. 2023-05-10. Retrieved 2023-07-04.
  7. ^ [1]. W3.org. Retrieved on 2021-31-07.
  8. ^ a b "Blink". QuirksBlog. April 2013. Retrieved 4 April 2013.
  9. ^ "Google going its own way, forking WebKit rendering engine". Ars Technica. April 2013. Retrieved 4 April 2013.
  10. ^ "HTTP access control (CORS) - MDN". Developer.mozilla.org. Archived from the original on 2010-05-27. Retrieved 2012-07-05.
  11. ^ "Gecko - MDN". Developer.mozilla.org. 2012-06-08. Archived from the original on 2012-08-03. Retrieved 2012-07-05.
  12. ^ Tony Ross; Program Manager; Internet Explorer (2012-02-09). "CORS for XHR in IE10". MSDN. Retrieved 2012-12-14.
  13. ^ "cross-site xmlhttprequest with CORS". MOZILLA. Retrieved 2012-09-05.
  14. ^ David Honneffer, Documentation Specialist (2012-06-14). "12.00 for UNIX Changelog". Opera. Archived from the original on 2012-06-18. Retrieved 2012-07-05.
  15. ^ David Honneffer, Documentation Specialist (2012-04-23). "Opera Software: Web specifications support in Opera Presto 2.10". Opera.com. Retrieved 2012-07-05.
  16. ^ on July 6, 2009 by Arun Ranganathan (2009-07-06). "cross-site xmlhttprequest with CORS ✩ Mozilla Hacks – the Web developer blog". Hacks.mozilla.org. Retrieved 2012-07-05.{{cite web}}: CS1 maint: numeric names: authors list (link)
  17. ^ "59940: Apple Safari WebKit Cross-Origin Resource Sharing Bypass". Osvdb.org. Archived from the original on 2012-07-19. Retrieved 2012-07-05.
  18. ^ "Microsoft Edge deverloper's guide". 21 December 2023.
  19. ^ "Voice Extensible Markup Language (VoiceXML) 2.1". W3.org. 2004-03-23. Retrieved 2012-07-05.
  20. ^ "Authorizing Read Access to XML Content Using the <?access-control?> Processing Instruction 1.0". W3.org. Retrieved 2012-07-05.
  21. ^ "Authorizing Read Access to XML Content Using the <?access-control?> Processing Instruction 1.0 W3C - Working Draft 17 May 2006". W3.org. Retrieved 17 August 2015.
  22. ^ "Cross-Origin Resource Sharing - W3C Working Draft 17 March 2009". W3.org. Retrieved 17 August 2015.
  23. ^ "Cross-Origin Resource Sharing - W3C Recommendation 16 January 2014". W3.org. Retrieved 17 August 2015.
  24. ^ "When can I use... Cross Origin Resource Sharing". caniuse.com. Retrieved 2012-07-12.

Read other articles:

郭林祥中国人民解放军第三任总后勤部政委任期1973年8月-1975年8月 个人资料性别男出生1914年9月[1] 中華民國江西永丰逝世2010年4月25日(2010歲—04—25)(95歲) 中国北京市国籍 中华人民共和国语言汉语政党 中国共产党军衔上将 勋章奖章 中华人民共和国二级八一勋章(1958年) 中华人民共和国二级独立自由勋章(1958年) 中华人民共和国一级解放勋章(1958...

Plaintiff in St. Louis freedom suits Polly BerryI, Polly Wash...having recovered my freedom... (1843)BornPolly BeattyOther namesBased upon her slaveholder's surnames: Polly Crockett, Polly Berry, and Polly WashOccupation(s)Domestic servant, laundress, seamstressKnown forFreedom suit Polly Wash v. Joseph M. MagehanChildrenNancy Berry, Lucy A. Berry Delaney Part of a series onSlavery Contemporary Child labour Child soldiers Conscription Debt Forced marriage Bride buying Child marriage...

هذه المقالة يتيمة إذ تصل إليها مقالات أخرى قليلة جدًا. فضلًا، ساعد بإضافة وصلة إليها في مقالات متعلقة بها. (أبريل 2019) يوهانس إنجل   معلومات شخصية الميلاد سنة 1463[1]  آيشاخ  الوفاة 29 سبتمبر 1512 (48–49 سنة)  فيينا  مواطنة ألمانيا  الحياة العملية المدرسة الأم جامع

Madame Figaro Logo de Madame Figaro Pays France Zone de diffusion France Langue français Périodicité hebdomadaire Genre presse féminine Prix au numéro Avec la formule week-end du Figaro (5,60 €) Diffusion 382 996 ex. (2018 Diffusion France payée Acpm[réf. incomplète]) Fondateur Robert Hersant Date de fondation mai 1980 Éditeur Le Figaro Ville d’édition Paris Propriétaire Groupe Figaro (Groupe Dassault) Directeur de publication Marc Feuillée Directeur de la réda...

?Hadromerida Tethya aurantia Біологічна класифікація Домен: Ядерні (Eukaryota) Царство: Тварини (Animalia) Підцарство: Первинні багатоклітинні (Prometazoa) Тип: Губки (Porifera) Клас: Звичайні губки (Demospongiae) Ряд: HadromeridaTopsent, 1894 Родини Див.текст Посилання Вікісховище: Hadromerida ITIS: 48443 NCBI: 45119 Fossilworks: 3326 84250, 3326 Hadrom...

التحالف من أجل الديمقراطية والاتحاد الأيديولوجيا لبرالية  تعديل مصدري - تعديل   يفتقر محتوى هذه المقالة إلى الاستشهاد بمصادر. فضلاً، ساهم في تطوير هذه المقالة من خلال إضافة مصادر موثوق بها. أي معلومات غير موثقة يمكن التشكيك بها وإزالتها. (أغسطس 2021) هذه المقالة يتيمة إذ ت

Earl of Tankerville ist ein erblicher britischer Adelstitel, der einmal als französischer Adelstitel, einmal in der Peerage of England und einmal in der Peerage of Great Britain verliehen wurde. Der Titel ist nach dem Ort Tancarville in der Normandie benannt. Inhaltsverzeichnis 1 Verleihungen 1.1 Erste Verleihung von 1418 1.2 Zweite Verleihung 1695 1.3 Dritte Verleihung 1714 2 Liste der Earls of Tankerville 2.1 Grafen von Tancarville, erste Verleihung (1419) 2.2 Earls of Tankerville, zweite ...

United States historic placeEngine Company No. 3U.S. National Register of Historic PlacesNew Jersey Register of Historic Places Location201 Jefferson Street, Hoboken, New JerseyCoordinates40°44′27″N 74°2′17″W / 40.74083°N 74.03806°W / 40.74083; -74.03806Area0.9 acres (0.36 ha)Built1915ArchitectFagan & BriscoeArchitectural styleItalian VillaMPSHoboken Firehouses and Firemen's Monument TRNRHP reference No.84002687[1]NJRHP ...

此條目需要擴充。 (2011年11月21日)请協助改善这篇條目,更進一步的信息可能會在討論頁或扩充请求中找到。请在擴充條目後將此模板移除。 ASCII MEDIA WORKS原文名稱アスキー・メディアワークス產品類型出版品牌持有者KADOKAWA國家/地區 日本建立2013年10月1日-2015年3月31日前任持有者株式會社ASCII MEDIA WORKS網站http://asciimw.jp/ 株式会社ASCII MEDIA WORKSASCII Media Works Inc.原文名称株

Izzy Brown Brown bersama timnas Inggris U-19 pada 2015Informasi pribadiNama lengkap Isaiah Jay Brown[1]Tanggal lahir 7 Januari 1997 (umur 26)Tempat lahir Peterborough, InggrisTinggi 1,82 m (5 ft 11+1⁄2 in)[2]Posisi bermain PenyerangKarier junior2011 Leicester City2011–2013 West Bromwich Albion2013–2014 ChelseaKarier senior*Tahun Tim Tampil (Gol)2013 West Bromwich Albion 1 (0)2013–2021 Chelsea 1 (0)2015–2016 → Vitesse (pinjaman) 22 (1)2016–...

巴伐利亚基督教社会联盟Christlich-Soziale Union in Bayern巴伐利亚基督教社会联盟标志领袖马库斯·索德尔副主席梅拉妮·胡姆尔成立1945年总部Franz-Josef-Strauß-HausNymphenburger Str. 6480335 Munich意識形態巴伐利亚地区主义基督教民主主义保守主義[1]政治立場中間偏右至右翼国内组织基民盟/基社盟欧洲组织歐洲人民黨国际组织國際民主聯盟歐洲議會黨團欧洲人民党党团官方色彩藍色(

توكسي   الإحداثيات 31°54′39″N 88°18′33″W / 31.9107117°N 88.3091459°W / 31.9107117; -88.3091459  تقسيم إداري  البلد الولايات المتحدة[1]  التقسيم الأعلى مقاطعة شوكتو  خصائص جغرافية  المساحة 1.772177 كيلومتر مربع (1 أبريل 2010)  ارتفاع 32 متر  عدد السكان  عدد السكان 137 (1 أبر...

2018 film by Wajed Ali Sumon Captain KhanThe theatrical posterDirected byWajed Ali SumonWritten byN. LinguswamyBased onAnjaan (2014)by N. LinguswamyProduced bySelim KhanStarring Shakib Khan Shabnom Bubly Samraat Misha Sawdagor Ashish Vidyarthi CinematographySaiful SaheenEdited byTouhid Hossain ChowdhuryMusic byShahriar RafatProductioncompanyShapla MediaDistributed byLive Technologies LimitedRelease date 22 August 2018 (2018-08-22) Running time155 minutesCountryBangladeshLanguag...

The Muthoot family is one of the foremost business houses in South India. The family has interests in various sectors of business varying from financial services to media. The founder of the Muthoot Group was M.N. Mathai (who goes by N. Mathai Muthoot), from whom the business house was later taken over by his son, M. George Muthoot,. The family traces its roots to Thevervelil Family in the small town of Kozhencherry in Central Travancore.[1] The Muthoot family are Christians belonging...

Christian theology Part of a series onChristianity JesusChrist Nativity Baptism Ministry Crucifixion Resurrection Ascension BibleFoundations Old Testament New Testament Gospel Canon Church Creed New Covenant Theology God Trinity Father Son Holy Spirit Apologetics Baptism Christology History of theology Mission Salvation Universalism HistoryTradition Apostles Peter Paul Mary Early Christianity Church Fathers Constantine Councils Augustine Ignatius East–West Schism Crusades Aquinas Reformatio...

The Elvis DeadRob Kemp, The Elvis Dead, Glastonbury Festival, 2019MusicElvis PresleyLyricsRob KempBasisEvil Dead II, directed by Sam RaimiPremiere12 February 2017: The Soundhouse, Leicester Comedy FestivalAwards 2017 Leicester Comedy Festival Award for Best Show and Best Musical/Improv Show 2017 Amused Moose Award for Outstanding Fringe Show 2017 Malcolm Hardee Award for Act Most Likely to Make a Million Quid 2017 Midlands Comedy Award for Breakthrough Act, Best Alternative Act and Best Live ...

Agenoria is a Roman goddess of activity (actus). Her name is presumably derived from the Latin verb agō, to do, drive, go; present participle agēns. She is named only by Augustine of Hippo, who places her among the deities who are concerned with childhood.[1] She is thus one of the goddesses who endows the child with a developmental capacity, such as walking, singing, reasoning, and learning to count.[2] W.H. Roscher includes Agenoria among the indigitamenta, the list of dei...

Disambiguazione – Carabinieri rimanda qui. Se stai cercando altri significati, vedi Carabinieri (disambigua). Arma dei CarabinieriStemma dell'Arma dei Carabinieri(adottato dal 2002) Descrizione generaleAttiva13 luglio 1814 – oggi(fino al 1861 Corpo dei Carabinieri Reali) Nazione ItaliaPrecedentemente: Regno di Sardegna Regno d'Italia ServizioEsercito italiano (fino al 1999)Forza armata (dal 2000) TipoForza armata e corpo militare di polizia a competenza generale. Compiti...

1968 United States Grand Prix Race detailsDate October 6, 1968Official name XI United States Grand PrixLocation Watkins Glen Grand Prix Race CourseWatkins Glen, New YorkCourse Permanent road courseCourse length 3.78 km (2.35 miles)Distance 108 laps, 408.2 km (253.8 miles)Weather Temperatures reaching a maximum of 20 °C (68 °F);wind speeds up to 14.82 km/h (9.21 mph)[1]Pole positionDriver Mario Andretti Lotus-FordTime 1:04.20Fastest lapDriver Jackie Stewart Matra-...

For defunct Canadian football team, see Victoria Travellers Football Club § Victoria Capitals. This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Victoria Capitals – news · newspapers · books · scholar · JSTOR (December 2009) (Learn how and when to remove this template message) Victoria Capitals Team logo...

Kembali kehalaman sebelumnya