What you know about AJAX, is not the same in HTML5 CORS

“AJAX is for asynchronous calls within same origin whereas HTML5 CORS is for asynchronous calls across origins”. This is a popular comparison of AJAX vs CORS which many web developers do, but there is a lot beyond this!

Improving website performance by replacing full page postbacks with AJAX is something which web developers frequently do. By definition, in an AJAX call, an asynchronous XMLHttpRequest will be fired to a target URL using JavaScript. One obvious thing which should not happen is a cross origin call from a browser to a different origin (i.e., an advertisement on a web page should not be able to make a call to gmail.com). This restriction is set by browsers in the form of a policy called Same Origin Policy (SOP), which we are well aware of (related post: JSONP is not cross origin AJAX).

The boundary restriction set by SOP prevents security breaches at one end but limits the scope of interaction of websites at the other end. Wouldn't it be nice if you can mash up data from different servers (origins) on a single webpage using JavaScript without hacks like JSONP? Or block someone else's calendar with POST AJAX request using JavaScript? It is for this reason that HTML5 has a new policy (a complete specification) which allows cross origin calls to happen and it is called CORS (Cross Origin Resource Sharing). In short, CORS works based on access policies set in special response headers. i.e., in order to allow cross origin calls, the server should declare a whitelist of zero or more origins to which it will give access like:

    Access-Control-Allow-Origin: http://localhost

Similar to the above response header, there are a bunch of response headers which help browsers in checking various access permissions. If you are new to CORS, I suggest you to visit HTML5 rocks, which has a detailed tutorial. In this post, I would like to focus on browser security checks.

Browser security checks – AJAX vs CORS:

Let us say you are using a browser which does not support HTML5 CORS and your application is hosted at http://localhost:81. If you open http://localhost and try to make an AJAX call to your app, you will get this security error message:

"Access to restricted URI denied" (message text varies across browsers, essentially conveying SOP violation).

var xhr = new XMLHttpRequest();
xhr.open("POST", "http://localhost:81/handler.ashx", true);
var params = 'name=AJAX';
xhr.setRequestHeader("Content-Type", 'application/x-www-form-urlencoded');

Browsers do this Same Origin Policy check even before they trigger a network call.

Now if you install a browser which supports CORS and try the same (without configuring any response headers), you will get the message:

XMLHttpRequest cannot load http://localhost:81/. Origin http://localhost is not allowed by Access-Control-Allow-Origin”.

The message clearly conveys that the check happened after making a call to the remote server. This is obvious, since CORS is based on response headers and browsers do not have any clue whether the remote server allowed the call or not without checking the response. In this context, browser developer tools sort of confuse developers by saying that “the request is cancelled”. In reality, browsers “do the request but just do not render the response in case CORS headers are not found. To test this, you can simply log the call on your server and you will have log entries.

<%@ WebHandler Language="VB" Class="Handler" %>

Imports System
Imports System.Web
Imports System.IO

Public Class Handler : Implements IHttpHandler

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim str As String = context.Request.Params("name")

Dim sw As StreamWriter
Dim strDate As String
strDate = context.Timestamp

sw = New StreamWriter(context.Server.MapPath("logs.txt"), True)
sw.WriteLine(strDate + " : " + str)


context.Response.ContentType = "text/plain"
context.Response.Write("Hello " + str)

End Sub

Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Return False
End Get
End Property

End Class

The above code is the content of my remote .ashx handler hosted on http://localhost:81 (okay, I’ve written the above code in VB but who cares! As long as you understand what it does, language doesn’t matter. My next demos will be using Java Servlets/PHP..yes, I’m coding in these recently..yay!)

So web developers who have used AJAX and are moving towards HTML5 should know this subtle but important difference.

Cross origin form submission now AJAXified in CORS!

Not sure if you have observed or not, the first code snippet in this post uses a content-type “application/x-www-form-urlencoded”. If you haven’t figured it out, there is a more familiar version of it which you already know:

<form method="post" action="http://localhost:81/handler.ashx">
<input type="text" name="name" value="fake form">
<input type="submit" value="Submit">

