ember-ajax icon indicating copy to clipboard operation
ember-ajax copied to clipboard

trustedHosts checks for hostname match instead of host

Open makepanic opened this issue 9 years ago • 5 comments

I don't know if this is a bug, but the trustedHosts filter checks for a urls hostname instead of its host. ( https://github.com/ember-cli/ember-ajax/blob/master/addon/mixins/ajax-request.js#L355 )

This results in valid hosts not being accepted, because the hosts port isn't matched:

20160511-130558

If it's a bug, I can open a PR to change the behavior (maybe resulting in a breaking change?). One way would be to simply rename trustedHosts to trustedHostnames which describes the given hostname check. Alternatively change it to check the urls host.

makepanic avatar May 11 '16 12:05 makepanic

Thanks for catching this! I don't think it was intentional. I would imagine that most people wouldn't provide the host in the whitelist, but then again, I'm not sure that we want to assume that just because one port is valid, all of them are...

What if compare by host and port, and add an implicit port 80 to items in the whitelist that don't provide one? If we're always using host and port, we're always comparing apples to apples and since 80 is the implicit default, we can use that fact to add the port if we need to just for the comparison.

alexlafroscia avatar May 13 '16 22:05 alexlafroscia

Sounds like a good way to solve this issue. Should I try to implement it? (Would the best way to change this, to pass the RequestUrl object to the _matchHosts(host, matcher) and simply compare its hostname + port field?)

makepanic avatar May 15 '16 16:05 makepanic

If you'd like to, that would be great! I think that sounds like a good approach; just make sure to add some testing to make sure that it handles the implicit port numbers correctly!

alexlafroscia avatar May 15 '16 20:05 alexlafroscia

Should the implicit port only work with trusted hosts in string format? I'm not sure if we should modify a given regex.

makepanic avatar May 17 '16 20:05 makepanic

What do you mean? Can you provide an example?

alexlafroscia avatar May 21 '16 23:05 alexlafroscia