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

Protocol Path Sanitisation #149

Open
jmannau opened this issue Apr 17, 2024 · 0 comments
Open

Protocol Path Sanitisation #149

jmannau opened this issue Apr 17, 2024 · 0 comments

Comments

@jmannau
Copy link

jmannau commented Apr 17, 2024

In regards to securely handling custom protocols, the electron docs suggest preventing relative path traversal (https://www.electronjs.org/docs/latest/api/protocol#protocolhandlescheme-handler)

// NB, this checks for paths that escape the bundle, e.g.
// app://bundle/../../secret_file.txt
const pathToServe = path.resolve(__dirname, pathname)
const relativePath = path.relative(__dirname, pathToServe)
const isSafe = relativePath && !relativePath.startsWith('..') && !path.isAbsolute(relativePath)
if (!isSafe) {
  return new Response('bad', {
    status: 400,
    headers: { 'content-type': 'text/html' }
  })
}

return net.fetch(pathToFileURL(pathToServe).toString())

How does this compare to the current protocol handler https://github.com/reZach/secure-electron-template/blob/master/app/electron/protocol.js

Is there benefit to one over? I am happy to make a PR to add comments explaining the benefits or to consolidate on the the preferred option.

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

1 participant