A Magento 2 module that enables configurable CORS Headers on the GraphQL and REST APIs

Overview

Magento 2 CORS

Packagist Downloads Packagist Version Packagist License Build Status

Magento Version Support

Magento v2.3 Supported Magento v2.4 Supported

Ever try to work with the Magento GraphQL API or REST API from your browser and see the following?

Access to XMLHttpRequest at 'https://my.magento.app' from origin 'http://my.webapp.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

This package allows you to securely add the necessary CORS headers to the Magento 2 GraphQL or REST APIs with ease.

Purpose

When building a headless application for Magento, or working with a client that respects the CORS protocol, you will need CORS headers on your backend resource.

This package will add configurable CORS Resource headers to the Magento 2 GraphQL or REST APIs, allowing you to access the GraphQL or REST APIs from your browser.

Getting Started

This module is intended to be installed with composer. From the root of your Magento 2 project:

  1. Download the package
composer require graycore/magento2-cors
  1. Configure the package
  2. Enable the package
./bin/magento module:enable Graycore_Cors

Features

Helpful Links

Upgrading

Comments
  • Add header provider for Access-Control-Allow-Credentials

    Add header provider for Access-Control-Allow-Credentials

    • Header provider for Allow-Credentials
    • If Allow-Credentials is true; a wildcard is now used to dynamically echo the request origin in the allowed-origin header
    • Unit test and documentation updates to include details of the Allow-Credentials functionality
    documentation enhancement 
    opened by moloughlin 13
  • feat(graphql,rest): add faster CORS headers

    feat(graphql,rest): add faster CORS headers

    PR Checklist

    Please check if your PR fulfills the following requirements:

    • [x] The commit message follows our guidelines: https://github.com/graycoreio/magento2-cors/blob/master/CONTRIBUTING.md#commit
    • [x] Tests for the changes have been added (for bug fixes / features)
    • [x] Docs have been added / updated (for bug fixes / features)

    PR Type

    What kind of change does this PR introduce?

    [ ] Bugfix
    [x] Feature
    [ ] Code style update (formatting, local variables)
    [ ] Refactoring (no functional changes, no api changes)
    [ ] Build related changes
    [ ] CI related changes
    [ ] Documentation content changes
    [ ] Other... Please describe:
    

    What is the current behavior?

    Fixes: #65

    What is the new behavior?

    The layer in which we compute whether or not an incoming preflight request receives CORS headers has changed. Previously, we leveraged a plugin around the relevant native Magento 2 Controller (webapi_rest/graphql) and as a result, we incurred significant overhead from Magento code when computing CORS headers.

    In the new code we no longer incur this overhead by adding a plugin around application launch and creating our own custom controller. It is very possible that we broke expectations of anything that plugs-in around this plugin or adds additional CORS headers other than our own.

    For 99.99% of GraphQl/Rest API deployments, the API is used sessionlessly. As such, we can take the opportunity to improve performance for the majority at the expense of the minority. If this breaks your codebase, please submit an issue and we will see what can be done to remedy your specific use-case.

    In theory, most dependents simply need to upgrade and there are no breaking changes.

    However, if you were expecting to use the native GraphQl/REST controller when computing CORS headers (and everything else that entails - like having a Magento session, for example) that guarantee is no-longer provided.

    Does this PR introduce a breaking change?

    [x] Yes
    [ ] No
    

    Other information

    opened by damienwebdev 10
  • ci(all): cache composer dependencies

    ci(all): cache composer dependencies

    PR Checklist

    Please check if your PR fulfills the following requirements:

    • [x] The commit message follows our guidelines: https://github.com/graycoreio/magento2-cors/blob/master/CONTRIBUTING.md#commit
    • [x] Tests for the changes have been added (for bug fixes / features)
    • [x] Docs have been added / updated (for bug fixes / features)

    PR Type

    What kind of change does this PR introduce?

    [ ] Bugfix
    [ ] Feature
    [ ] Code style update (formatting, local variables)
    [ ] Refactoring (no functional changes, no api changes)
    [ ] Build related changes
    [ ] CI related changes
    [ ] Documentation content changes
    [ ] Other... Please describe:
    

    What is the current behavior?

    We download deps every time we build.

    Fixes: N/A

    What is the new behavior?

    We download deps IFF the lock file changes.

    Does this PR introduce a breaking change?

    [ ] Yes
    [x] No
    
    opened by damienwebdev 9
  • Prevent fatal error when using Chrome extensions for graphql querying

    Prevent fatal error when using Chrome extensions for graphql querying

    Hey team; thanks for providing this - it's going to be a big help for our Headless efforts.

    One problem I have though is that I use a GraphQL Chrome extension (Altair) for my testing, which sends an Origin Request header with a chrome-extension:// scheme. The Zend framework fails to validate that as part of the getHeader() call, and throws an error.

    I've proposed that we catch this specific exception and treat it the same way as a request without an Origin header.

    Shout out if you have any thoughts or concerns.

    enhancement 
    opened by moloughlin 7
  • ci(all): add ci pipeline to run unit and integration tests

    ci(all): add ci pipeline to run unit and integration tests

    We should add CI to ensure consistent build quality. Preferably, we should use Azure DevOps.

    Currently, while tests are written, they are not run in CI.

    We need to run both the integration and unit tests, and these two processes can be done in parallel.

    See https://github.com/magento/adobe-stock-integration/blob/1.1-develop/.travis.yml as an example of a working Travis sample. We would need to translate this over to Azure Devops and run against PR builds and master.

    • [x] Linting (static) (#16 and #17)
    • [x] Unit (#18 & #19)
    • [ ] Integration
    • [ ] Api-Functional
    opened by damienwebdev 7
  • Magento Rest Options Error

    Magento Rest Options Error

    Hi, I was using the SplashLabs CORS module, but ran into a blocker with it when trying to POST to the guest-cart. I disabled it and installed your module, added the configs etc etc.

    Now I can't even see the initial API GET product request work anymore. We are using Magento 2.3.3 (commerce) on Magento Cloud - working on Integration instance.

    In the exception I see: [2021-03-09 05:45:50] report.CRITICAL: Request method is invalid. {"report_id":"076a55918ca8c940a9c25f3cc440482a965e1d6ed7b7e24d647dbc8906e6b43d","exception":"[object] (Magento\Framework\Exception\InputException(code: 0): Request method is invalid. at /app/vendor/magento/framework/Webapi/Rest/Request.php:180)"} []

    Which closely matched an access log: 193.114.101.142 - - [09/Mar/2021:05:45:50 +0000] "OPTIONS /rest/V1/products?&searchCriteria[filter_groups][0][filters][0][field]=entity_id&searchCriteria[filter_groups][0][filters][0][value]=3019&searchCriteria[filter_groups][0][filters][0][condition_type]=eq HTTP/1.1" 500 501 "https://crv-test5.racingjd.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36"

    I notice that in your module your not overriding the ->getHttpMethod() which by default does not recognise OPTIONS method (which is inherently the Magento shortcoming)

    Did we miss something in the setup? The module was active, and cached were flushed after the deployment.. I even tried a few different option variations..

    Thnx...

    bug 
    opened by gilbert-rehling 6
  • [FEAT] Add Magento 2.4 support

    [FEAT] Add Magento 2.4 support

    :bulb: Feature request

    Add Magento 2.4 Support

    The Desired Behavior

    Installation of this module works with Magento 2.4.

    Your Use Case

    As a developer I want to use this module in Magento 2.4.

    I tried to install this module in the following environment:

    magento2-cors version: 1.3.0
    Magento version: 2.4.0 
    PHP Version version: 7.4.9

    and got the following error message:

    Problem 1
        - magento/framework 102.0.0 requires php ~7.1.3||~7.2.0 -> your PHP version (7.4.9) does not satisfy that requirement.
        - magento/framework 102.0.1 requires php ~7.1.3||~7.2.0 -> your PHP version (7.4.9) does not satisfy that requirement.
        - magento/framework 102.0.2 requires php ~7.1.3||~7.2.0 -> your PHP version (7.4.9) does not satisfy that requirement.
        - magento/framework 102.0.3 requires php ~7.1.3||~7.2.0||~7.3.0 -> your PHP version (7.4.9) does not satisfy that requirement.
        - magento/framework 102.0.2-p2 requires php ~7.1.3||~7.2.0 -> your PHP version (7.4.9) does not satisfy that requirement.
        - magento/framework 102.0.4 requires php ~7.1.3||~7.2.0||~7.3.0 -> your PHP version (7.4.9) does not satisfy that requirement.
        - magento/framework 102.0.3-p1 requires php ~7.1.3||~7.2.0||~7.3.0 -> your PHP version (7.4.9) does not satisfy that requirement.
        - magento/framework 102.0.5 requires php ~7.1.3||~7.2.0||~7.3.0 -> your PHP version (7.4.9) does not satisfy that requirement.
        - magento/framework 102.0.4-p2 requires php ~7.1.3||~7.2.0||~7.3.0 -> your PHP version (7.4.9) does not satisfy that requirement.
        - magento/framework 102.0.5-p2 requires php ~7.1.3||~7.2.0||~7.3.0 -> your PHP version (7.4.9) does not satisfy that requirement.
        - graycore/magento2-cors 1.3.0 requires magento/framework ^102.0 -> satisfiable by magento/framework[102.0.5-p2, 102.0.4-p2, 102.0.5, 102.0.3-p1, 102.0.4, 102.0.2-p2, 102.0.3, 102.0.2, 102.0.1, 102.0.0].
        - Installation request for graycore/magento2-cors ^1.3 -> satisfiable by graycore/magento2-cors[1.3.0].
    
    opened by JulianZschieschang 6
  • Better PHP8.1 support

    Better PHP8.1 support

    PHP8.1 throws a warning when $string is null, if it is any form of empty we can immediately return with an empty array.

    PR Checklist

    Please check if your PR fulfills the following requirements:

    • [ ] The commit message follows our guidelines: https://github.com/graycoreio/magento2-cors/blob/master/CONTRIBUTING.md#commit
    • [ ] Tests for the changes have been added (for bug fixes / features)
    • [ ] Docs have been added / updated (for bug fixes / features)

    PR Type

    What kind of change does this PR introduce?

    [x] Bugfix
    [ ] Feature
    [ ] Code style update (formatting, local variables)
    [ ] Refactoring (no functional changes, no api changes)
    [ ] Build related changes
    [ ] CI related changes
    [ ] Documentation content changes
    [ ] Other... Please describe:
    

    What is the current behavior?

    PHP8.1 throws a warning when $string is null, if it is any form of empty we can immediately return with an empty array.

    Fixes: N/A

    What is the new behavior?

    The module short circuits with an empty array if $string is empty

    Does this PR introduce a breaking change?

    [ ] Yes
    [x] No
    

    Other information

    opened by indykoning 2
  • chore(deps): update standard-version to 9.1.1

    chore(deps): update standard-version to 9.1.1

    PR Checklist

    Please check if your PR fulfills the following requirements:

    • [ ] The commit message follows our guidelines: https://github.com/graycoreio/magento2-cors/blob/master/CONTRIBUTING.md#commit
    • [ ] Tests for the changes have been added (for bug fixes / features)
    • [ ] Docs have been added / updated (for bug fixes / features)

    PR Type

    What kind of change does this PR introduce?

    [ ] Bugfix
    [ ] Feature
    [ ] Code style update (formatting, local variables)
    [ ] Refactoring (no functional changes, no api changes)
    [ ] Build related changes
    [ ] CI related changes
    [ ] Documentation content changes
    [ ] Other... Please describe:
    

    What is the current behavior?

    Fixes: N/A

    What is the new behavior?

    Does this PR introduce a breaking change?

    [ ] Yes
    [ ] No
    

    Other information

    opened by damienwebdev 2
  • chore(deps): bump ini from 1.3.5 to 1.3.7

    chore(deps): bump ini from 1.3.5 to 1.3.7

    Bumps ini from 1.3.5 to 1.3.7.

    Commits
    • c74c8af 1.3.7
    • 024b8b5 update deps, add linting
    • 032fbaf Use Object.create(null) to avoid default object property hazards
    • 2da9039 1.3.6
    • cfea636 better git push script, before publish instead of after
    • 56d2805 do not allow invalid hazardous string as section name
    • See full diff in compare view
    Maintainer changes

    This version was pushed to npm by isaacs, a new releaser for ini since your current version.


    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 2
  • chore(deps-dev): bump standard-version from 6.0.1 to 8.0.1

    chore(deps-dev): bump standard-version from 6.0.1 to 8.0.1

    Bumps standard-version from 6.0.1 to 8.0.1.

    Release notes

    Sourced from standard-version's releases.

    standard-version v8.0.1

    Bug Fixes

    • deps: update dependency conventional-changelog to v3.1.21 (#586) (fd456c9)
    • deps: update dependency conventional-changelog-conventionalcommits to v4.3.0 (#587) (b3b5eed)
    • deps: update dependency conventional-recommended-bump to v6.0.9 (#588) (d4d2ac2)
    • deps: update dependency git-semver-tags to v4 (#589) (a0f0e81)
    • Vulnerability Report GHSL-2020-11101 (9d978ac)

    standard-version v8.0.0

    ⚠ BREAKING CHANGES

    • composer.json and composer.lock will no longer be read from or bumped by default. If you need to obtain a version or write a version to these files, please use bumpFiles and/or packageFiles options accordingly.

    Bug Fixes

    • composer.json and composer.lock have been removed from default package and bump files. (c934f3a), closes #495 #394
    • deps: update dependency conventional-changelog to v3.1.18 (#510) (e6aeb77)
    • deps: update dependency yargs to v15.1.0 (#518) (8f36f9e)
    • deps: update dependency yargs to v15.3.1 (#559) (d98cd46)
    Changelog

    Sourced from standard-version's changelog.

    8.0.1 (2020-07-12)

    Bug Fixes

    • deps: update dependency conventional-changelog to v3.1.21 (#586) (fd456c9)
    • deps: update dependency conventional-changelog-conventionalcommits to v4.3.0 (#587) (b3b5eed)
    • deps: update dependency conventional-recommended-bump to v6.0.9 (#588) (d4d2ac2)
    • deps: update dependency git-semver-tags to v4 (#589) (a0f0e81)
    • Vulnerability Report GHSL-2020-11101 (9d978ac)

    8.0.0 (2020-05-06)

    ⚠ BREAKING CHANGES

    • composer.json and composer.lock will no longer be read from or bumped by default. If you need to obtain a version or write a version to these files, please use bumpFiles and/or packageFiles options accordingly.

    Bug Fixes

    • composer.json and composer.lock have been removed from default package and bump files. (c934f3a), closes #495 #394
    • deps: update dependency conventional-changelog to v3.1.18 (#510) (e6aeb77)
    • deps: update dependency yargs to v15.1.0 (#518) (8f36f9e)
    • deps: update dependency yargs to v15.3.1 (#559) (d98cd46)

    7.1.0 (2019-12-08)

    Features

    • Adds support for header (--header) configuration based on the spec. (#364) (ba80a0c)
    • custom 'bumpFiles' and 'packageFiles' support (#372) (564d948)

    Bug Fixes

    • deps: update dependency conventional-changelog to v3.1.15 (#479) (492e721)
    • deps: update dependency conventional-changelog-conventionalcommits to v4.2.3 (#496) (bc606f8)
    • deps: update dependency conventional-recommended-bump to v6.0.5 (#480) (1e1e215)
    • deps: update dependency yargs to v15 (#484) (35b90c3)
    • use require.resolve for the default preset (#465) (d557372)
    • deps: update dependency detect-newline to v3.1.0 (#482) (04ab36a)
    • deps: update dependency figures to v3.1.0 (#468) (63300a9)
    • deps: update dependency git-semver-tags to v3.0.1 (#485) (9cc188c)
    • deps: update dependency yargs to v14.2.1 (#483) (dc1fa61)
    • deps: update dependency yargs to v14.2.2 (#488) (ecf26b6)

    7.0.1 (2019-11-07)

    Commits
    • 57e4e25 chore: release 8.0.1 (#611)
    • 58105e1 chore: Adds basic issue templates (#613)
    • 9d978ac fix: Vulnerability Report GHSL-2020-11101
    • 267d78d chore: stop pinning deps (#615)
    • da84ec4 test(windows): skip mock-git tests for Windows (#616)
    • 871201f Merge pull request from GHSA-7xcx-6wjh-7xp2
    • a0f0e81 fix(deps): update dependency git-semver-tags to v4 (#589)
    • fd456c9 fix(deps): update dependency conventional-changelog to v3.1.21 (#586)
    • b3b5eed fix(deps): update dependency conventional-changelog-conventionalcommits to v4...
    • d4d2ac2 fix(deps): update dependency conventional-recommended-bump to v6.0.9 (#588)
    • Additional commits viewable in compare view
    Maintainer changes

    This version was pushed to npm by oss-bot, a new releaser for standard-version since your current version.


    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 2
Releases(v2.0.0)
Owner
Graycore, LLC
Graycore, LLC - let's make the internet a better place.
Graycore, LLC
Magento Quickorder module, enables bulk order creation by inputting SKUs & quantities.

Extension User Guide This extension was developed to enable merchants to allow customers to place multiple orders of various quanities quickly, in an

Popesites 30 Apr 24, 2022
Enhancement to Magento to allow simple product prices to be used instead of the default special-case configurable product prices

Simple Configurable Products Extension For Magento This documentation applies to SCP versions 0.7 onwards. The documentation for SCP v0.6 and earlier

Simon King 288 Nov 7, 2022
Package to send customer specific prices to Magento from a Laravel application using a configurable source.

Laravel Magento Customer Prices This package provides a way to add customer specific prices to Magento from a Laravel app. By default, it uses the Mag

JustBetter 14 Nov 4, 2022
Package to send prices to Magento from a Laravel application using a configurable source.

Laravel Magento Prices Package to send prices to Magento from a Laravel application using a configurable source. Features The idea is that we want to

JustBetter 15 Nov 4, 2022
MailChimp for Magento 2. Syncs all data (subscriber, customers, orders, products) and enables marketing automation with email campaigns, automations, ads, postcards and more.

MailChimp for Magento 2. Syncs all data (subscriber, customers, orders, products) and enables marketing automation with email campaigns, automations, ads, postcards and more.

Mailchimp 139 Sep 9, 2022
Harden request headers, login interface and passwords to increase backend security.

JvMTECH.NeosHardening Package for Neos CMS Harden request headers, login interface and passwords to increase backend security. Installation composer r

Jung von Matt TECH 3 May 4, 2022
Enables developers to modify Magento installations (configuration, data) based on the given environment using n98-magerun.

Enables developers to modify Magento installations (configuration, data) based on the given environment using n98-magerun.

LimeSoda Interactive Marketing GmbH 73 Apr 1, 2022
Lightweight PHP wrapper for OVH APIs. That's the easiest way to use OVH.com APIs in your PHP applications.

This PHP package is a lightweight wrapper for OVH APIs. That's the easiest way to use OVH.com APIs in your PHP applications.

OVHcloud 263 Dec 14, 2022
Magento 2 Module Experius Page Not Found 404. This module saves all 404 url to a database table

Magento 2 Module Experius Page Not Found 404 This module saves all 404 urls to a database table. Adds an admin grid with 404s It includes a count so y

Experius 28 Dec 9, 2022
Automatically load the next page of products in Magento. Easy to install and configure, this module works 100% out of the box with vanilla Magento 1.9.x and earlier.

Automatically load the next page of products in Magento. Easy to install and configure, this module works 100% out of the box with vanilla Magento 1.9.x and earlier.

Strategery 123 Nov 20, 2021
A tool for creating configurable dumps of large MySQL-databases.

slimdump slimdump is a little tool to help you create configurable dumps of large MySQL-databases. It works off one or several configuration files. Fo

webfactory GmbH 176 Dec 26, 2022
Oui player - Manage configurable media players in @Textpattern CMS

oui_player Introduction An extendable plugin to easily embed customized audio and video players. . This plugin does not use oembed, it builds iframe e

Nicolas Morand 3 Aug 15, 2018
Simple configurable plugin to see all commands executed by players

About [FR] Simple plugin configurable permettant de voir toutes les commandes exécutées par les joueurs [ENG] Simple configurable plugin to see all co

leo 1 Feb 4, 2022
A tool that allows to quickly export data from Magento 1 and Magento 2 store and import it back into Magento 2

Simple Import / Export tool A tool that allows to quickly export data from Magento 1 and Magento 2 store and import it back into Magento 2. Table data

EcomDev B.V. 51 Dec 5, 2022
Laravel Podcast Manager is a complete podcast manager package for Laravel 5.3+ that enables you to manage RSS feeds for your favorite podcasts and listen to the episodes in a seamless UI.

laravelpodcast | A Laravel podcast manager package - v0.0.8 Introduction Laravel Podcast Manager is a complete podcast manager package for Laravel 5.3

Jeremy Kenedy 22 Nov 4, 2022
LaraNx Seo enables your Laravel app to store SEO and social media meta tag data in database instead of your code

LaraNx Seo enables your Laravel app to store SEO and social media meta tag data in database instead of your code. Moving marketing data out of your code base and into your database where it is easily modified.

srg 13 Dec 29, 2022
Ecotone Framework is Service Bus Implementation. It enables message driven architecture and DDD, CQRS, Event Sourcing PHP

This is Read Only Repository To contribute make use of Ecotone-Dev repository. Ecotone is Service Bus Implementation, which enables message driven arc

EcotoneFramework 308 Dec 29, 2022