Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hostep committed May 23, 2024
0 parents commit e9e8347
Show file tree
Hide file tree
Showing 21 changed files with 9,762 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.php-cs-fixer.cache
/auth.json
/vendor-bin/*/vendor
/vendor/
1 change: 1 addition & 0 deletions .php-auto-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
php82
29 changes: 29 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use PhpCsFixer\Finder as PhpCsFixerFinder;
use PhpCsFixer\Config as PhpCsFixerConfig;
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;

$finder = PhpCsFixerFinder::create()
->in(__DIR__)
->exclude('vendor')
->exclude('vendor-bin')
;

$config = new PhpCsFixerConfig();
return $config
->setParallelConfig(ParallelConfigFactory::detect())
->setRules([
'@PER-CS' => true,
'binary_operator_spaces' => ['default' => 'at_least_single_space', 'operators' => ['=>' => 'align']],
'declare_strict_types' => true,
'no_alias_functions' => true,
'no_useless_sprintf' => true,
'nullable_type_declaration_for_default_null_value' => true,
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'phpdoc_align' => ['align' => 'vertical'],
'phpdoc_separation' => ['skip_unlisted_annotations' => true],
'self_accessor' => true,
])
->setFinder($finder)
;
13 changes: 13 additions & 0 deletions Helper/CspNonceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Magento\Csp\Helper;

class CspNonceProvider
{
public function generateNonce(): string
{
return '';
}
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Baldwin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# set default target which is executed when no explicit target is provided on the cli
.DEFAULT_GOAL := default

.PHONY: default
default:
# do nothing

.PHONY: check
check: checkquality checkstyle

.PHONY: checkstyle
checkstyle:
vendor-bin/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run --diff --stop-on-violation --allow-risky=yes
vendor-bin/phpcs/vendor/bin/phpcs -s --standard=Magento2 --exclude=Magento2.Annotation.MethodAnnotationStructure,Magento2.CodeAnalysis.EmptyBlock --ignore=./vendor/,./vendor-bin/ .
vendor-bin/phpcs/vendor/bin/phpcs -s --standard=PHPCompatibility --runtime-set testVersion 8.2- --ignore=./vendor/,./vendor-bin/ .
vendor/bin/composer normalize --dry-run

.PHONY: checkquality
checkquality:
vendor-bin/phpstan/vendor/bin/phpstan analyse

xmllint --noout --schema vendor/magento/framework/Module/etc/module.xsd etc/module.xml
13 changes: 13 additions & 0 deletions Model/Collector/DynamicCollector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Magento\Csp\Model\Collector;

class DynamicCollector
{
public function add(mixed $policy): void
{
// do nothing
}
}
24 changes: 24 additions & 0 deletions Model/Policy/FetchPolicy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Magento\Csp\Model\Policy;

class FetchPolicy
{
public function __construct(
string $id,
bool $noneAllowed = true,
array $hostSources = [],
array $schemeSources = [],
bool $selfAllowed = false,
bool $inlineAllowed = false,
bool $evalAllowed = false,
array $nonceValues = [],
array $hashValues = [],
bool $dynamicAllowed = false,
bool $eventHandlersAllowed = false,
) {
// do nothing
}
}
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# CSP shim module for Magento 2

## Purpose

This module exists for people who don't want to deal with the CSP (Content-Security-Policy) module which ships with Magento.

Up until Magento 2.4.7, it was simple, you could just remove the module via composer's `replace` syntax.
But in Magento 2.4.7, this module is more tightly integrated with certain modules (like the AdminAnalytics, Checkout and Paypal modules), which - when you try to remove the CSP module using composer's `replace` syntax - would cause `bin/magento setup:di:compile` to fail.

This module provides a solution for this case, by pretending to be the Magento CSP module for certain classes that some other modules require. The classes introduced by this module use the Magento namespace because there doesn't seem to be another way of doing this but the classes are actually empty and only contain empty functions just so nothing crashes when other modules call them.

This module comes bundled with the composer `replace` line to remove the Magento CSP module, so you don't need to do this yourself anymore.

## Watch out

- The module is currently declared compatible with Magento 2.4.7 only, it's hard to predict what will happen in the future, so we'll try to open up compatibility with more future Magento versions when they get released.

## Compatibility

- This module should work with Magento 2.4.7
- The module should be compatible with PHP 8.2 and 8.3

## Installation

You can use composer to install this module:

```sh
composer require baldwin/magento2-module-csp-shim
```

After which you can then activate it in Magento using:

```sh
bin/magento setup:upgrade
```
53 changes: 53 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"name": "baldwin/magento2-module-csp-shim",
"description": "Magento 2 module which replaces the default Magento CSP module and effectively disables its functionality",
"license": "MIT",
"type": "magento2-module",
"authors": [
{
"name": "Pieter Hoste",
"email": "pieter@baldwin.be",
"role": "Problem Solver"
}
],
"require": {
"php": "~8.2.0 || ~8.3.0",
"magento/framework": "^103.0.7",
"magento/module-csp": "100.4.6"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8",
"ergebnis/composer-normalize": "^2.42"
},
"replace": {
"magento/module-csp": "*"
},
"repositories": [
{
"type": "composer",
"url": "https://repo.magento.com/"
}
],
"autoload": {
"psr-4": {
"Magento\\Csp\\": ""
},
"files": [
"registration.php"
]
},
"config": {
"allow-plugins": {
"bamarni/composer-bin-plugin": true,
"ergebnis/composer-normalize": true,
"magento/composer-dependency-version-audit-plugin": false
},
"sort-packages": true
},
"extra": {
"bamarni-bin": {
"bin-links": false,
"forward-command": true
}
}
}
Loading

0 comments on commit e9e8347

Please sign in to comment.