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

Add option to allow empty URL schemes #137

Merged
merged 3 commits into from
Jan 13, 2017

Conversation

lukebarnard1
Copy link
Contributor

Set to true by default, this can be set to false to avoid //evil.com/nasty or evil.com/nasty being allowed as hrefs.

Set to true by default, this can be set to false to avoid //evil.com/nasty or evil.com/nasty being allowed as hrefs.
@boutell
Copy link
Member

boutell commented Jan 12, 2017 via email

@lukebarnard1
Copy link
Contributor Author

lukebarnard1 commented Jan 13, 2017

For protocol-relative URLs, I think it would make more sense to have an option to specify what the default scheme is

Sounds like a good idea. When the default scheme has not been provided, should protocol-relative URLs be rejected as nasty? i.e.:

var matches = href.match(/^([a-zA-Z]+)\:/);
if (!matches) {
  // No scheme, "//nasty.domain.co" or "nasty.domain.co"
  if (!options.defaultScheme || typeof options.defaultScheme !== 'string') {
    return false;
  }
  // Match against default scheme
  return href.startsWith(options.defaultScheme);
}

I don't think your second case ( "some.domain.co/nasty" ) is a real thing

Sorry, I should've made it obvious that it's the some.domain.co bit which is the nasty bit.

@boutell
Copy link
Member

boutell commented Jan 13, 2017

On reflection, I think I'm wrong. You don't always know what the scheme will be when you're sanitizing.

Your original patch is the right idea, however you need to actually verify that the URL starts with // before treating it as protocol-relative. It looks like your code would assume all relative URLs are protocol-relative URLs.

@lukebarnard1
Copy link
Contributor Author

Would it not be best to also have an option to [dis]allow the protocol-less some.evil.com? Most browsers would allow no "//" to be treated as an implicit "//".

@boutell
Copy link
Member

boutell commented Jan 13, 2017 via email

@lukebarnard1
Copy link
Contributor Author

lukebarnard1 commented Jan 13, 2017

Ah. My mistake. I shall update the comment!

I guess it should also return false if there is no scheme?

@boutell boutell merged commit e22f2e2 into apostrophecms:master Jan 13, 2017
@boutell
Copy link
Member

boutell commented Jan 13, 2017

This has been published to npm after reversing that if statement (naughtyHref returns true for bad things, not happy things). Thanks!

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

Successfully merging this pull request may close these issues.

2 participants