How exactly do you configure httpOnly Cookies in ASP Classic? - security

I'm looking to implement httpOnly in my legacy ASP classic sites.
Anyone knows how to do it?

If you run your Classic ASP web pages on IIS 7/7.5, then you can use the IIS URL Rewrite module to write a rule to make your cookies HTTPOnly.
Paste the following into the section of your web.config:
<rewrite>
<outboundRules>
<rule name="Add HttpOnly" preCondition="No HttpOnly">
<match serverVariable="RESPONSE_Set_Cookie" pattern=".*" negate="false" />
<action type="Rewrite" value="{R:0}; HttpOnly" />
<conditions>
</conditions>
</rule>
<preConditions>
<preCondition name="No HttpOnly">
<add input="{RESPONSE_Set_Cookie}" pattern="." />
<add input="{RESPONSE_Set_Cookie}" pattern="; HttpOnly" negate="true" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
See here for the details: http://forums.iis.net/t/1168473.aspx/1/10
For background, HTTPOnly cookies are required for PCI compliance reasons. The PCI standards folks (for credit card security) make you have HTTPOnly on your sessionID cookies at the very least in order to help prevent XSS attacks.
Also, at the current time (2-11-2013), all major browser support the HTTPOnly restriction on cookies. This includes current versions of IE, Firefox, Chrome and Safari.
See here for more info on how this works and support by various browser versions:
https://www.owasp.org/index.php/HTTPOnly

Response.AddHeader "Set-Cookie", "mycookie=yo; HttpOnly"
Other options like expires, path and secure can be also added in this way. I don't know of any magical way to change your whole cookies collection, but I could be wrong about that.

You need to append ";HttpOnly" to the Response cookies collection.

Response.AddHeader "Set-Cookie", ""&CStr(Request.ServerVariables("HTTP_COOKIE"))&";path=/;HttpOnly"&""

If you are using IIS7 or IIS7.5 and install the URL Rewriting add-in then you can do this. You can create a rewriting rule that adds "HttpOnly" to any out going "Set-Cookie" headers. Paste the following into the <system.webServer> section of your web.config. I then used Fiddler to prove the output.
Regards, Jeremy
<rewrite>
<outboundRules>
<rule name="Add HttpOnly" preCondition="No HttpOnly">
<match serverVariable="RESPONSE_Set_Cookie" pattern=".*" negate="false" />
<action type="Rewrite" value="{R:0}; HttpOnly" />
<conditions>
</conditions>
</rule>
<preConditions>
<preCondition name="No HttpOnly">
<add input="{RESPONSE_Set_Cookie}" pattern="." />
<add input="{RESPONSE_Set_Cookie}" pattern="; HttpOnly" negate="true" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>

HttpOnly does very little to improve the security of web applications. For one thing, it only works in IE (Firefox "supports" it, but still discloses cookies to Javascript in some situations). For another thing, it only prevents a "drive-by" attack against your application; it does nothing to keep a cross-site scripting attack from resetting passwords, changing email addresses, or placing orders.
Should you use it? Sure. It's not going to hurt you. But there are 10 things you should be sure you're doing before you start messing with HttpOnly.

Related

Url rewriting/routing on .Net Core with IIS and Cloudflare

