Skip to content

Commit

Permalink
Document possibility of Path Traversal attacks in path validators (#900)
Browse files Browse the repository at this point in the history
Fixes #899
  • Loading branch information
sleberknight authored Jan 31, 2023
1 parent 9245867 commit 601380d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/main/java/org/kiwiproject/validation/DirectoryPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import java.lang.annotation.Target;

/**
* The annotated element must point to an existing directory.
* The annotated element must point to an existing directory. Please read the implementation note regarding
* intended usage of this annotation with respect to the potential for
* <a href="https://owasp.org/www-community/attacks/Path_Traversal">Path Traversal</a> attacks.
* <p>
* By default does not permit null values. If the element being validated allows {@code null} values, you can
* set {@link #allowNull()} to {@code true}.
Expand All @@ -39,6 +41,12 @@
* {@literal @}DirectoryPath(ensureReadable = true, ensureWritable = true, mkdirs = true)
* private String tempDir;
* </pre>
*
* @implNote This annotation is not intended to validate user input from client-side applications, because of the
* possibility of <a href="https://owasp.org/www-community/attacks/Path_Traversal">Path Traversal</a> attacks. Instead,
* the intended usage is to validate application configuration parameters, e.g. an application reads a local
* configuration file at startup. Even this is not 100% safe, since the configuration could come from a remote
* location such as a configuration service, so users should understand the usage risks and mitigate when possible.
*/
@Documented
@Constraint(validatedBy = {DirectoryPathValidator.class})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
* <p>
* As mentioned in the documentation for {@link DirectoryPath}, this may also attempt to create the directory
* if it does not already exist, which may be an unexpected side-effect.
*
* @implNote Please read the implementation note in {@link DirectoryPath} regarding the possibility of
* <a href="https://owasp.org/www-community/attacks/Path_Traversal">Path Traversal</a> attacks.
*/
@Slf4j
public class DirectoryPathValidator implements ConstraintValidator<DirectoryPath, String> {
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/org/kiwiproject/validation/FilePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import java.lang.annotation.Target;

/**
* The annotated element must point to an existing file.
* The annotated element must point to an existing file. Please read the implementation note regarding
* intended usage of this annotation with respect to the potential for
* <a href="https://owasp.org/www-community/attacks/Path_Traversal">Path Traversal</a> attacks.
* <p>
* By default does not permit null values. If the element being validated allows {@code null} values, you can
* set {@link #allowNull()} to {@code true}.
Expand All @@ -29,6 +31,12 @@
* {@literal @}FilePath(allowNull = true)
* public String getLocation() { return this.location; }
* </pre>
*
* @implNote This annotation is not intended to validate user input from client-side applications, because of the
* possibility of <a href="https://owasp.org/www-community/attacks/Path_Traversal">Path Traversal</a> attacks. Instead,
* the intended usage is to validate application configuration parameters, e.g. an application reads a local
* configuration file at startup. Even this is not 100% safe, since the configuration could come from a remote
* location such as a configuration service, so users should understand the usage risks and mitigate when possible.
*/
@Documented
@Constraint(validatedBy = {FilePathValidator.class})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

/**
* Validates that a string value is a valid path, exists, and is a regular file (not a directory).
*
* @implNote Please read the implementation note in {@link FilePath} regarding the possibility of
* <a href="https://owasp.org/www-community/attacks/Path_Traversal">Path Traversal</a> attacks.
*/
@Slf4j
public class FilePathValidator implements ConstraintValidator<FilePath, String> {
Expand Down

0 comments on commit 601380d

Please sign in to comment.