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

Add Validator for Path Traversal #22

Open
gilday opened this issue Feb 9, 2024 · 2 comments
Open

Add Validator for Path Traversal #22

gilday opened this issue Feb 9, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@gilday
Copy link
Contributor

gilday commented Feb 9, 2024

To prevent path traversal, I need to ensure that a given Path does not escape out of a given directory. Looking for a validator that will make this easy e.g.

public static boolean isParent(Path directory, Path path) { ... }
@gilday gilday added the enhancement New feature or request label Feb 9, 2024
@nahsra
Copy link
Contributor

nahsra commented Feb 9, 2024

I see multiple use cases here that align nicely with some of the issues we just had in our own security advisory.

public static boolean hasEscapeSequences(Path p) -- to confirm that a Path has no escape sequences and can be safely used with Path#resolve() to build a child Path of a directory.

public static boolean isFileWithinDirectory(Path file, Path directory) -- to confirm the given (full) file path is in the given directory.

Does this sound right to you?

@nahsra nahsra self-assigned this Feb 9, 2024
@nahsra nahsra added the good first issue Good for newcomers label Feb 9, 2024
@gilday
Copy link
Contributor Author

gilday commented Feb 9, 2024

Yes, that sounds right to me. My use case is this:

I am processing a response from an external system that I do not trust. This response includes a directory and a list of files that are supposedly in that directory. I want to verify that those files are in fact children of the given directory vs attempts to escape that directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants