# PathValidator

> Rejects source and destination paths that are absolute, contain .. segments, escape their root through a symlink, or address the reserved scaffold-lock.json.

[API reference](/docs/api/index.md) › [Scaffold](/docs/extensions/scaffold/reference/index.md) › [Security](/docs/extensions/scaffold/reference/security/index.md) › PathValidator

| final class | `PHPForge\Scaffold\Security\PathValidator` |
| --- | --- |
| Source | [`src/Security/PathValidator.php`](https://github.com/php-forge/scaffold/blob/main/src/Security/PathValidator.php#L15) |

Rejects source and destination paths that are absolute, contain `..` segments, escape their root through a symlink,
or address the reserved `scaffold-lock.json`.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`hasTraversal()`](#method-hasTraversal) static | Returns whether `$path` contains a `..` segment, splitting on forward slashes and backslashes. | `PathValidator` |
| [`isAbsolute()`](#method-isAbsolute) static | Returns whether `$path` starts with a directory separator or a Windows drive letter. | `PathValidator` |
| [`validateDestination()`](#method-validateDestination) | Validates that a destination path does not escape the project root. | `PathValidator` |
| [`validateSource()`](#method-validateSource) | Validates that a source path does not escape the provider root. | `PathValidator` |

## Method details

### hasTraversal() <span id="method-hasTraversal"></span>

```php
public static function hasTraversal(string $path): bool
```

Returns 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() <span id="method-isAbsolute"></span>

```php
public static function isAbsolute(string $path): bool
```

Returns 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() <span id="method-validateDestination"></span>

```php
public function validateDestination(string $destination, string $projectRoot): string
```

Validates 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`](https://www.php.net/manual/en/class.runtimeexception.php): when the project root does not exist, or the destination is absolute, contains `..`, escapes the root through a symlink, or is reserved.

### validateSource() <span id="method-validateSource"></span>

```php
public function validateSource(string $source, string $providerRoot): string
```

Validates 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`](https://www.php.net/manual/en/class.runtimeexception.php): when the provider root does not exist, or the source is absolute, contains `..` or escapes the root through a symlink.