Skip to content
Path traversal Write-up Beginner

Authenticated Arbitrary File Download (Path Traversal)

An authenticated user could manipulate the asset path parameter in a static content servlet to traverse directories and download arbitrary files from the server filesystem. This allowed reading of sensitive files such as API keys and system files like /etc/passwd.

Chris McCurley Follow

Published on research.aurainfosec.io

An Authenticated Arbitrary File Download vulnerability was found in PaperCut NG/MF. PaperCut is a popular Print Management product that’s used globally by over 80,000 organisations.

Chris McCurley (@chrisrmccurley), on research.aurainfosec.io

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 5 min read.

Context

PaperCut NG/MF is a print management product used by more than 80,000 organisations worldwide. Its application server component is written in Java. Most customers run the server behind a firewall, but some larger customers, universities in particular, may host it on more open servers. The vulnerability described here is an authenticated arbitrary file download in that application server, tracked as CVE-2023-31046 and affecting versions before 22.1.1. The fix shipped in 22.1.1.

Arbitrary file download or read issues arise when an application lets files be included in an unsafe way on the local machine, usually through directory traversal, where the application's directory structure can be walked to reach areas the developer never intended. In PaperCut's case the application server defines a servlet that can be reached with authentication, and a crafted HTTP request to it retrieves files from the underlying filesystem.

Setup

The report does not describe a particular lab build beyond the affected versions (below 22.1.1) and the fixed version (22.1.1). The only precondition that matters is authentication: testing determined that the lowest level of authentication available was enough to reach the vulnerable servlet. The example request targets a host named papercut on port 9192 and carries a session cookie, which the report omits.

Finding it

