-
Notifications
You must be signed in to change notification settings - Fork 179
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
refactor: server host filtering #1174
Conversation
Cleans up the host filtering by allowing `ipv6 addresses`, fixes a bug when host filtering with `*` is configured when a request is missing the default port. In addition the API on the server is stricter and hosts filtering with invalid authorities are now rejected which wasn't the case before.
let uri: Uri = s.parse().map_err(|e: InvalidUri| e.to_string())?; | ||
let authority = uri.authority().ok_or_else(|| "HTTP Host must contain authority".to_owned())?; | ||
let hostname = authority.host(); | ||
let maybe_port = &authority.as_str()[hostname.len()..]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah; can't do authority.port()
because port may bve eg *
I guess!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes and also http::Uri::port
won't tell us whether it has a default port or not as well, so we need to do some manual stuff here.
so a little bit hacky but this was cleanest I could come up with
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of small nits but looks cleaner to me :)
server/src/server.rs
Outdated
/// Enables host filtering and allow only the specified hosts. | ||
/// | ||
/// Default: allow all. | ||
pub fn host_filter<T: IntoIterator<Item = Authority>>(mut self, allow_only: T) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to copy my element comment:
It could accept anything that can TryFrom
into the Authority
type and then it'd have to return the error when host_filter
is called if there is one. Prolly a bit nicer cos then you can just do
.host_filter([
"foo.com",
"something_else.com:*"
])?
for instance which would be quite cool.
(I think it should return an AuthorityError
enum if the conversion fails personally rather than a String
)
Cleans up the host filtering by supporting
ipv6 addresses
, fixes a bug when host filtering with*
is configured when a request is missing the default port.In addition the API on the server is stricter and hosts filtering with invalid authorities are now rejected which wasn't the case before.
Close #1075