O'Reilly logo

CORS in Action: Creating and consuming cross-origin APIs by Monsur Hossain

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 6. Best practices

This chapter covers

  • Opening up your API to public CORS requests
  • Limiting CORS requests to a whitelisted set of origins
  • Ensuring your CORS responses are properly handled by proxy servers
  • Protecting against cross-site request forgery (CSRF) vulnerabilities
  • Configuring and minimizing preflight requests

The previous chapters showed how Access-Control prefixed HTTP headers can dictate the behavior of CORS requests. There are six CORS-specific response headers, each with its own set of valid values. This can lead to myriad ways in which the server response can be configured. While the previous chapters explained what these HTTP headers do, they didn’t offer a lot of guidance on how to best use these headers. How should ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required