Skip to content

Commit 8b1d87b

Browse files
author
Oleksandr Gorkun
committed
MC-19927: Implement hash-whitelisting, dynamic CSP
1 parent a5668b3 commit 8b1d87b

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

app/code/Magento/Csp/Helper/InlineUtil.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private function extractRemoteFonts(string $styleContent): array
9797
$urlsFound = [[]];
9898
preg_match_all('/\@font\-face\s*?\{([^\}]*)[^\}]*?\}/im', $styleContent, $fontFaces);
9999
foreach ($fontFaces[1] as $fontFaceContent) {
100-
preg_match_all('/url\((http(s)?\:[^\)]+)\)/i', $fontFaceContent, $urls);
100+
preg_match_all('/url\([\'\"]?(http(s)?\:[^\)]+)[\'\"]?\)/i', $fontFaceContent, $urls);
101101
$urlsFound[] = $urls[1];
102102
}
103103

dev/tests/integration/testsuite/Magento/Csp/Helper/InlineUtilTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,17 @@ public function getTags(): array
139139
'style',
140140
['type' => 'text/css'],
141141
"\n @font-face {\n font-family: \"MyCustomFont\";"
142-
."\n src: url(http://magento.com/static/font.ttf);\n }\n"
142+
."\n src: url(\"http://magento.com/static/font.ttf\");\n }\n"
143143
." @font-face {\n font-family: \"MyCustomFont2\";"
144-
."\n src: url(https://magento.com/static/font-2.ttf),"
144+
."\n src: url('https://magento.com/static/font-2.ttf'),"
145145
."\n url(static/font.ttf),"
146146
."\n url(https://devdocs.magento.com/static/another-font.woff),"
147147
."\n url(http://devdocs.magento.com/static/font.woff);\n }\n",
148148
"<style type=\"text/css\">"
149149
."\n @font-face {\n font-family: \"MyCustomFont\";"
150-
."\n src: url(http://magento.com/static/font.ttf);\n }\n"
150+
."\n src: url(\"http://magento.com/static/font.ttf\");\n }\n"
151151
." @font-face {\n font-family: \"MyCustomFont2\";"
152-
."\n src: url(https://magento.com/static/font-2.ttf),"
152+
."\n src: url('https://magento.com/static/font-2.ttf'),"
153153
."\n url(static/font.ttf),"
154154
."\n url(https://devdocs.magento.com/static/another-font.woff),"
155155
."\n url(http://devdocs.magento.com/static/font.woff);\n }\n"
@@ -174,7 +174,7 @@ public function getTags(): array
174174
false,
175175
false,
176176
[],
177-
['ha3DQAQqMpmhqPFaZpQV5tjgDc1QzTkIlfJ2R9hflVw=' => 'sha256']
177+
['TP6Ulnz1kstJ8PYUKvowgJm0phHhtqJnJCnWxKLXkf0=' => 'sha256']
178178
)
179179
]
180180
],

0 commit comments

Comments
 (0)