Fixed Remote Code Execution Vulnerability#1
Fixed Remote Code Execution Vulnerability#1huntr-helper merged 4 commits into418sec:masterfrom mufeedvh:master
Conversation
toufik-airane
left a comment
There was a problem hiding this comment.
Dear @mufeedvh,
Thank you for your contribution.
The regexp isn't easily readable and so maintainable and especially two parts of the expression.
Can you ease the regular expression or at least document it?
Best regards.
index.js
Outdated
|
|
||
| function PDFImage(pdfFilePath, options) { | ||
| // validating the file path for invalid characters to prevent remote code execution | ||
| if (/;|&|`|\$|\(|\)|\|\||\||!|>|<|\?|\${/g.test(pdfFilePath)) { |
There was a problem hiding this comment.
The regexp isn't easily readable and so maintainable and especially two parts of the expression.
The first part is |\|\||\| and the second is |\${.
adam-nygate
left a comment
There was a problem hiding this comment.
Also, it looks like you're duplicating matches for $ symbols and pipes (matching both \|\| and \|). Feel free to revise and then we can accept the PR 🙂
|
Hi, Check out the revised commit, I just cleaned up the Regex to |
toufik-airane
left a comment
There was a problem hiding this comment.
Dear @mufeedvh,
You are restricting too many characters. Some characters seem not related to a command shell feature.
index.js
Outdated
|
|
||
| function PDFImage(pdfFilePath, options) { | ||
| // validating the file path for invalid characters to prevent remote code execution | ||
| var filter_chars = /[`!@#$%^&*()_+\-=\[\]{};':"\\|,<>\/?~]/; |
There was a problem hiding this comment.
Not all characters could trigger remote code execution.
You've blacklisted some harmful and probably legit one such as _ (underscore), ~ (tilde), etc.
I would only filter these characters, that have potential command shell feature:
;|`$()&<>
There was a problem hiding this comment.
Oh yeah didn't think about it. I did it in a hurry and was sleepy! 😅
|
Done, fixed that! 👍 |
|
Congratulations @mufeedvh - your fix has been selected! 🎉 |
⚙️ Fix:
The
PDFImage()function doesn't validate the input ofpdfFilePathinput parameter. ThepdfFilePathparameter accepts the path of the PDF file which is then used in a system command execution which when given without validation will result in a Remote Code Execution (RCE) Vulnerability.What the fix does is: It validates the
pdfFilePathinput and checks for characters that can be used to concatenate any other system commands.❓ How:
The mitigation is implemented with a Regex (
/;|&|`|\$|\(|\)|\|\||\||!|>|<|\?|\${/g) check for invalid characters in index.js📎 Proof of Concept (PoC):
poc.js (put inside the node-pdf-image folder)
🔥 Fix On Action:
OSX:
Linux (Ubuntu):
Run PoC To Test Fix:
❤️ After Fix:
✌️ Fixed!