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

Issue #8329 - support wildcards in proxy exclusion hosts #10538

Open
wants to merge 3 commits into
base: jetty-10.0.x
Choose a base branch
from

Conversation

sugilite
Copy link

@sugilite sugilite commented Sep 17, 2023

Proxy configuration: Allow for "*" wildcard at the start and the end of excluded hosts.

Signed-off-by: Lukas Gisi <lukasgisi@gmail.com>
Comment on lines 222 to 226
HostPort hostPort = new HostPort(pattern);
String host = hostPort.getHost();
int port = hostPort.getPort();
String hostRegex = extractHostRegex(host);
return Pattern.matches(hostRegex, address.getHost()) && (port <= 0 || port == address.getPort());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is getting to be an expensive check to do on every request, as it will be parsing the HostPort and compiling the regex itself. Both of these operations should be able to be done in advance rather than on every call to matches.

This really should be a specialized Set for use with IncludeExcludeSet. See InetAccessHandler for an example (albeit not a great one) of how this should be done.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedback and your hints. I checked out InetAccessHandler and InetAddressSet.

Can we sensibly achieve this without breaking the current API?

Some thoughts:
At the moment clients use the HashSet<String> returned by getExcludedAddresses() directly and add (or remove) proxy exclusions by directly adding Strings to this set.
I briefly thought about instead of returning a HashSet in getExcludedAddresses we return our own class (extension of HashSet) which proxies all the add/remove operations and holds an internal set with all the Patterns (or Matchers) - this obviously has it's own problems and is most likely a pretty bad approach.

For now I added two commits: First commit which adds a HashMap to cache the Patterns for a given regex string, second one to do the same for the HostPorts.
This is not perfect at all: these maps only grow and never shrink. But I also don't think (hope) that people use thousands of included and excluded addresses. (If we would use a local HashMap as a cache in my day to day job we would use guave CacheBuilder or the newer caffeine which lets us set a max size or expiration time for entries - are there some helpers in jetty which I can use here?)

I need some more time to figure out how to best use IncludeExcludeSet here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sugilite I'll have a think too about how we can avoid breaking the current API too badly. For now I've moved this to our next release cycle for consideration

…r same hosts

Signed-off-by: Lukas Gisi <lukasgisi@gmail.com>
… patterns

Signed-off-by: Lukas Gisi <lukasgisi@gmail.com>
@joakime joakime requested a review from gregw October 27, 2023 01:30
Copy link
Contributor

@gregw gregw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is better, but:

  • it still does not use the IncludeExclude mechanism
  • It allows wild cards on exclude but not include
  • It should use the existing InetAddressPattern class (which may need to be enhanced?)

Ultimately it should be really similar to InetAccessHandler.

@joakime do you have time to help @sugilite get this PR ready this cycle?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

Why there is no Regex Support for excludeList of nonProxyHost
3 participants