Azure / iisnode

Hosting node.js applications in IIS on Windows
Other
667 stars 101 forks source link

Url received in node was decoded #104

Open iskiselev opened 3 years ago

iskiselev commented 3 years ago

When request is transferred from IIS to Node, it is decoded. I do request to http://.../%24%3A%2Fcore%2Ftemplates%2Ftiddlywiki5.js.

I got next application output when it is executed on node natively:

Request path: {"protocol":null,"slashes":null,"auth":null,"host":null,"port":null,"hostname":null,"hash":null,"search":null,"query":null,"pathname":"/$:/core/templates/tiddlywiki5.js","path":"/$:/core/templates/tiddlywiki5.js","href":"/$:/core/templates/tiddlywiki5.js"}
Request headers: {"host":"localhost:8080","connection":"keep-alive","sec-ch-ua":"\"Google Chrome\";v=\"87\", \" Not;A Brand\";v=\"99\", \"Chromium\";v=\"87\"","sec-ch-ua-mobile":"?0","upgrade-insecure-requests":"1","user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36","accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9","sec-fetch-site":"none","sec-fetch-mode":"navigate","sec-fetch-user":"?1","sec-fetch-dest":"document","accept-encoding":"gzip, deflate, br","accept-language":"en-US,en;q=0.9,ru-RU;q=0.8,ru;q=0.7","cookie":"__test=1"}

When I run similar in Azure App Service with IISNode I got next output:

Request path: {"protocol":null,"slashes":null,"auth":null,"host":null,"port":null,"hostname":null,"hash":null,"search":null,"query":null,"pathname":"/$:/core/templates/tiddlywiki5.js","path":"/$:/core/templates/tiddlywiki5.js","href":"/$:/core/templates/tiddlywiki5.js"}
Request headers: {"cache-control":"max-age=0","connection":"keep-alive","content-length":"0","accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9","accept-encoding":"gzip, deflate, br","accept-language":"en-US,en;q=0.9,ru-RU;q=0.8,ru;q=0.7","cookie":"ARRAffinity=f5ecfb306e60620010bb76308e041dc8ca96ba5fca7967d574bfef606d2482e1; ARRAffinitySameSite=f5ecfb306e60620010bb76308e041dc8ca96ba5fca7967d574bfef606d2482e1","host":"iktestwin.azurewebsites.net","max-forwards":"10","user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36","sec-ch-ua":"\"Google Chrome\";v=\"87\", \" Not;A Brand\";v=\"99\", \"Chromium\";v=\"87\"","sec-ch-ua-mobile":"?0","upgrade-insecure-requests":"1","sec-fetch-site":"cross-site","sec-fetch-mode":"navigate","sec-fetch-user":"?1","sec-fetch-dest":"document","x-waws-unencoded-url":"/%24%3A%2Fcore%2Ftemplates%2Ftiddlywiki5.js","client-ip":"73.151.39.176:52385","x-arr-log-id":"08f6dc36-26ff-421c-9760-7662f93aef65","disguised-host":"iktestwin.azurewebsites.net","x-site-deployment-id":"iktestwin","was-default-hostname":"iktestwin.azurewebsites.net","x-original-url":"/$:/core/templates/tiddlywiki5.js","x-forwarded-for":"73.151.39.176:52385","x-arr-ssl":"2048|256|C=US, O=Microsoft Corporation, CN=Microsoft RSA TLS CA 01|CN=*.azurewebsites.net","x-forwarded-proto":"https","x-appservice-proto":"https","x-forwarded-tlsversion":"1.2"}
authenticatedUsername: undefined

So, instead of original request, I got request to: /$:/core/templates/tiddlywiki5.js

iskiselev commented 3 years ago

Issue is duplicate of tjanczuk/iisnode#217. PR that should solve it (tjanczuk/iisnode#486) still not merged. Workaround suggested in https://github.com/tjanczuk/iisnode/issues/217#issuecomment-206953773 works perfectly.

To modify applicationhost.config in azure next applicatiohost.xdt can be used:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <configSections>
      <sectionGroup name="system.webServer" xdt:Locator="Match(name)">
        <sectionGroup name="rewrite" xdt:Locator="Match(name)">
          <section name="allowedServerVariables" overrideModeDefault="Allow" xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
        </sectionGroup>
      </sectionGroup>
  </configSections>
  <system.webServer>
    <rewrite>
      <allowedServerVariables>
        <add name="HTTP_X_ORIGINAL_URL" xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)" />
      </allowedServerVariables>
    </rewrite>
</system.webServer>
</configuration>