mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-09 09:45:42 +02:00
Rejects incorrect url in download manager
This commit is contained in:
parent
ef658bf5f1
commit
28778e6c1b
3 changed files with 30 additions and 22 deletions
22
src/util.js
22
src/util.js
|
@ -108,6 +108,28 @@ function combineUrl(baseUrl, url) {
|
|||
}
|
||||
}
|
||||
|
||||
// Validates if URL is safe and allowed, e.g. to avoid XSS.
|
||||
function isValidUrl(url, allowRelative) {
|
||||
if (!url) {
|
||||
return false;
|
||||
}
|
||||
var colon = url.indexOf(':');
|
||||
if (colon < 0) {
|
||||
return allowRelative;
|
||||
}
|
||||
var protocol = url.substr(0, colon);
|
||||
switch (protocol) {
|
||||
case 'http':
|
||||
case 'https':
|
||||
case 'ftp':
|
||||
case 'mailto':
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
PDFJS.isValidUrl = isValidUrl;
|
||||
|
||||
// In a well-formed PDF, |cond| holds. If it doesn't, subsequent
|
||||
// behavior is undefined.
|
||||
function assertWellFormed(cond, msg) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue