Skip to content

Commit 291b629

Browse files
committed
Block external links
1 parent 89844ba commit 291b629

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

check_logos.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,24 @@ for (const file of files) {
4848
const originalDOM = new JSDOM(svgContent, { contentType: 'image/svg+xml' });
4949
const sanitizedDOM = new JSDOM(cleanSVG, { contentType: 'image/svg+xml' });
5050

51+
const externalUrlPattern = /^(https?|ftp):\/\//i;
52+
const imageElements = originalDOM.window.document.querySelectorAll('image');
53+
const useElements = originalDOM.window.document.querySelectorAll('use');
54+
55+
imageElements.forEach((img, index) => {
56+
const href = img.getAttribute('href') || img.getAttribute('xlink:href');
57+
if (href && externalUrlPattern.test(href.trim())) {
58+
issues.push(`Found external URL in image element: ${href}`);
59+
}
60+
});
61+
62+
useElements.forEach((use, index) => {
63+
const href = use.getAttribute('href') || use.getAttribute('xlink:href');
64+
if (href && externalUrlPattern.test(href.trim())) {
65+
issues.push(`Found external URL in use element: ${href}`);
66+
}
67+
});
68+
5169
const originalScripts = originalDOM.window.document.querySelectorAll('script');
5270
const sanitizedScripts = sanitizedDOM.window.document.querySelectorAll('script');
5371

0 commit comments

Comments
 (0)