The starting point was the web.xml configuration file of the PaperCut application. It declares a servlet named static-content-files, mapped to the URL pattern /content/*, whose purpose is to let static content be retrieved and displayed to the user:

XML
<servlet-mapping>
    <servlet-name>static-content-files</servlet-name>
    <url-pattern>/content/*</url-pattern>
</servlet-mapping>

The affected Java code sits in the getStaticContent() function inside UIContentResource.class:

Java
  @GET
  @Path("static/{asset:.*}")
  @CacheControlHeader("max-age=600,public")
  public Response getStaticContent(@PathParam("asset") String asset) {
    try {
      File page = getResourceAsFile("/ui/static/" + asset);
      String contentType = MimeTypeUtils.getMimeTypeStringFromFileName(page.getName());
      return Response.ok(page, contentType).build();
    } catch (Exception e) {
      return Response.status(Response.Status.NOT_FOUND).build();
    }
  }

  private File getResourceAsFile(String resourcePath) {
    String docroot = this._servletContext.getRealPath("/");
    return new File(docroot, resourcePath);
  }

The @PathParam("asset") value is the part of the URL an authenticated user controls. It is concatenated onto the /ui/static/ prefix and passed into getResourceAsFile() without any further sanitisation. That function resolves the document root of the web application and builds a new File object from it and the supplied path, so whatever the caller asks for is opened and returned.

Exploitation

Step 1: send a traversal request to the static content endpoint

With an authenticated session, the asset path parameter is filled with a sequence of ..// segments to climb out of the static content directory and reach the filesystem root, then the target file is named. The report's example requests /etc/passwd:

HTTP
GET /ui/static/..//..//..//..//..//..//..//etc//passwd HTTP/1.1
Host: papercut:9192
Cookie: <..omitted..>
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/110.0
Accept: application/font-woff2;q=1.0,application/font-woff;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: https://papercut:9192/ui/static
Sec-Fetch-Dest: font
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
Te: trailers
Connection: close

The repeated ..// segments are the traversal: each pair moves one directory up from the /ui/static/ base, and the doubled slashes are used as separators. The trailing //etc//passwd names the file to read. The Cookie header carries the authenticated session; testing showed the lowest level of authentication available was enough.

Step 2: read the response

The report states the HTTP response to that request will contain the contents of the requested /etc/passwd file. The same technique reaches anything else the application server process can read. The report names two categories in particular: application material such as API keys under /papercut/server/data/, and files anywhere on the filesystem such as /etc/passwd and /proc/self/environ.

Root cause

The servlet takes a user-controlled path segment and joins it to a fixed prefix without normalising or constraining the result. getResourceAsFile() computes the web application's real path and passes it, together with the attacker-supplied string, to new File(docroot, resourcePath). Nothing checks that the resolved file still lies beneath the intended static content directory, so .. segments are honoured by the filesystem and the file is opened and streamed back with a content type derived from its name. The try/catch around the call only turns failures into a 404; it does not restrict what can be read. Authentication gates the endpoint, but any authenticated user, including one at the lowest level of authentication available, can supply the path.

Impact

An authenticated attacker can download files from the server's filesystem. Which files are available depends on the user account the PaperCut application server runs as. At a minimum, files inside the PaperCut application server directories are disclosed, including API secrets, and those secrets allow authenticated API calls to be made. Where the process can read further, system files such as /etc/passwd and /proc/self/environ are also exposed. Exposure is limited by the deployment: most servers sit behind firewalls, while some larger customers host them on more open servers.

Fix

PaperCut addressed the issue in version 22.1.1, and upgrading to the latest release is the recommended mitigation. The vendor stated that the mitigation in the code is very effective, combining suggestions from the researcher with ideas from PaperCut's own security team, and that release notes and the check-for-updates feature would make the upgrade clear to customers.

Variants to test

  1. Other servlets that serve files by name. Look through web.xml for mappings whose handlers build a File from a request parameter. A positive result is a request whose path parameter, after traversal segments, returns content from outside the intended directory.
  2. Different traversal encodings. Try ..//, ../, URL-encoded %2e%2e%2f and doubled separators against the same parameter. A positive result is any encoding that returns a file you know exists outside the base directory, such as /etc/passwd on Linux.
  3. Application secrets under the data directory. Request paths under /papercut/server/data/ and look for API keys or credentials in the response. A positive result is a response containing secret material that can be used for authenticated API calls.
  4. Process environment. Request /proc/self/environ on Linux hosts. A positive result is environment variables from the application server process, which often include credentials or configuration paths.
  5. Low-privilege accounts. Repeat the request with the least privileged authenticated account available. A positive result is the same file content, showing the endpoint does not enforce role checks beyond authentication.
  6. Content type handling. Note the Content-Type returned for each file, since it is derived from the requested file name. A positive result is a response that renders or downloads the file according to its extension, which can matter when the file is later consumed by a browser.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 15 min read.

What happened, in plain words

PaperCut NG/MF is a print management product: software that organisations use to control who can print what, count pages, charge for printing and manage printers across a network. The report says it is used by more than 80,000 organisations worldwide. Part of the product is an application server, a program that runs in the background and answers requests from web browsers and other software. That component is written in Java, a programming language.

Most customers keep that server behind a firewall, a network barrier that blocks outside connections. Some larger customers, universities in particular, may run it on servers that are more open to the internet.

The report describes a vulnerability in that application server. A vulnerability is a weakness in software that someone can use to make it behave in a way its authors did not intend. This one is an authenticated arbitrary file download: "authenticated" means the attacker must first log in, and "arbitrary file download" means that once logged in, the attacker can ask the server for files and get their contents back, including files the application was never meant to hand out. The weakness is tracked as CVE-2023-31046. A CVE is a public catalogue number given to a known security flaw so that people can refer to it unambiguously. Versions before 22.1.1 are affected, and the fix shipped in 22.1.1.

How does a file download flaw like this happen? Applications often need to serve files: images, stylesheets, fonts, documents. They take a file name from the request and open the matching file on disk. If the application trusts that name without checking it, a user can supply a name that points somewhere else entirely. The usual trick is called directory traversal. On a computer, folders are arranged in a tree, and the notation .. means "the folder one level up". If an application builds a path like static/ plus whatever the user typed, and the user types ../../etc/passwd, the resulting path climbs out of the static folder and lands somewhere the developer never intended. It is like a hotel receptionist who is told "room 12" and walks to room 12, but who will also obediently walk to "room 12, then up the stairs, then out the back door" if you phrase it that way.

In PaperCut's case, the application server defines a servlet that can be reached once you are logged in. A servlet is a small Java program that handles a particular kind of web request inside a larger server. Testing showed that the lowest level of authentication available was enough to reach it. A crafted HTTP request to that servlet retrieves files from the underlying filesystem, the collection of files and folders on the server's disk.

Setup

The report does not describe a particular lab build beyond the affected versions (below 22.1.1) and the fixed version (22.1.1). The only precondition that matters is authentication: testing determined that the lowest level of authentication available was enough to reach the vulnerable servlet. The example request targets a host named papercut on port 9192 and carries a session cookie, which the report omits.

A few of those words deserve unpacking. A host is simply a machine on a network, identified by a name or address. A port is a numbered channel on that machine; one server can listen on several ports for different services, much like a building with several doors, each leading to a different desk. A session cookie is a small piece of text that a website gives your browser after you log in, and which your browser sends back with every later request so the server can recognise you. It works like a wristband at an event: you show it at the door and you are let in without proving who you are again. Because a cookie is effectively a key to your logged-in session, the report leaves its value out of the example.

Finding it

The starting point was the web.xml configuration file of the PaperCut application. A configuration file is a text file that tells a program how to behave, and web.xml is the standard place where a Java web application declares its servlets and the URL patterns they answer. This one declares a servlet named static-content-files, mapped to the URL pattern /content/*, whose purpose is to let static content be retrieved and displayed to the user. "Static content" means files that do not change per user: images, fonts, style sheets and similar assets that the interface needs in order to look right.

XML
<servlet-mapping>
    <servlet-name>static-content-files</servlet-name>
    <url-pattern>/content/*</url-pattern>
</servlet-mapping>

Line by line:

  1. <servlet-mapping> opens a block that ties a servlet to a URL pattern. Everything until the closing tag belongs to that mapping.
  2. <servlet-name>static-content-files</servlet-name> names the servlet being mapped. This is the internal name the application uses for that piece of code.
  3. <url-pattern>/content/*</url-pattern> says which incoming URLs this servlet handles. The * is a wildcard, so any URL that starts with /content/ is routed to this servlet.
  4. </servlet-mapping> closes the block.

Why start here? Because configuration files describe the application's public surface: which URLs exist and what handles them. Reading them is a way of mapping the building before trying any doors. The report then moved from the configuration to the code behind it.

The affected Java code sits in the getStaticContent() function inside UIContentResource.class. A function (or method) is a named block of code that does one job; a class is a file that groups related code together. The .class suffix is the compiled form of a Java source file.

Java
  @GET
  @Path("static/{asset:.*}")
  @CacheControlHeader("max-age=600,public")
  public Response getStaticContent(@PathParam("asset") String asset) {
    try {
      File page = getResourceAsFile("/ui/static/" + asset);
      String contentType = MimeTypeUtils.getMimeTypeStringFromFileName(page.getName());
      return Response.ok(page, contentType).build();
    } catch (Exception e) {
      return Response.status(Response.Status.NOT_FOUND).build();
    }
  }

  private File getResourceAsFile(String resourcePath) {
    String docroot = this._servletContext.getRealPath("/");
    return new File(docroot, resourcePath);
  }

Line by line:

  1. @GET marks this function as the handler for HTTP GET requests. GET is the method a browser uses when you simply ask for a page or a file.
  2. @Path("static/{asset:.*}") says which URL path this function answers. The {asset:.*} part is a placeholder named asset that matches any text, so whatever appears after static/ in the URL is captured and handed to the function.
  3. @CacheControlHeader("max-age=600,public") tells browsers and caches that the response may be stored for 600 seconds and is not private to one user. Caching is when a browser keeps a copy of a file so it does not have to fetch it again.
  4. public Response getStaticContent(@PathParam("asset") String asset) { declares the function. It takes one input, the captured asset text, and returns a Response, which is the HTTP reply sent back to the browser.
  5. try { begins a block of code where errors are expected and will be handled below.
  6. File page = getResourceAsFile("/ui/static/" + asset); is the heart of the problem. It glues the fixed prefix /ui/static/ onto whatever the user supplied and asks the helper function for the resulting file. There is no check that the result stays inside the intended folder.
  7. String contentType = MimeTypeUtils.getMimeTypeStringFromFileName(page.getName()); works out the file's type (for example an image or a text file) from its name, so the reply can be labelled correctly.
  8. return Response.ok(page, contentType).build(); sends the file back to the caller with a success status and that type label.
  9. } catch (Exception e) { catches any error that occurred above, such as the file not existing.
  10. return Response.status(Response.Status.NOT_FOUND).build(); turns that error into a standard "not found" reply. This only hides failures; it does not limit what can be read.
  11. } closes the function.
  12. private File getResourceAsFile(String resourcePath) { starts the helper function. private means it is only used inside this class.
  13. String docroot = this._servletContext.getRealPath("/"); asks the server for the real folder on disk where the web application lives. This is the starting point for every path.
  14. return new File(docroot, resourcePath); builds a file reference by combining that starting folder with the supplied path. If the supplied path contains .. segments, the operating system will happily walk upwards.
  15. } closes the helper.

The @PathParam("asset") value is the part of the URL an authenticated user controls. It is concatenated onto the /ui/static/ prefix and passed into getResourceAsFile() without any further sanitisation. Sanitisation means cleaning input before using it, for example by rejecting .. or by confirming the final path is still inside the allowed folder. That function resolves the document root of the web application and builds a new File object from it and the supplied path, so whatever the caller asks for is opened and returned.

Exploitation

Step 1: send a traversal request to the static content endpoint

With an authenticated session, the asset path parameter is filled with a sequence of ..// segments to climb out of the static content directory and reach the filesystem root, then the target file is named. The report's example requests /etc/passwd, a classic Linux file that lists user accounts.

HTTP
GET /ui/static/..//..//..//..//..//..//..//etc//passwd HTTP/1.1
Host: papercut:9192
Cookie: <..omitted..>
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/110.0
Accept: application/font-woff2;q=1.0,application/font-woff;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: https://papercut:9192/ui/static
Sec-Fetch-Dest: font
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
Te: trailers
Connection: close

Line by line:

  1. GET /ui/static/..//..//..//..//..//..//..//etc//passwd HTTP/1.1 is the request line. GET asks for something; the path is the file being requested; HTTP/1.1 is the version of the web protocol being spoken. The path is where the attack lives: seven ..// pairs climb seven folders up from the static folder, and //etc//passwd names the target file. The doubled slashes are used as separators.
  2. Host: papercut:9192 tells the server which name and port the request is for. One server can host several sites, so the server needs to know which one you mean.
  3. Cookie: <..omitted..> is where the session cookie would go. The report leaves the value out, but this header is what proves the request comes from a logged-in user.
  4. User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/110.0 identifies the browser making the request. Here it claims to be Firefox on Windows.
  5. Accept: application/font-woff2;q=1.0,application/font-woff;q=0.9,*/*;q=0.8 lists the file types the client says it can handle, with relative preferences. Font formats are listed first, which fits the disguise described below.
  6. Accept-Language: en-US,en;q=0.5 states the preferred language, US English first.
  7. Accept-Encoding: gzip, deflate says the client can accept compressed replies.
  8. Referer: https://papercut:9192/ui/static says which page the request came from. Here it claims the request originated on the static UI page.
  9. Sec-Fetch-Dest: font says the browser expects a font as the result.
  10. Sec-Fetch-Mode: cors says this is a cross-origin request, a request whose rules differ from a normal page load.
  11. Sec-Fetch-Site: same-origin says the request is going to the same site that issued the page.
  12. Te: trailers says the client can accept trailing headers after the body.
  13. Connection: close asks the server to close the connection after replying.

