Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Fix Path traversal vulnerability#1

Merged
JamieSlome merged 2 commits into418sec:masterfrom
alromh87:master
Sep 10, 2020
Merged

Fix Path traversal vulnerability#1
JamieSlome merged 2 commits into418sec:masterfrom
alromh87:master

Conversation

@alromh87
Copy link

@alromh87 alromh87 commented Sep 4, 2020

📊 Metadata *

marscode is a web editor created with monaco-editor, jquery file tree and nodejs file tree to read, write, edit, delete (CRUD) files.

Affected versions of this package are vulnerable to Directory Traversal.

Bounty URL: https://www.huntr.dev/bounties/1-npm-marscode/

⚙️ Description *

There is no path sanitization in the path provided making marscode vulnerable against path traversal through the ../ technique, leading to information exposure and file content disclosure.

💻 Technical Description *

Fixed by sanitizing any occurrence of ../, using regexp.

🐛 Proof of Concept (PoC) *

  1. Start the server
    node index.js
  2. Request private file from server
    curl -v --path-as-is http://127.0.0.1:8080/../../../../../../../../../../../etc/passwd
  3. /etc/passwd will be displayed.
    POCC

🔥 Proof of Fix (PoF) *

After fix Response code 400 Bad request is returned to user instead of restricted file content
Captura de pantalla de 2020-09-02 15-33-46

👍 User Acceptance Testing (UAT)

After fix functionality is unafected
Captura de pantalla de 2020-09-02 15-45-54

Copy link

@Mik317 Mik317 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @alromh87 😄,
thanks for your help in securing the OSS 👍

The fix proposed is bypassable due to the usage of querystring.unescape which is used when the /api/.. endpoint is called. Try these steps:

  1. Start your server (fixed version) with node index.js
  2. Open another terminal and execute:
curl --path-as-is http://localtest.me:8080/api/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd

Screenshot from 2020-09-07 21-09-10

Cheers,
Mik

@alromh87
Copy link
Author

alromh87 commented Sep 7, 2020

Thank you for calling my attention to it, taken care of

@alromh87 alromh87 requested a review from Mik317 September 7, 2020 19:42
Copy link

@Mik317 Mik317 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really solid fix 😄 🎉

Cheers,
Mik

@JamieSlome JamieSlome merged commit 5131151 into 418sec:master Sep 10, 2020
@huntr-helper
Copy link

Congratulations alromh87 - your fix has been selected! 🎉

Thanks for being part of the community & helping secure the world's open source code.
If you have any questions, please respond in the comments section. Your bounty is on its way - keep hunting!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants