{"id":8269,"date":"2020-09-29T11:27:43","date_gmt":"2020-09-29T11:27:43","guid":{"rendered":"https:\/\/cloudkul.com\/blog\/?p=8269"},"modified":"2021-07-19T03:37:07","modified_gmt":"2021-07-19T03:37:07","slug":"magento-2-cors-secure-your-magento2-store-from-cors-attack","status":"publish","type":"post","link":"https:\/\/cloudkul.com\/blog\/magento-2-cors-secure-your-magento2-store-from-cors-attack\/","title":{"rendered":"Magento 2 CORS: Secure your Magento2 store from CORS attack"},"content":{"rendered":"\n<p>So far in this <a href=\"https:\/\/store.webkul.com\/magento2-security-extension.html\">Magento 2 security<\/a> series we have discussed <a href=\"https:\/\/cloudkul.com\/blog\/magento-2-sql-injection-how-to-secure-your-store-against-sql-injection\/\">injection<\/a>, <a href=\"https:\/\/cloudkul.com\/blog\/magento-2-csrf-secure-your-magento2-store-from-csrf\/\">csrf<\/a> attacks and global techniques to prevent them as well as we have checked how Webkul security <a href=\"https:\/\/store.webkul.com\/Ecommerce-Security-Audit-Basic-Plan.html\">module<\/a> can help us for an easy and quick fix. <\/p>\n\n\n\n<p>Let&#8217;s discuss another attack Cross Origin Resource Sharing  (cors) which is being exploited by the attacker in the wild to steal sensitive information. <\/p>\n\n\n\n<p>In a typical web application, it generally fetches resources such as image , JSON data from another origin but browsers <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/Security\/Same-origin_policy\">same origin policy<\/a> can restrict loading of resources from another domain.<\/p>\n\n\n\n<p>To fix this issue caused by same origin policy CORS can be an effective solution. By enabling CORS header the server will tell the browser to allow use of additional origin.<\/p>\n\n\n\n<p>But if CORS policy is poorly configured and implemented it can potentially invite cross-domain based attacks. <\/p>\n\n\n\n<p>Let&#8217;s check the general misconfiguration scenarios:<\/p>\n\n\n\n<p><strong>1.wildcard (*) in CORS Headers:<\/strong> Here  the header Access-Control-Allow-Origin is configured with a wildcard(*). It means any domain can access the resources.  As the site shares information from any site it can be exploited easily.<\/p>\n\n\n\n<p><strong>2. Whitelisted null origin value:<\/strong>The Origin header is set to null because the browser doesn\u2019t want to leak the origin value to the  server.<\/p>\n\n\n\n<p>Browsers might send the value null in the Origin header in situations such as:<\/p>\n\n\n\n<ul><li>Cross-site redirects.<\/li><li>Request using the file: protocol.<\/li><li>Requests from serialized data.<\/li><li>Sandboxed cross-origin requests.<\/li><\/ul>\n\n\n\n<p>In such cases, hiding the Origin header value by setting it to null is a safety precaution. But this can be exploited by using various tricks to satisfy the whitelist.  <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">How to secure your magento2 store against CORS based attacks<\/h4>\n\n\n\n<p><strong>Avoid wildcards and Whitelisting null<\/strong><\/p>\n\n\n\n<p>Avoid setting Access-Control-Allow-Origin header to wildcard (*) as it&#8217;s not a good practice to trust every application over the internet. <\/p>\n\n\n\n<p>Also avoid setting it to null as attackers can set origin value to null to exploit. we should also avoid dynamically reflecting the origin header without proper validation.<\/p>\n\n\n\n<p>The origin should be properly specified in the Access-Control-Allow-Origin header. Admins should maintain a list of allowed\/trusted domains.<\/p>\n\n\n\n<p>Although maintaining a list of allowed domains is itself complicated and can invite errors.  In such case <a href=\"https:\/\/webkul.com\/\">Webkul<\/a> can help in detection and in mitigation from vulnerabilities on Magento 2 store through its <a href=\"https:\/\/store.webkul.com\/Ecommerce-Security-Audit-Basic-Plan.html\">basic security module<\/a> which can also be customized.<\/p>\n\n\n\n<p>To safeguard your Magento 2 store from other attacks like malicious <a href=\"https:\/\/owasp.org\/www-community\/vulnerabilities\/Unrestricted_File_Upload\">file upload<\/a> or brute force visit our <a href=\"https:\/\/store.webkul.com\/\">store<\/a> and check out our <a href=\"https:\/\/store.webkul.com\/magento2-security-extension.html\">Security Extension Suite for Magento 2 <\/a>module for more details, which is effective in blocking malicious users and in notifying admins for suspected login attempts. <\/p>\n\n\n\n<p><strong>In case of any help or query, please <a href=\"https:\/\/cloudkul.com\/contact\/\">contact<\/a> us or raise a <a href=\"https:\/\/webkul.uvdesk.com\/en\/customer\/create-ticket\/\">ticket<\/a>.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>So far in this Magento 2 security series we have discussed injection, csrf attacks and <a class=\"text-primary\" title=\"read more\" href=\"https:\/\/cloudkul.com\/blog\/magento-2-cors-secure-your-magento2-store-from-cors-attack\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":28,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[87,20,340],"tags":[24,231],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Magento 2 CORS: Secure your Magento2 store from CORS attack - Cloudkul<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cloudkul.com\/blog\/magento-2-cors-secure-your-magento2-store-from-cors-attack\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Magento 2 CORS: Secure your Magento2 store from CORS attack - Cloudkul\" \/>\n<meta property=\"og:description\" content=\"So far in this Magento 2 security series we have discussed injection, csrf attacks and [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudkul.com\/blog\/magento-2-cors-secure-your-magento2-store-from-cors-attack\/\" \/>\n<meta property=\"og:site_name\" content=\"Cloudkul\" \/>\n<meta property=\"article:published_time\" content=\"2020-09-29T11:27:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-07-19T03:37:07+00:00\" \/>\n<meta name=\"author\" content=\"Amit Yadav\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cloudkul.com\/blog\/magento-2-cors-secure-your-magento2-store-from-cors-attack\/\",\"url\":\"https:\/\/cloudkul.com\/blog\/magento-2-cors-secure-your-magento2-store-from-cors-attack\/\",\"name\":\"Magento 2 CORS: Secure your Magento2 store from CORS attack - Cloudkul\",\"isPartOf\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/#website\"},\"datePublished\":\"2020-09-29T11:27:43+00:00\",\"dateModified\":\"2021-07-19T03:37:07+00:00\",\"author\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/e7fc1ebc6e48c46a938780b19ea8b378\"},\"breadcrumb\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/magento-2-cors-secure-your-magento2-store-from-cors-attack\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cloudkul.com\/blog\/magento-2-cors-secure-your-magento2-store-from-cors-attack\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cloudkul.com\/blog\/magento-2-cors-secure-your-magento2-store-from-cors-attack\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cloudkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Magento 2 CORS: Secure your Magento2 store from CORS attack\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#website\",\"url\":\"https:\/\/cloudkul.com\/blog\/\",\"name\":\"Cloudkul\",\"description\":\"Host your eCommerce Store on AWS with Optimized Performance\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/cloudkul.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/e7fc1ebc6e48c46a938780b19ea8b378\",\"name\":\"Amit Yadav\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/154c2c18758419af8c80f50ed0e8c615?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/154c2c18758419af8c80f50ed0e8c615?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g\",\"caption\":\"Amit Yadav\"},\"url\":\"https:\/\/cloudkul.com\/blog\/author\/amit-yadav411\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Magento 2 CORS: Secure your Magento2 store from CORS attack - Cloudkul","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/cloudkul.com\/blog\/magento-2-cors-secure-your-magento2-store-from-cors-attack\/","og_locale":"en_US","og_type":"article","og_title":"Magento 2 CORS: Secure your Magento2 store from CORS attack - Cloudkul","og_description":"So far in this Magento 2 security series we have discussed injection, csrf attacks and [...]","og_url":"https:\/\/cloudkul.com\/blog\/magento-2-cors-secure-your-magento2-store-from-cors-attack\/","og_site_name":"Cloudkul","article_published_time":"2020-09-29T11:27:43+00:00","article_modified_time":"2021-07-19T03:37:07+00:00","author":"Amit Yadav","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/cloudkul.com\/blog\/magento-2-cors-secure-your-magento2-store-from-cors-attack\/","url":"https:\/\/cloudkul.com\/blog\/magento-2-cors-secure-your-magento2-store-from-cors-attack\/","name":"Magento 2 CORS: Secure your Magento2 store from CORS attack - Cloudkul","isPartOf":{"@id":"https:\/\/cloudkul.com\/blog\/#website"},"datePublished":"2020-09-29T11:27:43+00:00","dateModified":"2021-07-19T03:37:07+00:00","author":{"@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/e7fc1ebc6e48c46a938780b19ea8b378"},"breadcrumb":{"@id":"https:\/\/cloudkul.com\/blog\/magento-2-cors-secure-your-magento2-store-from-cors-attack\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cloudkul.com\/blog\/magento-2-cors-secure-your-magento2-store-from-cors-attack\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/cloudkul.com\/blog\/magento-2-cors-secure-your-magento2-store-from-cors-attack\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Magento 2 CORS: Secure your Magento2 store from CORS attack"}]},{"@type":"WebSite","@id":"https:\/\/cloudkul.com\/blog\/#website","url":"https:\/\/cloudkul.com\/blog\/","name":"Cloudkul","description":"Host your eCommerce Store on AWS with Optimized Performance","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cloudkul.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/e7fc1ebc6e48c46a938780b19ea8b378","name":"Amit Yadav","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/154c2c18758419af8c80f50ed0e8c615?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/154c2c18758419af8c80f50ed0e8c615?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g","caption":"Amit Yadav"},"url":"https:\/\/cloudkul.com\/blog\/author\/amit-yadav411\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/8269"}],"collection":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/users\/28"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/comments?post=8269"}],"version-history":[{"count":10,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/8269\/revisions"}],"predecessor-version":[{"id":9708,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/8269\/revisions\/9708"}],"wp:attachment":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/media?parent=8269"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/categories?post=8269"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/tags?post=8269"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}