Skip to content
This repository has been archived by the owner on Apr 4, 2019. It is now read-only.

Add hook for extracting protocol from URLs #273

Merged
merged 2 commits into from
Jan 31, 2015
Merged

Conversation

tomdale
Copy link
Collaborator

@tomdale tomdale commented Jan 30, 2015

In order to sanitize potentially dangerous URLs that contain executable
behavior (e.g. “javascript:” URLs), we need to determine the protocol.

Unfortunately, URL parsing is notoriously error-prone, so we want to use
the host environment’s native functionality such that the protocol we
report is the same as what it will act upon.

In this case, we expose a protocolForURL hook that uses a generated
<a> element to set its href and check the resulting protocol. A
Node.js implementation could fall back to using the url package that
is included in the standard library.

In order to sanitize potentially dangerous URLs that contain executable
behavior (e.g. “javascript:” URLs), we need to determine the protocol.

Unfortunately, URL parsing is notoriously error-prone, so we want to use
the host environment’s native functionality such that the protocol we
report is the same as what it will act upon.

In this case, we expose a `protocolForURL` hook that uses a generated
`<a>` element to set its `href` and check the resulting `protocol`. A
Node.js implementation could fall back to using the `url` package that
is included in the standard library.
tomdale added a commit that referenced this pull request Jan 31, 2015
Add hook for extracting protocol from URLs
@tomdale tomdale merged commit db589d9 into master Jan 31, 2015
@tomdale tomdale deleted the protocol-for-url branch January 31, 2015 00:13
@mmun
Copy link
Collaborator

mmun commented Jan 31, 2015

👍

@rwjblue
Copy link
Collaborator

rwjblue commented Jan 31, 2015

Will release shortly.

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

Successfully merging this pull request may close these issues.

3 participants