@@ -1,5 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * @copyright Copyright (c) 2016, ownCloud, Inc. |
| 5 | 5 | * |
@@ -31,186 +31,186 @@ |
||
| 31 | 31 | * @package OC\Security\CSP |
| 32 | 32 | */ |
| 33 | 33 | class ContentSecurityPolicy extends \OCP\AppFramework\Http\ContentSecurityPolicy { |
| 34 | - /** |
|
| 35 | - * @return boolean |
|
| 36 | - */ |
|
| 37 | - public function isInlineScriptAllowed(): bool { |
|
| 38 | - return $this->inlineScriptAllowed; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @param boolean $inlineScriptAllowed |
|
| 43 | - */ |
|
| 44 | - public function setInlineScriptAllowed(bool $inlineScriptAllowed) { |
|
| 45 | - $this->inlineScriptAllowed = $inlineScriptAllowed; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @return boolean |
|
| 50 | - */ |
|
| 51 | - public function isEvalScriptAllowed(): bool { |
|
| 52 | - return $this->evalScriptAllowed; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @param boolean $evalScriptAllowed |
|
| 57 | - */ |
|
| 58 | - public function setEvalScriptAllowed(bool $evalScriptAllowed) { |
|
| 59 | - $this->evalScriptAllowed = $evalScriptAllowed; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @return array |
|
| 64 | - */ |
|
| 65 | - public function getAllowedScriptDomains(): array { |
|
| 66 | - return $this->allowedScriptDomains; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @param array $allowedScriptDomains |
|
| 71 | - */ |
|
| 72 | - public function setAllowedScriptDomains(array $allowedScriptDomains) { |
|
| 73 | - $this->allowedScriptDomains = $allowedScriptDomains; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @return boolean |
|
| 78 | - */ |
|
| 79 | - public function isInlineStyleAllowed(): bool { |
|
| 80 | - return $this->inlineStyleAllowed; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @param boolean $inlineStyleAllowed |
|
| 85 | - */ |
|
| 86 | - public function setInlineStyleAllowed(bool $inlineStyleAllowed) { |
|
| 87 | - $this->inlineStyleAllowed = $inlineStyleAllowed; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @return array |
|
| 92 | - */ |
|
| 93 | - public function getAllowedStyleDomains(): array { |
|
| 94 | - return $this->allowedStyleDomains; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @param array $allowedStyleDomains |
|
| 99 | - */ |
|
| 100 | - public function setAllowedStyleDomains(array $allowedStyleDomains) { |
|
| 101 | - $this->allowedStyleDomains = $allowedStyleDomains; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * @return array |
|
| 106 | - */ |
|
| 107 | - public function getAllowedImageDomains(): array { |
|
| 108 | - return $this->allowedImageDomains; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * @param array $allowedImageDomains |
|
| 113 | - */ |
|
| 114 | - public function setAllowedImageDomains(array $allowedImageDomains) { |
|
| 115 | - $this->allowedImageDomains = $allowedImageDomains; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * @return array |
|
| 120 | - */ |
|
| 121 | - public function getAllowedConnectDomains(): array { |
|
| 122 | - return $this->allowedConnectDomains; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * @param array $allowedConnectDomains |
|
| 127 | - */ |
|
| 128 | - public function setAllowedConnectDomains(array $allowedConnectDomains) { |
|
| 129 | - $this->allowedConnectDomains = $allowedConnectDomains; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * @return array |
|
| 134 | - */ |
|
| 135 | - public function getAllowedMediaDomains(): array { |
|
| 136 | - return $this->allowedMediaDomains; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @param array $allowedMediaDomains |
|
| 141 | - */ |
|
| 142 | - public function setAllowedMediaDomains(array $allowedMediaDomains) { |
|
| 143 | - $this->allowedMediaDomains = $allowedMediaDomains; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @return array |
|
| 148 | - */ |
|
| 149 | - public function getAllowedObjectDomains(): array { |
|
| 150 | - return $this->allowedObjectDomains; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * @param array $allowedObjectDomains |
|
| 155 | - */ |
|
| 156 | - public function setAllowedObjectDomains(array $allowedObjectDomains) { |
|
| 157 | - $this->allowedObjectDomains = $allowedObjectDomains; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * @return array |
|
| 162 | - */ |
|
| 163 | - public function getAllowedFrameDomains(): array { |
|
| 164 | - return $this->allowedFrameDomains; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * @param array $allowedFrameDomains |
|
| 169 | - */ |
|
| 170 | - public function setAllowedFrameDomains(array $allowedFrameDomains) { |
|
| 171 | - $this->allowedFrameDomains = $allowedFrameDomains; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * @return array |
|
| 176 | - */ |
|
| 177 | - public function getAllowedFontDomains(): array { |
|
| 178 | - return $this->allowedFontDomains; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * @param array $allowedFontDomains |
|
| 183 | - */ |
|
| 184 | - public function setAllowedFontDomains($allowedFontDomains) { |
|
| 185 | - $this->allowedFontDomains = $allowedFontDomains; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * @return array |
|
| 190 | - */ |
|
| 191 | - public function getAllowedChildSrcDomains(): array { |
|
| 192 | - return $this->allowedChildSrcDomains; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * @param array $allowedChildSrcDomains |
|
| 197 | - */ |
|
| 198 | - public function setAllowedChildSrcDomains($allowedChildSrcDomains) { |
|
| 199 | - $this->allowedChildSrcDomains = $allowedChildSrcDomains; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * @return array |
|
| 204 | - */ |
|
| 205 | - public function getAllowedFrameAncestors(): array { |
|
| 206 | - return $this->allowedFrameAncestors; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * @param array $allowedFrameAncestors |
|
| 211 | - */ |
|
| 212 | - public function setAllowedFrameAncestors($allowedFrameAncestors) { |
|
| 213 | - $this->allowedFrameAncestors = $allowedFrameAncestors; |
|
| 214 | - } |
|
| 34 | + /** |
|
| 35 | + * @return boolean |
|
| 36 | + */ |
|
| 37 | + public function isInlineScriptAllowed(): bool { |
|
| 38 | + return $this->inlineScriptAllowed; |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @param boolean $inlineScriptAllowed |
|
| 43 | + */ |
|
| 44 | + public function setInlineScriptAllowed(bool $inlineScriptAllowed) { |
|
| 45 | + $this->inlineScriptAllowed = $inlineScriptAllowed; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @return boolean |
|
| 50 | + */ |
|
| 51 | + public function isEvalScriptAllowed(): bool { |
|
| 52 | + return $this->evalScriptAllowed; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @param boolean $evalScriptAllowed |
|
| 57 | + */ |
|
| 58 | + public function setEvalScriptAllowed(bool $evalScriptAllowed) { |
|
| 59 | + $this->evalScriptAllowed = $evalScriptAllowed; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @return array |
|
| 64 | + */ |
|
| 65 | + public function getAllowedScriptDomains(): array { |
|
| 66 | + return $this->allowedScriptDomains; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @param array $allowedScriptDomains |
|
| 71 | + */ |
|
| 72 | + public function setAllowedScriptDomains(array $allowedScriptDomains) { |
|
| 73 | + $this->allowedScriptDomains = $allowedScriptDomains; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @return boolean |
|
| 78 | + */ |
|
| 79 | + public function isInlineStyleAllowed(): bool { |
|
| 80 | + return $this->inlineStyleAllowed; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @param boolean $inlineStyleAllowed |
|
| 85 | + */ |
|
| 86 | + public function setInlineStyleAllowed(bool $inlineStyleAllowed) { |
|
| 87 | + $this->inlineStyleAllowed = $inlineStyleAllowed; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @return array |
|
| 92 | + */ |
|
| 93 | + public function getAllowedStyleDomains(): array { |
|
| 94 | + return $this->allowedStyleDomains; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @param array $allowedStyleDomains |
|
| 99 | + */ |
|
| 100 | + public function setAllowedStyleDomains(array $allowedStyleDomains) { |
|
| 101 | + $this->allowedStyleDomains = $allowedStyleDomains; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * @return array |
|
| 106 | + */ |
|
| 107 | + public function getAllowedImageDomains(): array { |
|
| 108 | + return $this->allowedImageDomains; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * @param array $allowedImageDomains |
|
| 113 | + */ |
|
| 114 | + public function setAllowedImageDomains(array $allowedImageDomains) { |
|
| 115 | + $this->allowedImageDomains = $allowedImageDomains; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @return array |
|
| 120 | + */ |
|
| 121 | + public function getAllowedConnectDomains(): array { |
|
| 122 | + return $this->allowedConnectDomains; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * @param array $allowedConnectDomains |
|
| 127 | + */ |
|
| 128 | + public function setAllowedConnectDomains(array $allowedConnectDomains) { |
|
| 129 | + $this->allowedConnectDomains = $allowedConnectDomains; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * @return array |
|
| 134 | + */ |
|
| 135 | + public function getAllowedMediaDomains(): array { |
|
| 136 | + return $this->allowedMediaDomains; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @param array $allowedMediaDomains |
|
| 141 | + */ |
|
| 142 | + public function setAllowedMediaDomains(array $allowedMediaDomains) { |
|
| 143 | + $this->allowedMediaDomains = $allowedMediaDomains; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @return array |
|
| 148 | + */ |
|
| 149 | + public function getAllowedObjectDomains(): array { |
|
| 150 | + return $this->allowedObjectDomains; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * @param array $allowedObjectDomains |
|
| 155 | + */ |
|
| 156 | + public function setAllowedObjectDomains(array $allowedObjectDomains) { |
|
| 157 | + $this->allowedObjectDomains = $allowedObjectDomains; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * @return array |
|
| 162 | + */ |
|
| 163 | + public function getAllowedFrameDomains(): array { |
|
| 164 | + return $this->allowedFrameDomains; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * @param array $allowedFrameDomains |
|
| 169 | + */ |
|
| 170 | + public function setAllowedFrameDomains(array $allowedFrameDomains) { |
|
| 171 | + $this->allowedFrameDomains = $allowedFrameDomains; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * @return array |
|
| 176 | + */ |
|
| 177 | + public function getAllowedFontDomains(): array { |
|
| 178 | + return $this->allowedFontDomains; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * @param array $allowedFontDomains |
|
| 183 | + */ |
|
| 184 | + public function setAllowedFontDomains($allowedFontDomains) { |
|
| 185 | + $this->allowedFontDomains = $allowedFontDomains; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * @return array |
|
| 190 | + */ |
|
| 191 | + public function getAllowedChildSrcDomains(): array { |
|
| 192 | + return $this->allowedChildSrcDomains; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * @param array $allowedChildSrcDomains |
|
| 197 | + */ |
|
| 198 | + public function setAllowedChildSrcDomains($allowedChildSrcDomains) { |
|
| 199 | + $this->allowedChildSrcDomains = $allowedChildSrcDomains; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * @return array |
|
| 204 | + */ |
|
| 205 | + public function getAllowedFrameAncestors(): array { |
|
| 206 | + return $this->allowedFrameAncestors; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * @param array $allowedFrameAncestors |
|
| 211 | + */ |
|
| 212 | + public function setAllowedFrameAncestors($allowedFrameAncestors) { |
|
| 213 | + $this->allowedFrameAncestors = $allowedFrameAncestors; |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | 216 | } |
@@ -28,48 +28,48 @@ |
||
| 28 | 28 | use OCP\Security\IContentSecurityPolicyManager; |
| 29 | 29 | |
| 30 | 30 | class ContentSecurityPolicyManager implements IContentSecurityPolicyManager { |
| 31 | - /** @var ContentSecurityPolicy[] */ |
|
| 32 | - private $policies = []; |
|
| 31 | + /** @var ContentSecurityPolicy[] */ |
|
| 32 | + private $policies = []; |
|
| 33 | 33 | |
| 34 | - /** {@inheritdoc} */ |
|
| 35 | - public function addDefaultPolicy(EmptyContentSecurityPolicy $policy) { |
|
| 36 | - $this->policies[] = $policy; |
|
| 37 | - } |
|
| 34 | + /** {@inheritdoc} */ |
|
| 35 | + public function addDefaultPolicy(EmptyContentSecurityPolicy $policy) { |
|
| 36 | + $this->policies[] = $policy; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Get the configured default policy. This is not in the public namespace |
|
| 41 | - * as it is only supposed to be used by core itself. |
|
| 42 | - * |
|
| 43 | - * @return ContentSecurityPolicy |
|
| 44 | - */ |
|
| 45 | - public function getDefaultPolicy(): ContentSecurityPolicy { |
|
| 46 | - $defaultPolicy = new \OC\Security\CSP\ContentSecurityPolicy(); |
|
| 47 | - foreach($this->policies as $policy) { |
|
| 48 | - $defaultPolicy = $this->mergePolicies($defaultPolicy, $policy); |
|
| 49 | - } |
|
| 50 | - return $defaultPolicy; |
|
| 51 | - } |
|
| 39 | + /** |
|
| 40 | + * Get the configured default policy. This is not in the public namespace |
|
| 41 | + * as it is only supposed to be used by core itself. |
|
| 42 | + * |
|
| 43 | + * @return ContentSecurityPolicy |
|
| 44 | + */ |
|
| 45 | + public function getDefaultPolicy(): ContentSecurityPolicy { |
|
| 46 | + $defaultPolicy = new \OC\Security\CSP\ContentSecurityPolicy(); |
|
| 47 | + foreach($this->policies as $policy) { |
|
| 48 | + $defaultPolicy = $this->mergePolicies($defaultPolicy, $policy); |
|
| 49 | + } |
|
| 50 | + return $defaultPolicy; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Merges the first given policy with the second one |
|
| 55 | - * |
|
| 56 | - * @param ContentSecurityPolicy $defaultPolicy |
|
| 57 | - * @param EmptyContentSecurityPolicy $originalPolicy |
|
| 58 | - * @return ContentSecurityPolicy |
|
| 59 | - */ |
|
| 60 | - public function mergePolicies(ContentSecurityPolicy $defaultPolicy, |
|
| 61 | - EmptyContentSecurityPolicy $originalPolicy): ContentSecurityPolicy { |
|
| 62 | - foreach((object)(array)$originalPolicy as $name => $value) { |
|
| 63 | - $setter = 'set'.ucfirst($name); |
|
| 64 | - if(\is_array($value)) { |
|
| 65 | - $getter = 'get'.ucfirst($name); |
|
| 66 | - $currentValues = \is_array($defaultPolicy->$getter()) ? $defaultPolicy->$getter() : []; |
|
| 67 | - $defaultPolicy->$setter(array_values(array_unique(array_merge($currentValues, $value)))); |
|
| 68 | - } elseif (\is_bool($value)) { |
|
| 69 | - $defaultPolicy->$setter($value); |
|
| 70 | - } |
|
| 71 | - } |
|
| 53 | + /** |
|
| 54 | + * Merges the first given policy with the second one |
|
| 55 | + * |
|
| 56 | + * @param ContentSecurityPolicy $defaultPolicy |
|
| 57 | + * @param EmptyContentSecurityPolicy $originalPolicy |
|
| 58 | + * @return ContentSecurityPolicy |
|
| 59 | + */ |
|
| 60 | + public function mergePolicies(ContentSecurityPolicy $defaultPolicy, |
|
| 61 | + EmptyContentSecurityPolicy $originalPolicy): ContentSecurityPolicy { |
|
| 62 | + foreach((object)(array)$originalPolicy as $name => $value) { |
|
| 63 | + $setter = 'set'.ucfirst($name); |
|
| 64 | + if(\is_array($value)) { |
|
| 65 | + $getter = 'get'.ucfirst($name); |
|
| 66 | + $currentValues = \is_array($defaultPolicy->$getter()) ? $defaultPolicy->$getter() : []; |
|
| 67 | + $defaultPolicy->$setter(array_values(array_unique(array_merge($currentValues, $value)))); |
|
| 68 | + } elseif (\is_bool($value)) { |
|
| 69 | + $defaultPolicy->$setter($value); |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - return $defaultPolicy; |
|
| 74 | - } |
|
| 73 | + return $defaultPolicy; |
|
| 74 | + } |
|
| 75 | 75 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * @copyright Copyright (c) 2016, ownCloud, Inc. |
| 5 | 5 | * |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | public function getDefaultPolicy(): ContentSecurityPolicy { |
| 46 | 46 | $defaultPolicy = new \OC\Security\CSP\ContentSecurityPolicy(); |
| 47 | - foreach($this->policies as $policy) { |
|
| 47 | + foreach ($this->policies as $policy) { |
|
| 48 | 48 | $defaultPolicy = $this->mergePolicies($defaultPolicy, $policy); |
| 49 | 49 | } |
| 50 | 50 | return $defaultPolicy; |
@@ -59,9 +59,9 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | public function mergePolicies(ContentSecurityPolicy $defaultPolicy, |
| 61 | 61 | EmptyContentSecurityPolicy $originalPolicy): ContentSecurityPolicy { |
| 62 | - foreach((object)(array)$originalPolicy as $name => $value) { |
|
| 62 | + foreach ((object) (array) $originalPolicy as $name => $value) { |
|
| 63 | 63 | $setter = 'set'.ucfirst($name); |
| 64 | - if(\is_array($value)) { |
|
| 64 | + if (\is_array($value)) { |
|
| 65 | 65 | $getter = 'get'.ucfirst($name); |
| 66 | 66 | $currentValues = \is_array($defaultPolicy->$getter()) ? $defaultPolicy->$getter() : []; |
| 67 | 67 | $defaultPolicy->$setter(array_values(array_unique(array_merge($currentValues, $value)))); |
@@ -34,52 +34,52 @@ |
||
| 34 | 34 | * @package OC\Security\CSP |
| 35 | 35 | */ |
| 36 | 36 | class ContentSecurityPolicyNonceManager { |
| 37 | - /** @var CsrfTokenManager */ |
|
| 38 | - private $csrfTokenManager; |
|
| 39 | - /** @var IRequest */ |
|
| 40 | - private $request; |
|
| 41 | - /** @var string */ |
|
| 42 | - private $nonce = ''; |
|
| 37 | + /** @var CsrfTokenManager */ |
|
| 38 | + private $csrfTokenManager; |
|
| 39 | + /** @var IRequest */ |
|
| 40 | + private $request; |
|
| 41 | + /** @var string */ |
|
| 42 | + private $nonce = ''; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @param CsrfTokenManager $csrfTokenManager |
|
| 46 | - * @param IRequest $request |
|
| 47 | - */ |
|
| 48 | - public function __construct(CsrfTokenManager $csrfTokenManager, |
|
| 49 | - IRequest $request) { |
|
| 50 | - $this->csrfTokenManager = $csrfTokenManager; |
|
| 51 | - $this->request = $request; |
|
| 52 | - } |
|
| 44 | + /** |
|
| 45 | + * @param CsrfTokenManager $csrfTokenManager |
|
| 46 | + * @param IRequest $request |
|
| 47 | + */ |
|
| 48 | + public function __construct(CsrfTokenManager $csrfTokenManager, |
|
| 49 | + IRequest $request) { |
|
| 50 | + $this->csrfTokenManager = $csrfTokenManager; |
|
| 51 | + $this->request = $request; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Returns the current CSP nounce |
|
| 56 | - * |
|
| 57 | - * @return string |
|
| 58 | - */ |
|
| 59 | - public function getNonce(): string { |
|
| 60 | - if($this->nonce === '') { |
|
| 61 | - $this->nonce = base64_encode($this->csrfTokenManager->getToken()->getEncryptedValue()); |
|
| 62 | - } |
|
| 54 | + /** |
|
| 55 | + * Returns the current CSP nounce |
|
| 56 | + * |
|
| 57 | + * @return string |
|
| 58 | + */ |
|
| 59 | + public function getNonce(): string { |
|
| 60 | + if($this->nonce === '') { |
|
| 61 | + $this->nonce = base64_encode($this->csrfTokenManager->getToken()->getEncryptedValue()); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - return $this->nonce; |
|
| 65 | - } |
|
| 64 | + return $this->nonce; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Check if the browser supports CSP v3 |
|
| 69 | - * |
|
| 70 | - * @return bool |
|
| 71 | - */ |
|
| 72 | - public function browserSupportsCspV3(): bool { |
|
| 73 | - $browserWhitelist = [ |
|
| 74 | - Request::USER_AGENT_CHROME, |
|
| 75 | - // Firefox 45+ |
|
| 76 | - '/^Mozilla\/5\.0 \([^)]+\) Gecko\/[0-9.]+ Firefox\/(4[5-9]|[5-9][0-9])\.[0-9.]+$/', |
|
| 77 | - ]; |
|
| 67 | + /** |
|
| 68 | + * Check if the browser supports CSP v3 |
|
| 69 | + * |
|
| 70 | + * @return bool |
|
| 71 | + */ |
|
| 72 | + public function browserSupportsCspV3(): bool { |
|
| 73 | + $browserWhitelist = [ |
|
| 74 | + Request::USER_AGENT_CHROME, |
|
| 75 | + // Firefox 45+ |
|
| 76 | + '/^Mozilla\/5\.0 \([^)]+\) Gecko\/[0-9.]+ Firefox\/(4[5-9]|[5-9][0-9])\.[0-9.]+$/', |
|
| 77 | + ]; |
|
| 78 | 78 | |
| 79 | - if($this->request->isUserAgent($browserWhitelist)) { |
|
| 80 | - return true; |
|
| 81 | - } |
|
| 79 | + if($this->request->isUserAgent($browserWhitelist)) { |
|
| 80 | + return true; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - return false; |
|
| 84 | - } |
|
| 83 | + return false; |
|
| 84 | + } |
|
| 85 | 85 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * @copyright Copyright (c) 2016 Lukas Reschke <[email protected]> |
| 5 | 5 | * |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * @return string |
| 58 | 58 | */ |
| 59 | 59 | public function getNonce(): string { |
| 60 | - if($this->nonce === '') { |
|
| 60 | + if ($this->nonce === '') { |
|
| 61 | 61 | $this->nonce = base64_encode($this->csrfTokenManager->getToken()->getEncryptedValue()); |
| 62 | 62 | } |
| 63 | 63 | |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | '/^Mozilla\/5\.0 \([^)]+\) Gecko\/[0-9.]+ Firefox\/(4[5-9]|[5-9][0-9])\.[0-9.]+$/', |
| 77 | 77 | ]; |
| 78 | 78 | |
| 79 | - if($this->request->isUserAgent($browserWhitelist)) { |
|
| 79 | + if ($this->request->isUserAgent($browserWhitelist)) { |
|
| 80 | 80 | return true; |
| 81 | 81 | } |
| 82 | 82 | |