concept CORS in category hapi

appears as: CORS
hapi.js in Action

This is an excerpt from Manning's book hapi.js in Action.

The piece of the security puzzle this chapter concentrates on is application security. That’s the part that’s your responsibility as an application developer. Things like authentication, security headers, protecting against CSRF (Cross-Site Request Forgery), and making use of CORS (Cross-Origin Resource Sharing). You’ll be pleased to hear that you’re not on your own with these matters. hapi has already done a huge amount to make these things as painless as possible.

A better solution finally appeared in the form of CORS. CORS allows a resource owner to explicitly define a policy that allows resources on their origin to be loaded from another origin with a fine degree of control over who can load what. See figure 9.8.

Figure 9.8. CORS allows cross-origin requests to take place that were previously disallowed by the same-origin policy.

All modern browsers handle this for you on the client side. But on the server, we need to manage which resources are allowed to be loaded with CORS. You do that by setting certain response headers, all named with the prefix Access-Control-*. The browser will inspect these headers and determine whether the script is allowed access to the resource.