A small introduction about the app's deployment & app in general:
We use .Net Core 6 MVC and is hosted in IIS. Additionally the application uses a domain which the actual website is hosted e.g. www.ExampleHost.com/ExampleApp.
Also we use Cloudflare to direct requests to a new domain for the website e.g. www.ExampleHost.com/ExampleApp -> www.Example-App.eu
Here is the problem, while the app works fine at www.ExampleHost.com/ExampleApp, if we enter www.Example-App.eu the directory of the app appears in the Url like www.Example-App.eu/ExampleApp in every request. That creates problem everywhere from returning Views to submitting Forms etc.
So an idea was to solve part of this problem by creating a web.config to configure URL Rewrite rules.
web.config
<rewrite>
<rules>
<rule name="RemoveExampleApp">
<match url=".*ExampleApp/(.*)" />
<conditions>
<add input="{REQUEST_METHOD}" matchType="Pattern" pattern="POST" ignoreCase="true" negate="true" />
</conditions>
<action type="Redirect" url="{R:1}"/>
</rule>
<rule name="RemoveExampleAppPost">
<match url=".*ExampleApp/(.*)" />
<conditions>
<add input="{REQUEST_METHOD}" matchType="Pattern" pattern="POST" ignoreCase="true" />
</conditions>
<action type="Rewrite" url="{R:1}" />
</rule>
</rules>
</rewrite>
But we still unable to perform POST requests.
Additionally, I read to another Stack Overflow post that it is possible to configure/fix that by of using routing instead of rewrite rules but we had no luck with that.
IIS URL Rewrite and .NET Core
We are open to any suggestions.
Thanks for your time.

IIS handling url requests for multiple applications within same webstie

This is definitely out of my area of expertise so I hope I explain this well. We have a website and within that website we have 2 different applications with 2 different login pages. What would I have to do so that for example requests for app1.website.com and app2.website.com get's routed to the correct apps login page?
WebServer Screenshot
you could try this rule:
<rule name="app1 redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="app1.website.com" />
</conditions>
<action type="Rewrite" url="http://website.com/react1/app1/" logRewrittenUrl="true"/>
</rule>

IIS7 URL Rewrite to router webadmin from child of default website

The Mission:
To access my home router's web admin site through my main website on my home server via IIS URL Rewrite/ARR. So instead of typing in http://192.168../index.cgi to get to my router, I can go to my home site http://example.com/index.html and then click on a link to go to http://example.com/router1/index.cgi.
The Journey
So far I have been able to redirect and rewrite in a number of ways. However, success only comes when I don't use a "sub-folder" in the URL. I have found that this is due to the router's website utilizing root relative links. I have tried with little success to write some outbound rules to get around this. When I use a little regex to strip that first forward slash like this
(replaces equals sign, double or single quotation mark, and a forward slash with equals and quote)
<outboundRules>
<rule name="gallifrey-out" preCondition="IsHTML">
<match filterByTags="None" customTags="" pattern="=(\"|\')\/" />
<action type="Rewrite" value="={R:1}" />
</rule>
<preConditions>
<remove name="IsHTML" />
<preCondition name="IsHTML">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
all the images appear correctly, but the links to pages are still missing the "router1" subfolder portion and therefore throw a 404 (not found) error.
I had read somewhere that the base tag would solve this. Seeing how there was no base tag for URL Rewrite to find and rewrite, I tried injecting it into the page via the style tag like so
<outboundRules>
<rule name="gallifrey-out" preCondition="IsHTML" stopProcessing="true">
<match filterByTags="CustomTags" customTags="baseInject" pattern="(.*)" />
<action type="Rewrite" value="text/css"></style><base href="http://example.com/router1/images"><style type="text/css" />
</rule>
<preConditions>
<remove name="IsHTML" />
<preCondition name="IsHTML">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
<customTags>
<tags name="baseInject">
<tag name="style" attribute="type" />
</tags>
</customTags>
</outboundRules>
Sadly this didn't work either, like .... not at all. It did inject though, here's a look at the source
Source code screenshot
Over the past few days I have looked at a ton of sites and videos on how to accomplish this. And while I have learned a lot in the process, I still can't get this done. Everyone else seem to have different way to go about it. Eventually I will go live with this on the main server and will need access to it outside my home which means the way the page is rendered to the client needs to be route-able from the public network.
Test Bench:
An extremely old Sony VIAO laptop running Win7 Ultimate with IIS7
ActionTec MI424WR rev i with Verizon/Frontier firmware
The Don't Wannas:
Don't want to open yet another port to the public on the router
Don't want to purchase yet another domain name
Don't want to purchase a wildcard SSL cert (only a single)
The Big Question
Does anyone have any idea on how to work around root-relative hyperlinks when redirecting with url rewrite?

