Package com.tnsai.server.security
Class WorkspaceGuard
java.lang.Object
com.tnsai.server.security.WorkspaceGuard
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classThrown when a request resolves to a path outside every allowlisted root. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionconfig()longcountFiles(Path root) Count files underrootand throw if it exceedsWorkspaceConfig.maxFileCount().Canonicalise the supplied path and verify it is under at least one allowlisted root.
-
Constructor Details
-
WorkspaceGuard
-
-
Method Details
-
config
-
validate
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
Count files underrootand throw if it exceedsWorkspaceConfig.maxFileCount(). Returns the count when within bounds.
-