Skip to content

Commit 26bb6ca

Browse files
Potential fix for code scanning alert no. 22: Incomplete URL substring sanitization
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 4fdc9b2 commit 26bb6ca

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

packages/stencil-library/src/rendererModules/SPDXType.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,15 @@ export class SPDXType extends GenericIdentifierType {
405405
* Finds the most official-looking URL from a list of URLs
406406
*/
407407
private findOfficialUrl(urls: string[]): string | undefined {
408+
const allowedHosts = ['opensource.org', 'fsf.org', 'gnu.org', 'apache.org', 'creativecommons.org'];
408409
return urls.find((url: string) => {
409-
const lower = url.toLowerCase();
410-
return lower.includes('opensource.org') || lower.includes('fsf.org') || lower.includes('gnu.org') || lower.includes('apache.org') || lower.includes('creativecommons.org');
410+
try {
411+
const parsedUrl = new URL(url);
412+
return allowedHosts.includes(parsedUrl.host);
413+
} catch {
414+
// Ignore invalid URLs
415+
return false;
416+
}
411417
});
412418
}
413419

0 commit comments

Comments
 (0)