Skip to content

Commit e6c6abb

Browse files
committed
Prevent loading remote content via URL hash
Fixes #1477. Fixes #1126.
1 parent eee9507 commit e6c6abb

File tree

1 file changed

+43
-34
lines changed

1 file changed

+43
-34
lines changed

src/core/fetch/index.js

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -102,41 +102,50 @@ export function fetchMixin(proto) {
102102
};
103103

104104
proto._fetch = function(cb = noop) {
105-
const { path, query } = this.route;
106-
const qs = stringifyQuery(query, ['id']);
107-
const { loadNavbar, requestHeaders, loadSidebar } = this.config;
108-
// Abort last request
109-
110-
const file = this.router.getFile(path);
111-
const req = request(file + qs, true, requestHeaders);
112-
113-
this.isRemoteUrl = isExternal(file);
114-
// Current page is html
115-
this.isHTML = /\.html$/g.test(file);
116-
117-
// Load main content
118-
req.then(
119-
(text, opt) =>
120-
this._renderMain(
121-
text,
122-
opt,
123-
this._loadSideAndNav(path, qs, loadSidebar, cb)
124-
),
125-
_ => {
126-
this._fetchFallbackPage(path, qs, cb) || this._fetch404(file, qs, cb);
127-
}
128-
);
129-
130-
// Load nav
131-
loadNavbar &&
132-
loadNested(
133-
path,
134-
qs,
135-
loadNavbar,
136-
text => this._renderNav(text),
137-
this,
138-
true
105+
const { query } = this.route;
106+
let { path } = this.route;
107+
108+
// Prevent loading remote content via URL hash
109+
// Ex: https://foo.com/#//bar.com/file.md
110+
if (isExternal(path)) {
111+
history.replaceState(null, '', '#');
112+
this.router.normalize();
113+
} else {
114+
const qs = stringifyQuery(query, ['id']);
115+
const { loadNavbar, requestHeaders, loadSidebar } = this.config;
116+
// Abort last request
117+
118+
const file = this.router.getFile(path);
119+
const req = request(file + qs, true, requestHeaders);
120+
121+
this.isRemoteUrl = isExternal(file);
122+
// Current page is html
123+
this.isHTML = /\.html$/g.test(file);
124+
125+
// Load main content
126+
req.then(
127+
(text, opt) =>
128+
this._renderMain(
129+
text,
130+
opt,
131+
this._loadSideAndNav(path, qs, loadSidebar, cb)
132+
),
133+
_ => {
134+
this._fetchFallbackPage(path, qs, cb) || this._fetch404(file, qs, cb);
135+
}
139136
);
137+
138+
// Load nav
139+
loadNavbar &&
140+
loadNested(
141+
path,
142+
qs,
143+
loadNavbar,
144+
text => this._renderNav(text),
145+
this,
146+
true
147+
);
148+
}
140149
};
141150

142151
proto._fetchCover = function() {

0 commit comments

Comments
 (0)