# symbol in path of file in IIS - iis

I have many folders in Virtual Directory, many of them have # in theirs name,
when something like this be requested from IIS, it will return 404 error,
folder name is John^Rezaei^^#SM 183217 and it seems it be separated in LOG file like:
2019-08-11 10:29:31 ::1 GET /web/virtuald/Study/John^Rezaei^^ - 80 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/75.0.3770.142+Safari/537.36 - 302 0 0 690
from # to end is ignored, mean /web/virtuald/Study/John^Rezaei^^ requested not /web/virtuald/Study/John^Rezaei^^#SM 183217/im00001.jpg.
even by adding below config nothing changed:
<system.webServer>
<security>
<requestFiltering allowDoubleEscaping="true">
</requestFiltering>
</security>

As far as I know, the # is the special character in the url part. The data behind the # will be regards as the querystring.
So you should use %23 to replace the "#".
So the url for the vitual path, you should use is John%5ERezaei%5E%5E%23SM%20183217.
More detals, you could refer to below image:

Related

Options +Indexes of .htaccess not working

I have a website running on a server. It's just an index.html with a hello world text. Also, I have a folder named /vpn which contains various txt files and an index.html file.
If I try to access the URL domain/vpn, it shows me the content of index.html.
I just need to show the files inside the folder vpn when the user tries to access domain/vpn.
I created an .htaccess file with the next content in the root:
RewriteEngine on
<If "%{REQUEST_URI} == '/vpn/'">
DirectoryIndex disabled
Options +Indexes
</If>
When I try to access to vpn, it shows me a 404 error, the requested URL was not found on this server.
.htaccess is applying the DirectoryIndex rule (If a delete it, it shows me index.html content again), but not the Options +Indexes one.
I tried the same example in localhost (with XAMPP) and it's working fine.
What can be the problem?
PD: This is the content of apache2.conf file:
When I try to acces to vpn, it shows me a 404 error, the requested URL was not found on this server.
If you are getting a "404 Not Found" then it would imply that mod_autoindex is not actually installed on your server (consequently Options +Indexes has no effect - although it would seem from your server config that Indexes is perhaps already enabled).
mod_autoindex is the module responsible for generating the directory listings.
I created an .htaccess file with the next content in the root:
Personally, I would create an additional .htaccess file in the /vpn directory instead:
DirectoryIndex disabled
Options +Indexes
And disable Indexes (and set DirectoryIndex) in the root .htaccess file.
NB: RewriteEngine has no place here, unless you are overriding a parent config.
If I try to access the url "domain/vpn"
Note that you should be requesting domain/vpn/ (with a trailing slash). If you omit the trailing slash then mod_dir issues a 301 redirect to append it.

Coldfusion page executed twice

