Skip to content

Commit 466fe81

Browse files
anderskMarshallOfSound
authored andcommitted
docs: security.md: Fix navigation lockdown example code (electron#14185)
The `url` module is not a constructor; change `require('url')` to `require('url').URL`. Also, check the entire origin rather than just the hostname, since otherwise `http://my-own-server.com` is allowed in addition to `https://my-own-server.com`, in violation of point 1 (only load secure content). Signed-off-by: Anders Kaseorg <andersk@mit.edu>
1 parent dbee03d commit 466fe81

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

docs/tutorial/security.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,13 +612,13 @@ sometimes be fooled - a `startsWith('https://google.com')` test would let
612612
`https://google.com.attacker.com` through.
613613

614614
```js
615-
const URL = require('url')
615+
const URL = require('url').URL
616616

617617
app.on('web-contents-created', (event, contents) => {
618618
contents.on('will-navigate', (event, navigationUrl) => {
619619
const parsedUrl = new URL(navigationUrl)
620620

621-
if (parsedUrl.hostname !== 'my-own-server.com') {
621+
if (parsedUrl.origin !== 'https://my-own-server.com') {
622622
event.preventDefault()
623623
}
624624
})

0 commit comments

Comments
 (0)