IIS URLrewrite: How to preserve original host name for internal redirects?

I have a web application running on one server and use IIS with rewriteURL on another server as a reverse proxy.
I configured the incoming rules to rewrite the reverse proxy address with the address of the web application server. This works fine.
However, the application allows users to download some content and redirects them to the download address. Right now, users get forwarded to the local IP address of the web application server, not the public address of the reverse proxy.
I understand, I need to edit the outbounding rules as well to catch this, but I somehow don't get it right.
I followed the instructions here
https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/modifying-http-response-headers
and my current rewrite rules look like this
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="er-platform" stopProcessing="true">
<match url="^er-platform(.*)" />
<conditions>
<add input="{CACHE_URL}" pattern="^(https?)://" />
</conditions>
<action type="Rewrite" url="{C:1}://192.168.80.6:8443/{R:0}" />
<serverVariables>
<set name="ORIGINAL_HOST" value="{HTTP_HOST}" />
</serverVariables>
</rule>
</rules>
<outboundRules>
<rule name="er-platform" preCondition="IsRedirection" enabled="true">
<match serverVariable="RESPONSE_LOCATION" pattern="^(https?)://[^/]+/(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{ORIGINAL_HOST}" pattern=".+" />
</conditions>
<action type="Rewrite" value="{R:1}://{ORIGINAL_HOST}/{R:2}" />
</rule>
<preConditions>
<preCondition name="IsRedirection">
<add input="{RESPONSE_STATUS}" pattern="3\d\d" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
</system.webServer>
</configuration>
I still get redirected to the local IP when trying to download something.
How do I need to change the rules to get this right?
Thanks,
Thomas
I don't think your outbound rule is incorrect. I have a couple of guesses for why it is failing.
First: Your inbound rule must match for your outbound rule to work. This is because ORIGINAL_HOST is captured when the inbound rule executes. Right now, your inbound rule is match the URL against ^er-platform(.*). I am going to assume that since this is a reverse proxy, that it is working because you wouldn't be able to start the download if it wasn't.
Second: The output rule only triggers on a 3xx code. This isn't the only way to redirect though. It's possible that you're redirecting using JavaScript. E.g. `window.location = 'http://wrongaddress'. In which case your outbound rule wouldn't work.
Next steps for debugging this:
Turn on Logging for the inbound rule.
Your logs will be written to %SystemDrive%\inetpub\logs\LogFiles\. Verify the inbound rule is being hit.
Verify what's happening on the wire:
Fiddler is a great tool for understanding what's actually happening on the wire. Use this to confirm that the URL rewrite rules should be hitting. I.e. that the request URL matches ^er-platform(.*) and that the response code is in the 300s.
Alternatively to Fiddler you could just get away with using Chrome Developer Tools Network tab. Turn on the 'Preserve log' checkbox so that it doesn't clear after you've been redirected. Verify what you think should be happening is actually happening.

IIS rule rewrite for query string

I have a URL that looks like
https://thesite.com/m/?pageName=profileSettings#notifications
I need to rewrite it to
https://thesite.com/m/?pageName=notificationSettings
I'm trying something like
<rule name="m_notifications" stopProcessing="true">
<match url="^m/(.*)" />
<conditions>
<add input="{QUERY_STRING}" pattern="pageName=profileSettings#notifications" />
</conditions>
<action type="Rewrite" url="pageName=notificationSettings" appendQueryString="False"/>
</rule>
This isn't working, no errors, just not making any changes. What am I missing?
Thanks
It is not possible to do a rewrite based on the hash string. Browser doesn't transmit the part after hash to the server.
It's called Fragment identifier and is client side only. It's not possible in any language unless you are using some browser implementation (or software) which would send that part of URL to the server.

Resources