Hi I am having a strange problem. On our development server coldfusion pages are executed twice. This happens everytime. To find out what is causing this issue, I send an email containing the request details to myself like this:
<Cfmail from="*" to="*" type="html">
<cfdump var=#GetHttpRequestData()#>
#gettickcount()#
#createUUID()#
</cfmail>
I get the following response when calling a page containing .cfm:
content [empty string]
headers struct
TOMCATCGIHTTPURL000000006A6B0000 /test.cfm
accept */*
content-length 0
host *
user-agent curl/7.40.0
method GET
protocol HTTP/1.1
1590760731452
C7487929-D679-B029-6E236DEE7E19B8EB
and a second mail containing
content [empty string]
headers struct
X-Original-URL /test.cfm
accept */*
content-length 0
host *
user-agent curl/7.40.0
method GET
protocol HTTP/1.1
1590760731425
C7487814-FA6F-4699-182C2E7382A06A47
Now the really strange part. When i call an index.cfm without the filename like / the page is only executed once. For example calling a page located on /test/index.cfm as /test/ returns as single response:
content [empty string]
headers struct
X-Original-URL /test/
accept */*
content-length 0
host *
user-agent curl/7.40.0
method GET
protocol HTTP/1.1
1590762636945
C86B3A74-025F-6DBA-EA187DFEF7751F03
Details of environment: Windows 2016 server, IIS 10, Coldfusion 2016
Any thoughts on what is causing this issue.
UPDATE
I use rewrite rules. I tested disabling the rewrite rules (as suggested by Miguel-F) and then the page is executed only once. When adding a simple rewrite rule like this the page is executed twice:
<rule name="Test rule" stopProcessing="true">
<match url="^(.*)$" />
<action type="Rewrite" url="/{R:1}" appendQueryString="true" />
</rule>
This behavior only occurs on our development server. Our production server has none of these issues and also runs on windows 2016 IIS 10 and coldfusion 2016.
Coldfusion version for development server: 2016.0.13.316217 (Production server runs on exactly the same version and has no issues)
This is not really an answer, but a really long comment.
You need to find out if this is one request or two. Add in some code like this:
<cfparam name="request.count" default="0">
<cfset request.count++>
<Cfmail from="*" to="*" type="html">
<cfdump var=#GetHttpRequestData()#>
Request.count: #request.count#
<br />
#gettickcount()#
#createUUID()#
</cfmail>
If the file was requested twice, each email will say 1
If the file is being included somehow, then then second email will say the request count is 2

IIS URL Rewrite and ARR don't handle rewrite rule properly

I have a problem with some understanding of how the URL Rewrite and ARR work together. I have a site and a standalone service that generates and provides updated sitemaps for the site. Below is my rule to handle sitemap requests. It is a local rule in the web.config under sites directory (the site is hosted under IIS 10).
<rule name="Sitemap Rule" stopProcessing="true">
<match url="^sitemap.*" />
<action type="Rewrite" url="http://sitemap.mysitedomain/provider?key={R:0}" logRewrittenUrl="true" />
</rule>
All looks good but it doesn't work. The only response I've got is 404. I should note that the ARR module is active and it properly handles other proxy requests.
To be transparent on this rule imagine that some web-robot request http://mysitedomain/sitemap.xml and the real request will be served from the http://sitemap.mysitedomain/provider?key=sitemap.xml where sitemap.mysitedomain is hosted on different servers and different environment.
The strange things here is that if I put empty sitemap.xml to the root of mysitedomain all my requests to the sitemap.xml start working as expected and I started to get updated sitemap.xml from sitemap service and an empty one that I've placed to the root of the site.
Added some tracing info from failed request
For the failed requests I have next in the tracing file
...
ModuleName RewriteModule
HeaderName X-Original-URL
HeaderValue /sitemap.xml
Replace true
OldUrl /sitemap.xml
NewUrl http://sitemap.mysitedomain/v1/sitemap/provider?key=sitemap.xml
...
ModuleName ApplicationRequestRouting
Notification MAP_REQUEST_HANDLER
fIsPostNotification false
...
OldUrl http://sitemap.laf24.ru/v1/sitemap/provider?key=sitemap.xml
NewUrl /sitemap.xml
...
ModuleName ManagedPipelineHandler
Notification EXECUTE_REQUEST_HANDLER
HttpStatus 404
HttpReason Not Found
HttpSubStatus 0
ErrorCode The operation completed successfully. (0x0)
I should point again that if I place an empty sitemap.xml to the root of mysitedomain, than all start working as expected. I got actual data from sitemap.mysitedomain.
I have found why it is happen and it is not a problem with Url Rewrite or ARR modules. The main reason is that ASP.Net handle such requests and return 404 because there are no routes defined to process such paths.
To fix this we added ignore definitions for sitemaps urls
routes.IgnoreRoute("sitemap.xml");
routes.IgnoreRoute("sitemap/{*pathInfo}");

How do I change where a web.config for a virtual directory in IIS is generated?

I've created a virtual directory within our intranet web application in IIS 7.5. The virtual directory currently points to the following location:
\\fileserver\root\Departments
Whenever I enable directory browsing, it creates a web.config within the Departments folder.
My question is - Is there a way that I can set this up to change where this web.config file is generated? If possible, I'd like it to be generated in the parent directory aka. \\fileserver\root. Is this possible?
When using IIS Manager, and modifying a directory or virtual directory you can not specify where the new web.config is saved. It goes into that directory.
However, you can get away with not using web.config in any sub-directories and specify specific settings for various sub-directories. In the root web.config, use the location node such as:
<configuration>
<location path="Departments">
<system.webServer>
<defaultDocument>
<files>
<add value="blah.htm" />
</files>
</defaultDocument>
</system.webServer>
</location>
</configuration>
The path is the name of the sub-directory, anything inside the location node is just applied to that path.
If you want to use the GUI, you can use the Configuration Editor to change your settings and choose From:Root web.config at the top.

Getting 404 errors using Slim PHP on IIS7

I'm trying to use the Slim PHP framework with IIS7. Now on some routes I keep getting a 404 from IIS which I find really confusing. Here's my index php:
require 'slim/slim.php';
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
$app->notFound(function () use ($app) {
echo("not found!");
});
$app->get("/books/:id", function($id){
echo("hello book " . $id . "!");
});
$app->get("/test",function(){
echo("testing");
});
$app->run();
On IIS (running PHP 5.3) I've setup the url rewritting to send all requests to my index.php file and disabled directory browsing. This seems to work fine as going to localhost/books/123 produces "hello book 123!". But when I go to localhost/test I just get a 404 error from IIS! If add a trailing slash to that url my slim notFound handler is triggered instead of my route handler.
If i create a directory called "test" it stops the 404 response but triggers the slim notFound handler rather than the defined route handler as I would expect. This seems really weird as I've disabled directory browsing.
I know my slim notFound handler is working ok as trying localhost/abc/xyz triggers the handler and works as expected.
Could anybody explain what is going on and why? Have I overlooked some configuration?
Thanks.
It turns out this weird behaviour was caused by my url rewrite rule on IIS. Doh!
I had the regex rule /.* rewrite to my index.php file rather than use .* as the regex.
The first slash wasn't being included as part of the rewritten url which then caused the issue I described. Changing the regex to just be .* fixed everything.
If anyone else encounters an issue like this then double check your url rewrite rule even if it seems to be working ok!
My very simple web.config file is:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="slim catch all" enabled="true">
<match url=".*" />
<action type="Rewrite" url="/index.php" />
<conditions>
<add input="{URL}" pattern="/content/.*" negate="true" />
</conditions>
</rule>
</rules>
</rewrite>
</system.webServer>
Note: this is using URL Rewrite 2.0 on IIS
Index.php is the file which sets up all the Slim routing. The condition is stopping requests to the /content/ path from being routed through Slim - this makes it a good place to store things like images, css files and javascript as the responses should be faster as they are not processed by Slim.

Resources