Skip to content

Performance: Redundant toRealPath() calls in validatePathTraversal #222

Description

@sfloess

Location

File: ./src/main/java/org/flossware/commons/util/FileUtil.java
Line: 78

Description

The validatePathTraversal() method calls toRealPath() twice (lines 78-79), which performs filesystem I/O operations including symlink resolution. This can be expensive, especially on network filesystems or when called frequently.

Recommendation

If this method is called in a hot path, consider:

  1. Caching the real path results, or
  2. Using a less expensive validation method for initial checks (like validateNoTraversalPatterns) before doing the expensive toRealPath() calls

Severity

HIGH (performance impact in critical I/O paths)

Related

Distinct from #137 (which is about testing infrastructure). This is a specific performance issue in production code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions