add feature #389
This commit is contained in:
parent
fca4c7ce19
commit
e80056d64e
2 changed files with 16 additions and 2 deletions
|
@ -183,6 +183,10 @@ function isGitHubRepository(repository: string): boolean {
|
|||
return /^https:\/\/github\.com\/|^git@github\.com:/.test(repository || '');
|
||||
}
|
||||
|
||||
function isGitHubBadge(href: string): boolean {
|
||||
return isGitHubRepository(href) && /[A-Za-z0-9_-]{1,100}\/workflows\/[^<>:;,?"*|/]+\/badge\.svg$/.test(href || '');
|
||||
}
|
||||
|
||||
class ManifestProcessor extends BaseProcessor {
|
||||
|
||||
constructor(manifest: Manifest) {
|
||||
|
@ -449,7 +453,7 @@ export class MarkdownProcessor extends BaseProcessor {
|
|||
throw new Error(`Images in ${this.name} must come from an HTTPS source: ${src}`);
|
||||
}
|
||||
|
||||
if (/\.svg$/i.test(srcUrl.pathname) && !isHostTrusted(srcUrl.host)) {
|
||||
if (/\.svg$/i.test(srcUrl.pathname) && (!isHostTrusted(srcUrl.host) && !isGitHubBadge(srcUrl.href))) {
|
||||
throw new Error(`SVGs are restricted in ${this.name}; please use other file image formats, such as PNG: ${src}`);
|
||||
}
|
||||
});
|
||||
|
@ -694,7 +698,7 @@ export function validateManifest(manifest: Manifest): Manifest {
|
|||
throw new Error(`Badge URLs must come from an HTTPS source: ${badge.url}`);
|
||||
}
|
||||
|
||||
if (/\.svg$/i.test(srcUrl.pathname) && !isHostTrusted(srcUrl.host)) {
|
||||
if (/\.svg$/i.test(srcUrl.pathname) && (!isHostTrusted(srcUrl.host) && !isGitHubBadge(srcUrl.href))) {
|
||||
throw new Error(`Badge SVGs are restricted. Please use other file image formats, such as PNG: ${badge.url}`);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1615,6 +1615,16 @@ describe('MarkdownProcessor', () => {
|
|||
assert(file);
|
||||
});
|
||||
|
||||
it('should allow SVG from GitHub actions in image tag', async() => {
|
||||
const manifest = { name: 'test', publisher: 'mocha', version: '0.0.1', engines: Object.create(null), repository: 'https://github.com/username/repository' };
|
||||
const contents = `![title](https://github.com/fakeuser/fakerepo/workflows/fakeworkflowname/badge.svg)`;
|
||||
const processor = new ReadmeProcessor(manifest, {});
|
||||
const readme = { path: 'extension/readme.md', contents };
|
||||
|
||||
const file = await processor.onFile(readme);
|
||||
assert(file);
|
||||
});
|
||||
|
||||
it('should prevent SVGs from not trusted sources in img tags', async () => {
|
||||
const manifest = { name: 'test', publisher: 'mocha', version: '0.0.1', engines: Object.create(null), repository: 'https://github.com/username/repository' };
|
||||
const contents = `<img src="https://foo/hello.svg" />`;
|
||||
|
|
Loading…
Add table
Reference in a new issue