Skip to content

Commit

Permalink
Prevent loading remote content via URL hash
Browse files Browse the repository at this point in the history
Fixes #1477. Fixes #1126.
  • Loading branch information
jhildenbiddle committed Feb 4, 2021
1 parent eee9507 commit e6c6abb
Showing 1 changed file with 43 additions and 34 deletions.
77 changes: 43 additions & 34 deletions src/core/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,41 +102,50 @@ export function fetchMixin(proto) {
};

proto._fetch = function(cb = noop) {
const { path, query } = this.route;
const qs = stringifyQuery(query, ['id']);
const { loadNavbar, requestHeaders, loadSidebar } = this.config;
// Abort last request

const file = this.router.getFile(path);
const req = request(file + qs, true, requestHeaders);

this.isRemoteUrl = isExternal(file);
// Current page is html
this.isHTML = /\.html$/g.test(file);

// Load main content
req.then(
(text, opt) =>
this._renderMain(
text,
opt,
this._loadSideAndNav(path, qs, loadSidebar, cb)
),
_ => {
this._fetchFallbackPage(path, qs, cb) || this._fetch404(file, qs, cb);
}
);

// Load nav
loadNavbar &&
loadNested(
path,
qs,
loadNavbar,
text => this._renderNav(text),
this,
true
const { query } = this.route;
let { path } = this.route;

// Prevent loading remote content via URL hash
// Ex: https://foo.com/#//bar.com/file.md
if (isExternal(path)) {
history.replaceState(null, '', '#');
this.router.normalize();
} else {
const qs = stringifyQuery(query, ['id']);
const { loadNavbar, requestHeaders, loadSidebar } = this.config;
// Abort last request

const file = this.router.getFile(path);
const req = request(file + qs, true, requestHeaders);

this.isRemoteUrl = isExternal(file);
// Current page is html
this.isHTML = /\.html$/g.test(file);

// Load main content
req.then(
(text, opt) =>
this._renderMain(
text,
opt,
this._loadSideAndNav(path, qs, loadSidebar, cb)
),
_ => {
this._fetchFallbackPage(path, qs, cb) || this._fetch404(file, qs, cb);
}
);

// Load nav
loadNavbar &&
loadNested(
path,
qs,
loadNavbar,
text => this._renderNav(text),
this,
true
);
}
};

proto._fetchCover = function() {
Expand Down

0 comments on commit e6c6abb

Please sign in to comment.