Skip to content

Commit

Permalink
fix: isExternal check with malformed URL + tests (#1510)
Browse files Browse the repository at this point in the history
Fix #1477. Fix #1126. Follow-up to #1489.
  • Loading branch information
jhildenbiddle authored Feb 18, 2021
1 parent 6c13bdb commit ff2a66f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function loadNested(path, qs, file, next, vm, first) {

function isExternal(url) {
let match = url.match(
/^([^:/?#]+:)?(?:\/\/([^/?#]*))?([^?#]+)?(\?[^#]*)?(#.*)?/
/^([^:/?#]+:)?(?:\/{2,}([^/?#]*))?([^?#]+)?(\?[^#]*)?(#.*)?/
);
if (
typeof match[1] === 'string' &&
Expand Down
32 changes: 32 additions & 0 deletions test/e2e/security.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const docsifyInit = require('../helpers/docsify-init');

describe(`Security`, function() {
const sharedOptions = {
markdown: {
homepage: '# Hello World',
},
routes: {
'test.md': '# Test Page',
},
};

describe(`Cross Site Scripting (XSS)`, function() {
const slashStrings = ['//', '///'];

for (const slashString of slashStrings) {
const hash = `#${slashString}domain.com/file.md`;

test(`should not load remote content from hash (${hash})`, async () => {
await docsifyInit(sharedOptions);
await expect(page).toHaveText('#main', 'Hello World');
await page.evaluate(() => (location.hash = '#/test'));
await expect(page).toHaveText('#main', 'Test Page');
await page.evaluate(newHash => {
location.hash = newHash;
}, hash);
await expect(page).toHaveText('#main', 'Hello World');
expect(page.url()).toMatch(/#\/$/);
});
}
});
});

1 comment on commit ff2a66f

@vercel
Copy link

@vercel vercel bot commented on ff2a66f Feb 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.