Skip to content

Commit e80056d

Browse files
committed
add feature #389
1 parent fca4c7c commit e80056d

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/package.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ function isGitHubRepository(repository: string): boolean {
183183
return /^https:\/\/github\.com\/|^git@github\.com:/.test(repository || '');
184184
}
185185

186+
function isGitHubBadge(href: string): boolean {
187+
return isGitHubRepository(href) && /[A-Za-z0-9_-]{1,100}\/workflows\/[^<>:;,?"*|/]+\/badge\.svg$/.test(href || '');
188+
}
189+
186190
class ManifestProcessor extends BaseProcessor {
187191

188192
constructor(manifest: Manifest) {
@@ -449,7 +453,7 @@ export class MarkdownProcessor extends BaseProcessor {
449453
throw new Error(`Images in ${this.name} must come from an HTTPS source: ${src}`);
450454
}
451455

452-
if (/\.svg$/i.test(srcUrl.pathname) && !isHostTrusted(srcUrl.host)) {
456+
if (/\.svg$/i.test(srcUrl.pathname) && (!isHostTrusted(srcUrl.host) && !isGitHubBadge(srcUrl.href))) {
453457
throw new Error(`SVGs are restricted in ${this.name}; please use other file image formats, such as PNG: ${src}`);
454458
}
455459
});
@@ -694,7 +698,7 @@ export function validateManifest(manifest: Manifest): Manifest {
694698
throw new Error(`Badge URLs must come from an HTTPS source: ${badge.url}`);
695699
}
696700

697-
if (/\.svg$/i.test(srcUrl.pathname) && !isHostTrusted(srcUrl.host)) {
701+
if (/\.svg$/i.test(srcUrl.pathname) && (!isHostTrusted(srcUrl.host) && !isGitHubBadge(srcUrl.href))) {
698702
throw new Error(`Badge SVGs are restricted. Please use other file image formats, such as PNG: ${badge.url}`);
699703
}
700704
});

src/test/package.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,6 +1615,16 @@ describe('MarkdownProcessor', () => {
16151615
assert(file);
16161616
});
16171617

1618+
it('should allow SVG from GitHub actions in image tag', async() => {
1619+
const manifest = { name: 'test', publisher: 'mocha', version: '0.0.1', engines: Object.create(null), repository: 'https://github.com/username/repository' };
1620+
const contents = `![title](https://github.com/fakeuser/fakerepo/workflows/fakeworkflowname/badge.svg)`;
1621+
const processor = new ReadmeProcessor(manifest, {});
1622+
const readme = { path: 'extension/readme.md', contents };
1623+
1624+
const file = await processor.onFile(readme);
1625+
assert(file);
1626+
});
1627+
16181628
it('should prevent SVGs from not trusted sources in img tags', async () => {
16191629
const manifest = { name: 'test', publisher: 'mocha', version: '0.0.1', engines: Object.create(null), repository: 'https://github.com/username/repository' };
16201630
const contents = `<img src="https://foo/hello.svg" />`;

0 commit comments

Comments
 (0)