[rt-devel] ReferrerWhitelist wildcard domain matching

Thomas Sibley trs at bestpractical.com
Thu Jul 12 13:41:23 EDT 2012


On 07/11/2012 09:25 PM, Matt Tyson wrote:
> I've attached a patch against RT to do simple wildcard matching against
> domain names for the ReferrerWhitelist.  This is to avoid having to
> enter a domain and all of its subdomains manually.
> 
> EG
>     domain.com:80
> foo.domain.com:80
> bar.domain.com:80
> baz.domain.com:80
> 
> could be entered as
> 
> *.domain.com:80
> 
> Does anyone have any interest in this or any feedback?

RT should support this syntax, yes.

The patch is not very Perlish.  It looks like C.  ;)  A quick, untested rewrite:

my $host_port = $referer->host_port;
if ($config =~ /\*/) {
    # Make *.example.com match example.com
    return 1 if $config eq "*.$host_port";

    # turn literal * into a non-greedy subdomain match
    my $regex = join '\.',
                 map { $_ eq '*' ? '[a-zA-Z0-9\-]+?' : quotemeta($_) }
               split /\./, $config;

    return 1 if $host_port =~ /^$regex$/;
} else {
    return 1 if $host_port eq $config;
}

Functional differences:

*.example.com shouldn't match foo.bar.example.com (see also how SSL cert CNs match)
foo.*.example.com shouldn't match foo..example.com (replaced * with +)
*.example.com shouldn't match #.example.com (replaced . with [a-zA-Z0-9\-])

Thomas


More information about the rt-devel mailing list