Package com.tnsai.server.security
Record Class WorkspaceConfig
java.lang.Object
java.lang.Record
com.tnsai.server.security.WorkspaceConfig
Workspace allowlist + caps for
/api/index (TNS-302).
Every path supplied by a client is canonicalised (symlinks resolved) and
checked against this allowlist before any file system walk. The default
allowlist is the JVM's working directory (user.dir); custom roots
can be supplied via roots(Path...) or the TNSAI_WORKSPACE_ROOT
environment variable (PATH-separated by File.pathSeparator).
maxFileCount() caps the directory tree size that can be indexed
in one call, preventing a malicious request from forcing the server to walk
an entire disk.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionWorkspaceConfig(List<Path> roots, int maxFileCount) Creates an instance of aWorkspaceConfigrecord class. -
Method Summary
Modifier and TypeMethodDescriptionstatic WorkspaceConfigcwd()JVM working directory as the only root.final booleanIndicates whether some other object is "equal to" this one.static WorkspaceConfigfromEnv()Reads roots fromTNSAI_WORKSPACE_ROOT(File.pathSeparator-separated).final inthashCode()Returns a hash code value for this object.intReturns the value of themaxFileCountrecord component.roots()Returns the value of therootsrecord component.static WorkspaceConfigCustom roots; each is canonicalised to its absolute real path.final StringtoString()Returns a string representation of this record class.withMaxFileCount(int max)
-
Field Details
-
ROOT_ENV
- See Also:
-
MAX_FILES_ENV
- See Also:
-
DEFAULT_MAX_FILES
public static final int DEFAULT_MAX_FILES- See Also:
-
-
Constructor Details
-
WorkspaceConfig
Creates an instance of aWorkspaceConfigrecord class.- Parameters:
roots- the value for therootsrecord componentmaxFileCount- the value for themaxFileCountrecord component
-
-
Method Details
-
cwd
JVM working directory as the only root. -
roots
Custom roots; each is canonicalised to its absolute real path. -
withMaxFileCount
-
fromEnv
Reads roots fromTNSAI_WORKSPACE_ROOT(File.pathSeparator-separated). Falls back tocwd()when unset. ReadsTNSAI_WORKSPACE_MAX_FILESfor the cap; falls back toDEFAULT_MAX_FILES. -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
roots
Returns the value of therootsrecord component.- Returns:
- the value of the
rootsrecord component
-
maxFileCount
public int maxFileCount()Returns the value of themaxFileCountrecord component.- Returns:
- the value of the
maxFileCountrecord component
-