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

Fix path traversal issue in createTemporaryNodeServer #19096

Merged
merged 1 commit into from
Nov 24, 2024

Conversation

Rob--W
Copy link
Member

@Rob--W Rob--W commented Nov 23, 2024

The test-only createTemporaryNodeServer helper featured a path traversal vulnerability. This enables attackers with network access to the device to read arbitrary files while unit tests are running that activate this test server.

This patch fixes the issue by validation of paths.

To test this vulnerability before the patch:

  1. Run the test-only server:
node -e 'console.log(require("./test/unit/test_utils.js").createTemporaryNodeServer().port)
  1. From another terminal, send the following request (modify the port to the port reported in the previous step):
curl --path-as-is http://localhost:45755/../../package.json

Before the patch, the second step would traverse the directory, and return results from the root of the PDF.js repository, instead of files within test/pdfs/.

With the patch, the server refuses the request with HTTP status 400.

test/unit/test_utils.js Fixed Show fixed Hide fixed
The test-only createTemporaryNodeServer helper featured a path traversal
vulnerability. This enables attackers with network access to the device
to read arbitrary files while unit tests are running that activate this
test server.

This patch fixes the issue by validation of paths.

To test this vulnerability before the patch:

1. Run the test-only server:

```
node -e 'console.log(require("./test/unit/test_utils.js").createTemporaryNodeServer().port)
```

2. From another terminal, send the following request (modify the port to
   the port reported in the previous step):

```
curl --path-as-is http://localhost:45755/../../package.json
```

Before the patch, the second step would traverse the directory, and
return results from the root of the PDF.js repository, instead of files
within test/pdfs/.

With the patch, the server refuses the request with HTTP status 400.
@timvandermeij
Copy link
Contributor

/botio unittest

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Received

Command cmd_unittest from @timvandermeij received. Current queue size: 0

Live output at: http://54.241.84.105:8877/e4ae57603073add/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Received

Command cmd_unittest from @timvandermeij received. Current queue size: 0

Live output at: http://54.193.163.58:8877/f77715541644ec4/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/e4ae57603073add/output.txt

Total script time: 2.56 mins

  • Unit Tests: Passed

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Success

Full output at http://54.193.163.58:8877/f77715541644ec4/output.txt

Total script time: 6.65 mins

  • Unit Tests: Passed

@timvandermeij timvandermeij merged commit 8ae5b4e into mozilla:master Nov 24, 2024
7 checks passed
@timvandermeij
Copy link
Contributor

Thank you for spotting and fixing this!

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

Successfully merging this pull request may close these issues.

3 participants