Java Snippet #07

Bookmarked!

This challenge covers the review of a snippet of code written in Java

PRO
Tier
Easy
< 1 Hr.
1206

The Code Review Snippet challenges are designed to provide you with small, vulnerable code snippets to analyze. In the Serve.java example, the code is intended to serve content based on a provided path, ensuring the path starts with "/srv/uploads" to restrict access. However, this filter is insufficient to prevent directory traversal attacks, which can exploit paths like "/srv/uploads/../../etc/passwd" to access sensitive files outside the intended directory.

The primary issue with this code is its vulnerability to directory traversal attacks due to the lack of proper path canonicalization. While the path check ensures that it starts with "/srv/uploads," it fails to account for malicious input that uses relative paths to navigate outside the restricted directory. To mitigate this, the path should be canonicalized first, ensuring no directory traversal can occur before applying the filter.

Want to learn more? Get started with PentesterLab Pro! GOPRO