The repeated ..// segments are the traversal: each pair moves one directory up from the /ui/static/ base, and the doubled slashes are used as separators. The trailing //etc//passwd names the file to read. The Cookie header carries the authenticated session, which is the only access control in front of the servlet. The remaining headers are ordinary browser headers; the Referer and Sec-Fetch-* values make the request look like a font fetch from the static UI page.

Step 2: read the response

The report states the HTTP response to that request will contain the contents of the requested /etc/passwd file. The same technique reaches anything else the application server process can read. The report names two categories in particular: application material such as API keys under /papercut/server/data/, and files anywhere on the filesystem such as /etc/passwd and /proc/self/environ.

An API is a way for one piece of software to talk to another, and an API key is a secret string that proves which software is calling. It works like a membership card: whoever holds it is treated as a member. If an attacker can read a file containing API keys, they can make authenticated API calls of their own, without ever knowing a password. /proc/self/environ is a special file on Linux that shows the environment variables of the running process, the settings and secrets it was started with. Reading it can reveal credentials or configuration paths.

Root cause

The servlet takes a user-controlled path segment and joins it to a fixed prefix without normalising or constraining the result. Normalising means tidying a path into its final, unambiguous form, so that a/../b becomes b before any decision is made about it. getResourceAsFile() computes the web application's real path and passes it, together with the attacker-supplied string, to new File(docroot, resourcePath). Nothing checks that the resolved file still lies beneath the intended static content directory, so .. segments are honoured by the filesystem and the file is opened and streamed back with a content type derived from its name. The try/catch around the call only turns failures into a 404; it does not restrict what can be read. Authentication gates the endpoint, but any authenticated user, including one at the lowest level of authentication available, can supply the path.

