nightmare icon indicating copy to clipboard operation
nightmare copied to clipboard

Remove window.__nightmare access

Open glyph opened this issue 7 years ago • 4 comments
trafficstars

I hope that the current response to #1234 (i.e.: adding a small note in the README) is not the end of the security story for Nightmare.

Electron does caution you to be careful, but it also offers sandboxing. It's documented here https://electronjs.org/docs/api/sandbox-option and a more in-depth tutorial on enabling this can be found here: https://github.com/kewde/electron-sandbox .

glyph avatar Jan 11 '18 06:01 glyph

Note that it seems sandboxing require root

Bnaya avatar Feb 09 '18 22:02 Bnaya

Correct me if I'm wrong here, but isn't the preload script the only thing that has access to the filesystem when you turn nodeIntegration: false?

Also knowing that the preload script is the first thing that loads, don't we just need to make sure that the preload script can't be modified in some way by the remote JS? By having fixed IPC events and handlers?

matthewmueller avatar Feb 12 '18 09:02 matthewmueller

update, ahh this is a big problem though:

<html>

<head>
  <title>HaxOr</title>
</head>

<body>
  <script type="text/javascript">
    console.log(window.__nightmare)  
  </script>
</body>

</html>
const Nightmare = require('nightmare')
const nightmare = Nightmare({ show: true })

nightmare.on('console', console.log)

nightmare
  .goto('http://localhost:5000')
  .catch(e => console.error(e))
  .then(() => nightmare.end())

The remote script has access to the window.__nightmare, so I think they could use some of electron's private endpoints. We'll need to lock this down, either with a whitelist or removing window.__nightmare altogether 🔒

matthewmueller avatar Feb 12 '18 09:02 matthewmueller

Removing access to window.__nightmare is a good idea, but my intention with this issue was to track adoption of the actual chrome sandbox. Could you make another issue for this separate security issue?

glyph avatar May 29 '19 22:05 glyph