Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: isExternal check with malformed URL + tests #1510

Merged
merged 2 commits into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(/#\/$/);
});
}
});
});