In everyday terms: the receptionist checks that you have a visitor badge, then reads out whatever room number you give, including "room 12, then out the back door". The badge check is real, but it is the only check.

Impact

An authenticated attacker can download files from the server's filesystem. Which files are available depends on the user account the PaperCut application server runs as. At a minimum, files inside the PaperCut application server directories are disclosed, including API secrets, and those secrets allow authenticated API calls to be made. Where the process can read further, system files such as /etc/passwd and /proc/self/environ are also exposed. Exposure is limited by the deployment: most servers sit behind firewalls, while some larger customers host them on more open servers.

Why does the account matter? Every program on a computer runs as some user, and that user can only read files it has permission to read. A program running as a restricted account can reach fewer files than one running as a powerful administrator account. That is why the report says the available files vary.

Fix

PaperCut addressed the issue in version 22.1.1, and upgrading to the latest release is the recommended mitigation. A mitigation is a change that removes or reduces the risk. The vendor stated that the mitigation in the code is very effective, combining suggestions from the researcher with ideas from PaperCut's own security team, and that release notes and the check-for-updates feature would make the upgrade clear to customers.

Variants to test

Once a flaw like this is understood, the natural next question is where else the same pattern might appear. The following follow-up checks apply the same pattern:

  1. Other servlets that serve files by name. Look through web.xml for mappings whose handlers build a File from a request parameter. A positive result is a request whose path parameter, after traversal segments, returns content from outside the intended directory.
  2. Different traversal encodings. Try ..//, ../, URL-encoded %2e%2e%2f and doubled separators against the same parameter. A positive result is any encoding that returns a file you know exists outside the base directory, such as /etc/passwd on Linux. URL encoding is a way of writing special characters using a percent sign and two hex digits, so %2e is a dot and %2f is a slash; some filters check for the literal characters and miss the encoded form.
  3. Application secrets under the data directory. Request paths under /papercut/server/data/ and look for API keys or credentials in the response. A positive result is a response containing secret material that can be used for authenticated API calls.
  4. Process environment. Request /proc/self/environ on Linux hosts. A positive result is environment variables from the application server process, which often include credentials or configuration paths.
  5. Low-privilege accounts. Repeat the request with the least privileged authenticated account available. A positive result is the same file content, showing the endpoint does not enforce role checks beyond authentication.
  6. Content type handling. Note the Content-Type returned for each file, since it is derived from the requested file name. A positive result is a response that renders or downloads the file according to its extension, which can matter when the file is later consumed by a browser.

