Installation

File path Traversal

File path Traversal

by Andras Balogh -
Number of replies: 2

Our server got flagged by IT for "File path Traversal".

They flagged 18 files like

/webwork2_files/node_modules/mathjax/es5/tex-svg.js  
/webwork2_files/themes/math4-green/bootstrap.0b64c025.min.css   
/webwork2_files/themes/math4-green/images/maa_logo.svg

While I don't fully understand the problem, to me, it seems like "webwork2_files" is not an actual directory, and there is no real file path.

Is there anything I can do about this?

They indicated that

Ideally, application functionality should be designed in such a way that user-controllable data does not need to be passed to filesystem operations. This can normally be achieved by referencing known files via an index number rather than their name, and using application-generated filenames to save user-supplied file content.

If it is considered unavoidable to pass user-controllable data to a filesystem operation, three layers of defense can be employed to prevent path traversal attacks:

  • User-controllable data should be strictly validated before being passed to any filesystem operation. In particular, input containing dot-dot sequences should be blocked.
  • After validating user input, the application can use a suitable filesystem API to verify that the file to be accessed is actually located within the base directory used by the application. In Java, this can be achieved by instantiating a java.io.File object using the user-supplied filename and then calling the getCanonicalPath method on this object. If the string returned by this method does not begin with the name of the start directory, then the user has somehow bypassed the application's input filters, and the request should be rejected. In ASP.NET, the same check can be performed by passing the user-supplied filename to the System.Io.Path.GetFullPath method and checking the returned string in the same way as described for Java.
  • The directory used to store files that are accessed using user-controllable data can be located on a separate logical volume to other sensitive application and operating system files, so that these cannot be reached via path traversal attacks. In Unix-based systems, this can be achieved using a chrooted filesystem; on Windows, this can be achieved by mounting the base directory as a new logical drive and using the associated drive letter to access its contents.


In reply to Andras Balogh

Re: File path Traversal

by Glenn Rice -

Your IT seems to be confused about something.  Those are static asset files.  Any file served under the webwork2_files path is a static asset (although they can be dynamically generated images and such they are still considered static assets).  None of those files contain user sensitive data.  Particularly the ones you listed.  Furthermore, all files under the webwork2_files path are meant to be publicly accessible.

Yes, there is no actual directory named webwork2_files. There never is an actual directory that matches the URL on any server for about any file that is served, so that is completely off the point.

Note that a file path traversal attack means that someone could modify a URL to access any file they wanted to on the server because the server does not protect against such modifications and allows any file to be served via such an approach.  For example, if the server had a route named loadFilename that accepted a URL parameter that will serve the given file like https://server.name/loadFilename?filename=image.png, and an attacker could use https://server.name/loadFilename?filename=../../../etc/passwd and get the secure file passwd because the server does not check the path that is passed and just serves that file.

I do not believe that there is such a case where that can be done with webwork2, and of course if there is let us know and we will fix that.

Although, here is where I believe your IT is confused.  The MathJax tex-svg.js file would have the URL http://localhost:3005/webwork2_files/node_modules/mathjax/es5/tex-svg.js?version=^3.2.2.  The version URL parameter in this case does not in any way dictate what file is loaded.  In fact, it is completely ignored by the webwork2 app.  The only reason it is there is to make the URL change when the version of the MathJax library changes (for instance when webwork2 is upgraded and a new MathJax version is switched to with that upgrade), and thus browser caching will be prevented.  This sort of thing is standard practice, and there is certainly nothing insecure about it.  Most likely your IT is seeing that and thinking it is something like the filename parameter in the previous example.  However, it is nothing like that and no file path traversal attack is possible using the version parameter.

For the bootstrap css file most likely there is similar confusion by your IT.  They are most likely seeing the hash in the file name and thinking that means that the file is user specific content that is being served. Again it is not.  In fact that hash will be the same on any webwork2 server using the same version of webwork2.  I see that my server has that exact hash.  The hash is based on the content of the file, and will change anytime the content of the file changes which again might happen when webwork2 is upgraded, and this has the exact same purpose as the version parameter to prevent browser caching.  This is also standard practice, there is nothing insecure about doing this, and it is completely impossible to use it for a file path traversal attack.

As to the maa_logo.svg file, that is completely off base.  That file does not have a parameter on its URL, and there is nothing that should make anyone believe there is a potential file path traversal attack.  The URL is /webwork2_files/themes/math4-green/images/maa_logo.svg, and the actual file served is /opt/webwork/webwork2/htdocs/themes/math4-green/images/maa_logo.svg.  This is the same as for a default apache2 server serving a file located in /var/www/html.  The URL would be /images/filename.svg and the file is /var/www/html/images/filename.svg.  Again, it is extremely rare that a file path on the server actually matches the URL path.  It is also not possible to, for instance, use a URL like /webwork2_files/../../../etc/passwd and gain access to the /etc/passwd file.

So long story short, your IT (or perhaps some automated tool they are using for this check) is completely unfounded with this.  It also is not possible for your IT to validly detect a potential file path traversal vulnerability just by looking at URLs.  So something is completely wrong with their assessment.  The only way to detect a potential file path traversal vulnerability would be to analyze the code of the server and application.  Just by looking at the URL they can not see if there are protections in place against exactly the sort of things listed (like using dot-dot sequences, using a suitable file system API, etc).

In reply to Glenn Rice

Re: File path Traversal

by Andras Balogh -
Thanks!
I sent in a shortened version of this explanation. So far no response. No news is good news.