Class WorkspaceGuard

java.lang.Object
com.tnsai.server.security.WorkspaceGuard

public final class WorkspaceGuard extends Object
Validates a client-supplied path against WorkspaceConfig (TNS-302).

validate(String) canonicalises the path (symlinks resolved) and confirms it falls under one of the configured roots. If the path doesn't exist yet the parent directory is canonicalised instead, so a request to index <root>/new-dir that the user has just created races between "exists" and "doesn't exist" without exploding.

countFiles(Path) runs a fast file-count walk and rejects when the tree exceeds WorkspaceConfig.maxFileCount() — pre-flight, before the indexer is invoked.

  • Constructor Details

  • Method Details

    • config

      public WorkspaceConfig config()
    • validate

      public Path validate(String pathStr)
      Canonicalise the supplied path and verify it is under at least one allowlisted root.
      Returns:
      the canonicalised absolute path, safe to pass downstream.
      Throws:
      WorkspaceGuard.WorkspaceViolation - when the path resolves outside every root.
    • countFiles

      public long countFiles(Path root)
      Count files under root and throw if it exceeds WorkspaceConfig.maxFileCount(). Returns the count when within bounds.