Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pathname may not contain double slash “//” when using UNC notation with IIS #801

Closed
paulsivers opened this issue Jan 28, 2019 · 12 comments

Comments

@paulsivers
Copy link

Short description of the issue

Getting error stating - pathname may not contain double slash “//”

Possibly with allowPath() method in WireFileTools.php

This seems to be throwing an exception when using UNC notation for pathnames (In an IIS7 / Share on NAS box environment)

After upgrading two development sites from version 3.0.114 to the now Master 3.0.123, I am encountering issues with image uploads / resizing when trying to add images or after executing some code to set a new width on existing images that are output as thumbnails within a slideshow thumbnail navigation.

If I revert back to my previous version of the 'wire' directory, all is ok.

I am running IIS7 on a Windows Server (for development) with files residing on a NAS box on the network - Sites in IIS7 are mapped to the NAS box network name ie. \ALPHA\Development.... and IP address/port number combinations used to view the sites - this is the development set up that has been running for a number of years and currently runs over 20 ProcessWire sites with no issues (certainly up to version 3.0.114)

Two of the errors I get are:

pathname may not contain double slash “//” (in \ALPHA\DEVELOPMENT\NOL Network\Website\wire\modules\Inputfield\InputfieldFile\InputfieldFile.module line 791)

The above is when adding an image to a page in Admin.

and ...

Error: Exception: pathname may not contain double slash “//” (in \ALPHA\DEVELOPMENT\NOL Network\Website\wire\core\WireFileTools.php line 486) #0 \ALPHA\DEVELOPMENT\NOL Network\Website\wire\core\WireFileTools.php(821): ProcessWire\WireFileTools->allowPath('//ALPHA/DEVELOP...', false, true) #1 \ALPHA\DEVELOPMENT\NOL Network\Website\wire\core\WireTempDir.php(353): ProcessWire\WireFileTools->filePutContents('//ALPHA/DEVELOP...', 1548003024) #2 \ALPHA\DEVELOPMENT\NOL Network\Website\wire\core\WireTempDir.php(164): ProcessWire\WireTempDir->mkdir('//ALPHA/DEVELOP...', true) #3 \ALPHA\DEVELOPMENT\NOL Network\Website\wire\core\PagefilesManager.php(623): ProcessWire\WireTempDir->get() #4 \ALPHA\DEVELOPMENT\NOL Network\Website\wire\core\Pageimage.php(703): ProcessWire\PagefilesManager->getTempPath() #5 \ALPHA\DEVELOPMENT\NOL Network\Website\wire\core\Pageimage.php(552): ProcessWire\Pageimage->___size(100, 0, Array) #6 \ALPHA\DEVELOPMENT\NOL Network\Website\wire\core\Pageimage.php(865): ProcessWire\Pageimage->size(

when an existing image is trying to resize on the fly after changing code to display images with a defined width.

I noticed that in WireFileTools.php there is a reference on line 414 in the notes near to where this error occurs that says '@SInCE 3.0.118'

It has been suggested in a reply to a forum post about this issue that the solution would be not to use UNC notation but rather map a drive to the share and use a drive letter. Have tried this but cannot configure IIS site to use mapped drive (also read that IIS should in fact use UNC notation)

Setup/Environment

ProcessWire 3.0.123
IIS7
PHP 5.6

@ryancramerdesign
Copy link
Member

I don't have a way to debug this as I don't work on IIS and PW doesn't officially support it. Though happy to try and resolve it still but probably need someone else to debug this one. Do you have any idea where the double slashes are in the path? PW disallows them as a matter of security because paths with double slashes can potentially mimic streams or schemes in some cases. You mentioned UNC notation, which I'm not familiar with—does that imply double slashes somewhere?

@paulsivers
Copy link
Author

There's a bit more explanation in the forum post I made about this issue - matjazp had some explanation as to why it is happening.

https://processwire.com/talk/topic/20704-image-upload-resize-issues-pathname-may-not-contain-double-slash-%E2%80%9C%E2%80%9D/

Prior to version 3.0.118 I have not had this issue arise with any other site that uses the same type of config in IIS (going back 5 or so years building ProcessWire sites)

Issue appears after I upgraded to 3.0.123 from 3.0.114 - Falling back to 3.0.114 everything is ok.

@matjazpotocnik
Copy link
Collaborator

Microsoft Windows (not IIS per se) uses the following types of paths:

  • local file system (LFS), such as C:\File
  • uniform naming convention (UNC), such as \\Server\Volume\File
  • long UNC such as \\?\C:\File or \\?\UNC\Server\Volume\File

UNC, short for Universal Naming Convention or Uniform Naming Convention, specifies a common syntax to describe the location of a network resource, such as a shared file, directory, or printer. The (short) UNC syntax for Windows systems has the generic form:

\\ComputerName\SharedFolder\Resource

and that can be used as the home directory folder in the applications and in IIS settings. For example, if you have a server with a name of "myserver" and a share on that server, named "myshare", you can set this as a home (root) folder for the PW installation and then a path to the templates folder is:

\\myserver\myshare\site\templates\

Starting with 3.0.118 (or somewhere around that version), backward slashes are replaced with forward slashes and the path becomes:

//myserver/myshare/site/templates/

throwing WireException in allowPath() method in WireFileTools.php

@ryancramerdesign
Copy link
Member

@matjazpotocnik Thanks for the info, very helpful. I added that double slash check as a safety measure, but it seems like we could let it through if the same slashes appear in a known safe path like $config->paths->assets. I think that would likely resolve the issue. I don't think I added any code to convert back-slashes to forward slashes (that I can remember), so maybe that is coming from PHP.

Matjaz or @paulsivers I'm curious if on a system using this UNC format, what does $config->paths->assets look like if you output it somewhere? Does it have the forward slashes or the back-slashes? Thanks.

@paulsivers
Copy link
Author

@ryancramerdesign Outputting $config->paths->assets in my local dev site gives //ALPHA/DEVELOPMENT/NOL Network/Website/site/assets/

Hope this helps.

@matjazpotocnik
Copy link
Collaborator

@paulsivers for a good measure, please also provide $config->paths->root

@paulsivers
Copy link
Author

$config->paths->root outputs as //ALPHA/DEVELOPMENT/NOL Network/Website/

ryancramerdesign added a commit to processwire/processwire that referenced this issue Feb 5, 2019
@ryancramerdesign
Copy link
Member

@paulsivers @matjazpotocnik Thanks, I think it should be easy for us to work around this then. I've pushed an update that I think will fix it, though please let me know if not.

@matjazpotocnik
Copy link
Collaborator

@paulsivers could you test this fix?
@ryancramerdesign would it work with $ character in path? eg this is a valid UNC share name ($ appended at the end is a hdden share, not viewable when browsing network neighborhood, quite common usage in IT world):

\\mycomputer\myshare$

@ryancramerdesign
Copy link
Member

@matjazpotocnik I don't know for sure without having a test environment, but I don't see anywhere that we are filtering for that, so chances are it would work.

@paulsivers
Copy link
Author

@ryancramerdesign @matjazpotocnik Have updated my site to latest dev and all seems ok now. Many thanks !

@netcarver
Copy link
Collaborator

@paulsivers If this issue is fixed to your satisfaction, please go ahead and close this issue. You can re-open it later if you need to. Thank you.

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

No branches or pull requests

4 participants