Skip to content

Unexpected/wrong/undocumented behavior when using regex_remap plugin #2877

Closed

Description

@wederbrand

According to the documentation defining something like:
map http://a.com http://b.com @plugin=regex_remap.so @pparam=maps.reg
will redirect to http://b.com if none if the rules in maps.reg matches.

However, I've seen that if we instead of http://b.com/ writes http://b.com/default the word default gets prepended to the string being matched. I would expect the "fall through url" to be totally ignored before matching has been done.

Activity

  1. mlibbey commented on Nov 29, 2017

    @mlibbey
    Contributor

    Can you post the content of maps.reg?

  2. wederbrand commented on Nov 29, 2017

    @wederbrand
    Author

    Sure, it's very simple as I'm just trying to learn ATS. Basically I have ATS running on port 8080 and then I have authentication service running on 8081 and my backend service on 8082

    ^/home/(.*)/climate http://xxx.xxx.xxx.xxx:8082/climate/$1
    ^/home/(.*)/light http://xxx.xxx.xxx.xxx:8082/light/$1
    

    in remap.config I have this (and nothing else)

    regex_map http://.*:8080/ http://xxx.xxx.xxx.xxx:8082/<adding something here breaks it> \
    @plugin=authproxy.so \
     @pparam=--auth-transform=redirect \
     @pparam=--auth-host=xxx.xxx.xxx.xxx \
     @pparam=--auth-port=8081 \
    @plugin=regex_remap.so \
     @pparam=maps.reg \
     @pparam=profile
    
    # authentication service needs to be added without authentication ...
    map http://xxx.xxx.xxx.xxx:8081/ http://xxx.xxx.xxx.xxx:8081/
    
  3. takkitano commented on Jul 17, 2018

    @takkitano
    Contributor

    I think it’s because regex_remap plugin use post remapped path to check regex remap rule.

    In my environment,
    when trafficserver get http request from client,
    first, trafficserver execute first remap plugin’s TSRemapDoRemap function. (in the above configuration, authproxy plugin’s TSRemapDoRemap.)
    Next, trafficserver execute remap operetaion.
    And finally, trafficserver execute regex_remap plugin’s TSRemapDoRemap function.

    Then regex_remap plugin get post remapped url in the following lines.
    https://github.com/apache/trafficserver/blob/master/plugins/regex_remap/regex_remap.cc#L97-L102

    I was faced the same problem.
    I use trafficserver-7.1.4.

    In following setting, trafficserver should forward the request from “http://before-remap.com/” to “http://after-remap.com/index.html”.
    But my trafficserver forward the request from “http://before-remap.com/” to “http://after-remap.com/no-regex/“.

    • remap.config
    map http://before-remap.com/ http://after-remap.com/no-regex/ @plugin=conf_remap.so @pparam=proxy.config.url_remap.pristine_host_hdr=0 @plugin=regex_remap.so @pparam=/opt/trafficserver-7.1.4/etc/trafficserver/test.reg
    
    • /opt/trafficserver-7.1.4/etc/trafficserver/test.reg (regex_remap setting)
    ^/$     http://after-remap.com/index.html
    

    Debug log of “regex_remap” tag is follow.
    I think regex_remap plugin use the post remapped path to check whether the path match with regex remap rule or not.

    (regex_remap) Target match string is `/no-regex/'
    
  4. bryancall commented on May 22, 2019

    @bryancall
    Contributor

    If this is still an issue please reopen.

  5. gtenev commented on May 30, 2019

    @gtenev
    Contributor

    This issue should have been fixed by PR #4964 which implemented what was agreed on the dev mailing list - email thread "[PROPOSAL] Rewrite url after running all remap plugins" which resulted in a new proposal to "rewrite url before all remap plugins". Please reopen if any problems or concerns!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions