{"id":309,"date":"2012-07-13T16:21:37","date_gmt":"2012-07-13T16:21:37","guid":{"rendered":"http:\/\/garysieling.com\/blog\/?p=309"},"modified":"2012-07-13T16:21:37","modified_gmt":"2012-07-13T16:21:37","slug":"dont-use-access-control-allow-origin","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/dont-use-access-control-allow-origin\/","title":{"rendered":"Don&#8217;t use Access-Control-Allow-Origin"},"content":{"rendered":"<p>Access-Control-Allow-Origin is an HTTP header that allows servers to specify which hosts may send cross domain AJAX requests. Let&#8217;s say you were building an ad network, fetching content via AJAX. You would add this header to HTTP responses, once for each allowed domain.\u00a0Clearly this is not scalable, but it&#8217;s a bad idea for other reasons as well.<\/p>\n<p>Access-Control-Allow-Origin is tempting as a developer, because it allows you to build a lean multi-server set-up, without proxying requests. The real problem is entirely outside your control &#8211; corporate firewall proxies. The Watchguard Firewall is very aggressive by default, blocking content on a variety of heuristics. It removes HTTP headers it considers dangerous, including Access-Control-Allow-Origin, so a site built with this will never work for anyone inside their firewall.<\/p>\n<p>The header directive is primarily for the client-side browser to enforce cross-site scripting policies. This protects end-users from malicious javascript. For example, Javascript might be inserted into a blog comment, and if incorrectly escaped, could run when a visitor loads the page, modifying content or redirecting the user to another domain. In spite of this, it is apparently too risky for some proxies, so be careful.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Access-Control-Allow-Origin is an HTTP header that allows servers to specify which hosts may send cross domain AJAX requests. Let&#8217;s say you were building an ad network, fetching content via AJAX. You would add this header to HTTP responses, once for each allowed domain.\u00a0Clearly this is not scalable, but it&#8217;s a bad idea for other reasons &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.garysieling.com\/blog\/dont-use-access-control-allow-origin\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Don&#8217;t use Access-Control-Allow-Origin&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[16],"tags":[43,124,278,302,499,548],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/309"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=309"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/309\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=309"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}