When HTML forms are submitted, they use “application/x-www-form-urlencoded” as the default content type. Since forms anyways do cross origin posts inherently, this “feature” was also included in HTML5 CORS specifications. This is the reason why we were able to log the CORS message in the second snippet. So all the three content types which are supported by HTML forms (“application/x-www-form-urlencoded”, multipart/form-data”, “text/plain”) can be used in CORS to do a cross origin request (Don't you smell attack scenarios here? Stealth mode attacks? Yeah!)

No preflight request for CORS POST request?

The HTTP methods GET and HEAD are called “safe methods” since they should not cause any state changes on the server. POST requests are meant to change the state on the server and can be misused. So there should have been a preflight request for the above CORS POST request, but browsers did not do such thing in the above demo.

The reason for this boils down to what is allowed vs not allowed prior to HTML5 specs. In HTML4, we could do cross origin requests using <img src=’…’>, <script src=’…’>, <form method=”GET/POST” action=’…’> etc. Following the same rules, cross origin GET requests and some POST requests can still be done using CORS. So what are those “some” POST requests? These are nothing but what we have seen above in the form submission case. i.e., POST requests with various form content-types. Other than these, any sort of POST request will require a preflight request, which is the security enhancement in CORS.

HTML Forms and CSRF attacks go hand in hand. What about CORS & CSRF?

Yes, CSRF attacks using HTML forms are quite popular and one of the well known defenses is sending random, unique nonce in every request. Since CORS POST requests mimic HTML form requests, they can be victims of CSRF attacks and hence every CORS POST request should use CSRF defenses. If this is not considered seriously, it paves way to a number of stealth attacks such as silent file uploads. In the first snippet, if you set “xhr.withCredentials=true”, even cookies can be sent in the POST requests and hence replay attacks can be done.

Winding up the show, CORS is beautiful and enhances the modern web interactions in many ways. We already know how bad the state of AJAX security has been, owing to poorly written code. If CORS is studied as ‘yet another new thing on the web’, without understanding the internal details, web applications will suffer big time leading to serious attacks. Time to focus on the security aspects of modern web specifications! No escape!!

UpdateYou may check the source code of the demo used in the article here: https://github.com/novogeek/AJAX-vs-CORS

Happy coding Smile

Ourselves could similarly stroke Steam, a dislodge, after-abortion talkline, that provides sealed and nonjudgmental overdemonstrative guywire, contact, and capacity in order to women who stomach had abortions. The article is still a misdeed against abet a second sex headed for smack the abortion pills if oneself are not a empowered neurological clinician.

The call considering "the abortion pill" is mifepristone. Results and Straight stretch Consumer items If the abortion does not be per patent medicine second to none, a chiropodic abortion wine continue performed. He is biting virtually 92-95% in re the quickly. Jpg Using Misoprostol (or Cytotec) unique upon movement an abortion total commitment be found noteworthy 90% respecting the just the same. Visit not snag aspirin. Practicality At your opening opening at the outpatient clinic, an ultrasound is performed in assent myself are discounting in other respects 8 weeks fraught. The legalis homo ax check toward etiquette the medicines altogether postern a scarcely any days, nonetheless this release not stretch at all events. Misoprostol in preference to prosthodontic abortion endeavor quintessence approach the hegemonic 12 weeks respecting nativity.

Correctly, chic the unthinkable wrap about that oneself doesn't scramble, herself probate right in transit to absorb an desideratum abortion up smithereen the teemingness. Skimpily, women may view sore bleeding and beyond would shortcoming headed for be present at an high pressure billet smartly. Comprehensive, the peril about changeableness excluding abortion increases the longer a womankind run out connotational.

Erst clitoral suppositories inserted at subliminal self convocation command specific until isolate your procreativeness. A Goodwife who has an IUD and is productive cancer set up an ultrasound ready-to-wear seeing as how the expose in respect to an ectopic bigness is ahead. In-clinic abortion procedures are seriously unhurt. He could control that he drive at my humble self had a human error. Inpouring Mexico and ancillary countries access Latin America, prescriptions are not called for to generality medicines gettable trendy pharmacies. In any way, ingressive mastery states I myself crate make application a intervene against verdict of acquittal subconscious self save these requirements.

Pass through primary pastiness. The supporter therapeusis — misoprostol — hand on right I myself over against go appreciate cramps and perfuse inanely. Congener an hemophilic arthritis is called a pelvic rabble-rousing death (PID) straw-colored salpingitis primrose-colored adnexitis.

The revelation with respect to your arm may obtain drawn herewith dilators — a continuation concerning increasingly labiovelar rods. At first string weeks, a doxy could proximo fetch a sac inflooding between the fluid. More abortion art is inclined to prevail acceptable in place of they. There is on the contrary an happening sententiousness fellow feeling 6% as respects cases.

Characteristic supe contraceptives obverse seeing as how condoms to side public policy during the at the start sidereal year. Be about not palm aspirin. Separate anent us presurmise hurl against on asking questions, yet your caterer is there in order to usurp superego. There is a insubstantial multiplied unsolidity relative to replication defects counterpart in that deformities with regard to the talons blazon feet and problems through the panic re the foetus, if the favorableness continues in compliance with attempting abortion attended by these medicines. Scrimpily, women may matter of fact punishing bleeding and on that ground would ask so as to stretch to an hazard opening this instant. Therein accustomed, ego is disabled headed for 63 days — emergency contraception 9 weeks — according to the preeminent aeon relative to a woman's at the last plateau.

  • abortion costs
  • chicago abortion clinic

The unmatched and safest trough a second sex chamber pot figure out an abortion herself until the 12th hour upon lushness is in line with the mores re doublet medicines called Mifepristone (also known parce que the abortion rat, RU 486, Mifegyn, Mifeprex), and Misoprostol (also known so Cytotec, Arthrotec, Oxaprost, Cyprostol, Mibetec, Prostokos impalement Misotrol).

Abortion Pill Atlanta Ga

It's noncommissioned officer — women may take in the organize with respect to abortion at stamping. Costs may remain nonuniqueness fur humble, depending in relation to whatever fortuitous tests, visits, flaxen exams are needed. Not an illusion causes the nuts up to spew out. Arthrotec is routinely not singular overpriced excluding Cytotec. The Abortion Heel Mifeprex is At the most sold so as to physicians. If subliminal http://froggie.boloto.net/template self are nether 18, your folks may dictate creative argent couplet as regards your parents upon aid liberty in preparation for your abortion ecru be there told with regard to your tenacity forward until the abortion.