IIS ARR replace encode slash %2F in query string

Viewed 59

I have an gitlab ce installed on VM Ubuntu-GLS inside the LAN. To give it access from internet am using IIS ARR URL Rewrite module at my primary web server. Gitlab for getting some files from repository via API requires to split catalog with forward slash encoded as %2F. If I sending request to gitlab API like:

curl --header "PRIVATE-TOKEN: <myPrivToken>" "http://gitlab.mysite.com/api/v4/projects/8/repository/files/DemoAM%2F.project?ref=master"

Where is DemoAM is folder in root repository. ARR replaces %2F on forward slash, and gitlab gets request like (i hid some non important fields from gitlab log):

{
  "status": 404,
  "method": "GET",
  "path": "/api/v4/projects/8/repository/files/DemoAM/.project",
  "host": "Ubuntu-GLS",
  "remote_ip": "192.168.0.1:58496, 192.168.0.102, 127.0.0.1"....

where %2F deplaced with /

But if I sending request directly to local VM/ like:

curl --header "PRIVATE-TOKEN: <myPrivToken>" "http://Ubuntu-GLS/api/v4/projects/8/repository/files/DemoAM%2F.project?ref=master"

gitlab gets correct request like:

{
  "status": 200,
  "method": "GET",
  "path": "/api/v4/projects/8/repository/files/DemoAM%2F.project",
  "host": "Ubuntu-GLS",
  "remote_ip": "192.168.0.102, 127.0.0.1".... 

where if %2F provided as is, and it's correct

I've find a very similar question here rewrite urls with slashes ( %2F ) in query string but i can't using it's answer because I can't change gitlab request rules. Also, without result i've tried to set up useOriginalURLEncoding to false as was recommended here: Windows IIS ARR Reverse Proxy Encoding Issue.

So, is the other way(s) to solve this problem? I expect to solution where rest string {R:1} will passthrow as is, without replacing encoded symbols

I use rules like this:

    <rule name="ReverseProxyInboundRule1" enabled="true" stopProcessing="true">
        <match url="(.*)" />
        <conditions logicalGrouping="MatchAny">
            <add input="{CACHE_URL}" pattern="^(https?)://gitlab\.mysite\.com" />
        </conditions>
        <action type="Rewrite" url="{C:1}://Ubuntu-GLS/{R:1}" appendQueryString="true" />
        <serverVariables>
            <set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}" />
            <set name="HTTP_ACCEPT_ENCODING" value="" />
        </serverVariables>
    </rule>
    <outboundRules>
        <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1" enabled="true">
           <match filterByTags="A, Form, Img" pattern="^http(s)?://Ubuntu-GLS/(.*)" />
            <action type="Rewrite" value="http{R:1}://gitlab.mysite.com/{R:2}" />
        </rule>
        <preConditions>
            <preCondition name="ResponseIsHtml1">
                <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
            </preCondition>
            <preCondition name="NeedsRestoringAcceptEncoding">
                <add input="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" pattern=".*" />
            </preCondition>
        </preConditions>
    </outboundRules>
1 Answers

Change

<action type="Rewrite" url="{C:1}://Ubuntu-GLS/{R:1}" appendQueryString="true" />

to

<action type="Rewrite" url="{C:1}://Ubuntu-GLS{UNENCODED_URL}" appendQueryString="false" />

and also change request filtering to allow double escaping.

Reference

https://blogs.iis.net/iisteam/url-rewrite-v2-1

Related