-
-
Notifications
You must be signed in to change notification settings - Fork 290
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 RCE in gateway.downloadBackup #2171
Closed
+94
−3
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
95c7a36
Fix RCE in gateway.downloadBackup
bnematzadeh 25b207b
Fix RCE in gateway.downloadBackup
bnematzadeh 72e8f17
Update gateway.downloadBackup
bnematzadeh d6e3d60
Update gateway.downloadBackup
bnematzadeh c58a539
Update gateway.downloadBackup
bnematzadeh dbc7753
Update gateway.downloadBackup.js
bnematzadeh 744e7d4
Merge branch 'GladysAssistant:master' into gladys-sec-2
bnematzadeh 0a4a46c
Update gateway.downloadBackup.js
bnematzadeh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const { expect } = require('chai'); | ||
const { isURL, validateUrl } = require('../../utils/url'); | ||
|
||
describe('url.validation', () => { | ||
it('should return true for a valid url', () => { | ||
const url = 'https://example.com'; | ||
expect(isURL(url)).to.equal(true); | ||
}); | ||
|
||
it('should return false for an invalid url', () => { | ||
const url = '/a/b'; | ||
expect(isURL(url)).to.equal(false); | ||
}); | ||
|
||
it('should return valid url', () => { | ||
const url = 'https://example.com/test'; | ||
expect(validateUrl(url)).to.be.equal('https://example.com/test'); | ||
}); | ||
|
||
it('should throw an error for malicious url', () => { | ||
const url = 'https://example.com/test?#a'; | ||
expect(() => { | ||
validateUrl(url); | ||
}).to.throw(Error); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const Joi = require('joi'); | ||
const { InvalidURL } = require('./coreErrors'); | ||
|
||
/** | ||
* @description Typeof url. | ||
* @param {string} str - The url of the backup. | ||
* @returns {boolean} Return true for valid url. | ||
* @example | ||
* isURL(); | ||
*/ | ||
const isURL = (str) => { | ||
try { | ||
const url = new URL(str); | ||
return url.protocol === 'http:' || url.protocol === 'https:'; | ||
} catch (_) { | ||
return false; | ||
} | ||
}; | ||
|
||
/** | ||
* @description Validate the url. | ||
* @param {string} url - The url of the backup. | ||
* @returns {string} Return a valid url. | ||
* @example | ||
* validateUrl(); | ||
*/ | ||
function validateUrl(url) { | ||
const schema = Joi.string() | ||
.uri() | ||
.pattern(/^[^?#]*$/, ''); | ||
const { error, value } = schema.validate(url); | ||
if (error) { | ||
throw new InvalidURL('INVALID_URL'); | ||
} else { | ||
return value; | ||
} | ||
} | ||
|
||
module.exports = { | ||
isURL, | ||
validateUrl, | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You created a generic function "validateUrl" in
utils
, but isn't this behavior very gateway.downloadBackup specific?Will this be used elsewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What change should I make so that the GET parameter is removed before it’s passed to path.basename()? The validator I wrote, in my opinion, can be used in other places, but it’s largely tied to gateway.downloadBackup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
fileWithoutSignedParams
instead ? (as it was before)