Skip to content

Commit ff2a66f

Browse files
authoredFeb 18, 2021
fix: isExternal check with malformed URL + tests (#1510)
Fix #1477. Fix #1126. Follow-up to #1489.
1 parent 6c13bdb commit ff2a66f

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed
 

Diff for: ‎src/core/fetch/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function loadNested(path, qs, file, next, vm, first) {
2222

2323
function isExternal(url) {
2424
let match = url.match(
25-
/^([^:/?#]+:)?(?:\/\/([^/?#]*))?([^?#]+)?(\?[^#]*)?(#.*)?/
25+
/^([^:/?#]+:)?(?:\/{2,}([^/?#]*))?([^?#]+)?(\?[^#]*)?(#.*)?/
2626
);
2727
if (
2828
typeof match[1] === 'string' &&

Diff for: ‎test/e2e/security.test.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const docsifyInit = require('../helpers/docsify-init');
2+
3+
describe(`Security`, function() {
4+
const sharedOptions = {
5+
markdown: {
6+
homepage: '# Hello World',
7+
},
8+
routes: {
9+
'test.md': '# Test Page',
10+
},
11+
};
12+
13+
describe(`Cross Site Scripting (XSS)`, function() {
14+
const slashStrings = ['//', '///'];
15+
16+
for (const slashString of slashStrings) {
17+
const hash = `#${slashString}domain.com/file.md`;
18+
19+
test(`should not load remote content from hash (${hash})`, async () => {
20+
await docsifyInit(sharedOptions);
21+
await expect(page).toHaveText('#main', 'Hello World');
22+
await page.evaluate(() => (location.hash = '#/test'));
23+
await expect(page).toHaveText('#main', 'Test Page');
24+
await page.evaluate(newHash => {
25+
location.hash = newHash;
26+
}, hash);
27+
await expect(page).toHaveText('#main', 'Hello World');
28+
expect(page.url()).toMatch(/#\/$/);
29+
});
30+
}
31+
});
32+
});