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

Do some validation on @downloadURL for OUJS based URIs #1004

Merged
merged 1 commit into from
May 6, 2016
Merged
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
37 changes: 31 additions & 6 deletions controllers/scriptStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,9 @@ exports.storeScript = function (aUser, aMeta, aBuf, aCallback, aUpdate) {
var name = null;
var thisName = null;
var scriptName = null;
var rAnyLocalHost = new RegExp('^(?:openuserjs\.org|oujs\.org' +
(isDev ? '|localhost:' + (process.env.PORT || 8080) : '') + ')');
var downloadURL = null;
var author = null;
var collaborators = null;
var installName = aUser.name + '/';
Expand Down Expand Up @@ -784,7 +787,29 @@ exports.storeScript = function (aUser, aMeta, aBuf, aCallback, aUpdate) {
}

// Can't install a userscript name ending in a reserved extension
if (/\.min$/.test(scriptName)) {
if (/\.(?:min|user|user\.js|meta)$/.test(scriptName)) {
aCallback(null);
return;
}


// `downloadURL` validations
downloadURL = URL.parse(findMeta(aMeta, 'UserScript.downloadURL.0.value'));

// Shouldn't install a userscript with a downloadURL of meta .user.js
if (rAnyLocalHost.test(downloadURL.host) &&
/^\/meta/.test(downloadURL.pathname) &&
/\.user\.js$/.test(downloadURL.pathname))
{
aCallback(null);
return;
}

// Shouldn't install a userscript with a downloadURL of source .meta.js
if (rAnyLocalHost.test(downloadURL.host) &&
/^\/(?:install|src\/scripts)/.test(downloadURL.pathname) &&
/\.meta\.js$/.test(downloadURL.pathname))
{
aCallback(null);
return;
}
Expand Down Expand Up @@ -817,14 +842,14 @@ exports.storeScript = function (aUser, aMeta, aBuf, aCallback, aUpdate) {
});
}
} else {
scriptName = cleanFilename(aMeta.replace(/^\s+|\s+$/g, ''), '');
scriptName = cleanFilename(aMeta.trim(), '');
if (!scriptName) {
aCallback(null);
return;
}

// Can't install a library name ending in a reserved extension
if (/\.(min|user|meta)$/.test(scriptName)) {
// Can't reference a library name ending in a reserved extension
if (/\.(min|user|user\.js|meta)$/.test(scriptName)) {
aCallback(null);
return;
}
Expand All @@ -843,7 +868,7 @@ exports.storeScript = function (aUser, aMeta, aBuf, aCallback, aUpdate) {
} else if (!aScript) {
// New script
aScript = new Script({
name: isLibrary ? aMeta : thisName,
name: isLibrary ? aMeta.trim() : thisName,
author: aUser.name,
installs: 0,
rating: 0,
Expand All @@ -853,7 +878,7 @@ exports.storeScript = function (aUser, aMeta, aBuf, aCallback, aUpdate) {
flags: { critical: 0, absolute: 0 },
installName: installName,
fork: null,
meta: isLibrary ? { name: aMeta } : aMeta,
meta: isLibrary ? { name: aMeta.trim() } : aMeta,
isLib: isLibrary,
uses: isLibrary ? null : libraries,
_authorId: aUser._id
Expand Down