Glossary

  • API: a defined way for one piece of software to talk to another.
  • API key: a secret string that identifies software calling an API, like a membership card.
  • Application server: a program that runs in the background and answers requests from browsers and other software.
  • Arbitrary file download: a flaw that lets an attacker fetch files of their choosing from a server.
  • Authenticated: having proved who you are, usually by logging in.
  • Cache / caching: storing a copy of a response so it does not have to be fetched again.
  • Class: a file in Java that groups related code together.
  • Configuration file: a text file that tells a program how to behave.
  • Content type: a label on a response saying what kind of file it is, such as an image or a text file.
  • Cookie: a small piece of text a site gives your browser after login, sent back on later requests so the server recognises you.
  • CVE: a public catalogue number for a known security flaw.
  • Directory traversal: using .. segments in a path to climb out of an intended folder and reach other files.
  • Environment variables: named settings a program is started with, sometimes including secrets.
  • Firewall: a network barrier that blocks unwanted connections.
  • Function / method: a named block of code that does one job.
  • GET: the HTTP method used when you simply ask for a page or file.
  • Host: a machine on a network, identified by a name or address.
  • HTTP: the protocol browsers and servers use to exchange requests and responses.
  • Java: a programming language, used here for the application server.
  • Mitigation: a change that removes or reduces a risk.
  • Normalising a path: tidying a path into its final form before making decisions about it.
  • Port: a numbered channel on a machine that a service listens on.
  • Sanitisation: cleaning input before using it, for example by rejecting ...
  • Servlet: a small Java program inside a larger server that handles a particular kind of request.
  • Session: the period during which a server remembers that you are logged in.
  • Static content: files that do not change per user, such as images, fonts and style sheets.
  • URL encoding: writing special characters as a percent sign plus two hex digits, such as %2e for a dot.
  • Vulnerability: a weakness in software that can be used to make it behave in unintended ways.
  • web.xml: the standard configuration file where a Java web application declares its servlets and URL patterns.
  • Wildcard: a symbol such as * that matches any text.

More by Chris McCurley

View all

1 more disclosed report, best first.

More from PaperCut

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Path traversal and file inclusion

The lesson behind this report.

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.