PathValidator
API reference › Scaffold › Security › PathValidator
Rejects source and destination paths that are absolute, contain .. segments, escape their root through a symlink,
or address the reserved scaffold-lock.json.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
hasTraversal() static | Returns whether $path contains a .. segment, splitting on forward slashes and backslashes. | PathValidator |
isAbsolute() static | Returns whether $path starts with a directory separator or a Windows drive letter. | PathValidator |
validateDestination() | Validates that a destination path does not escape the project root. | PathValidator |
validateSource() | Validates that a source path does not escape the provider root. | PathValidator |
Method details
Section titled “Method details”hasTraversal()
Section titled “hasTraversal() ”public static function hasTraversal(string $path): boolReturns whether $path contains a .. segment, splitting on forward slashes and backslashes.
Parameters
| Parameter | Type | Description |
|---|---|---|
$path | string | Path to check. |
Returns
bool: true when a segment is .., false otherwise.
isAbsolute()
Section titled “isAbsolute() ”public static function isAbsolute(string $path): boolReturns whether $path starts with a directory separator or a Windows drive letter.
Parameters
| Parameter | Type | Description |
|---|---|---|
$path | string | Path to check. |
Returns
bool: true when the path is absolute or drive-qualified, false otherwise.
validateDestination()
Section titled “validateDestination() ”public function validateDestination(string $destination, string $projectRoot): stringValidates that a destination path does not escape the project root.
Parameters
| Parameter | Type | Description |
|---|---|---|
$destination | string | Relative destination path declared in the manifest. |
$projectRoot | string | Absolute path to the project root directory. |
Returns
string: Canonical absolute path of the project root.
Throws
RuntimeException: when the project root does not exist, or the destination is absolute, contains.., escapes the root through a symlink, or is reserved.
validateSource()
Section titled “validateSource() ”public function validateSource(string $source, string $providerRoot): stringValidates that a source path does not escape the provider root.
Parameters
| Parameter | Type | Description |
|---|---|---|
$source | string | Relative source path declared in the manifest. |
$providerRoot | string | Absolute path to the provider root inside vendor. |
Returns
string: Canonical absolute path of the provider root.
Throws
RuntimeException: when the provider root does not exist, or the source is absolute, contains..or escapes the root through a symlink.