Skip to content

feature request: have a wildcard domain matcher #645

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

Closed
GlenDC opened this issue Apr 2, 2025 · 7 comments
Closed

feature request: have a wildcard domain matcher #645

GlenDC opened this issue Apr 2, 2025 · 7 comments
Milestone

Comments

@GlenDC
Copy link
Contributor

GlenDC commented Apr 2, 2025

Currently, the domain matchers (e.g., used in route_upstream) support only child_match and exact_match. However, there’s no support for wildcard matching. For example, something like:

foo*.site.bar.com

would ideally match:

foo.site.bar.com  
foo1.site.bar.com  
foofoo.site.bar.com

The exact syntax or feature set isn’t particularly important to me—what matters more is having the capability to perform wildcard-based filtering, especially in cases where exact_match or child_match aren’t sufficient.

I understand that wildcard matching may be slower by nature, but I still believe it could be quite useful for certain edge cases.

@zh-jq-b
Copy link
Member

zh-jq-b commented Apr 3, 2025

Yes it would be useful. It can use a radix_trie::Trie<u8, ArcEscaper> to do the match check. Can you submit a PR?

@GlenDC
Copy link
Contributor Author

GlenDC commented Apr 3, 2025

At the moment, I’m unfortunately swamped. If you haven’t had a chance to get to it by the time I need it, I’ll definitely take care of it myself.

That said, could you elaborate a bit more on how exactly you envision this? Your proposal still leaves quite a bit of room for interpretation, and I’d like to make sure we’re aligned before moving forward.

@zh-jq-b
Copy link
Member

zh-jq-b commented Apr 3, 2025

The wildcard_match code would be much like the child_match code, the difference is:

child_match insert example.net as net.example. to a Trie<String, ArcEscaper>,
wildcard_match insert a*.example.net as net.example.a to a Trie<String, ArcEscaper>.

*.example.net seems to be a special case as it should match both example.net and a.example.net.

@zh-jq-b zh-jq-b added this to the g3proxy v1.12 milestone Apr 3, 2025
@zh-jq
Copy link
Collaborator

zh-jq commented Apr 13, 2025

I have added 'regex match' support in this PR #667. I think this can be used to do a wildcard match.

@GlenDC
Copy link
Contributor Author

GlenDC commented Apr 14, 2025

Seems to work. However

let prefix = domain.split_at(domain.len() - prefix_len).0;
currently can panic in case prefix length is larger than domain length.

Example regex used in escaper that can trigger it:

regex_match:
  - next: forward-protoparser
    rules:
      - parent: foobar.com
        regex: abcdfoobaserver-dk\.clients\d+

output:

thread 'main#13' panicked at g3proxy/src/config/escaper/route_upstream/regex_match.rs:207:46:
attempt to subtract with overflow

That said it does work and the regex correctly uses the "next" escaper.

@zh-jq
Copy link
Collaborator

zh-jq commented Apr 14, 2025

the panic will be fixed by #671

@GlenDC
Copy link
Contributor Author

GlenDC commented Apr 14, 2025

Panic seems to be fixed indeed. I'm okay with closing this issue as done, as it seems to be implemented correctly as far as I can see?

@zh-jq zh-jq closed this as completed Apr 15, 2025
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

No branches or pull requests

3 participants