Skip to content

Commit 12eaf72

Browse files
committed
change: dangerous tools are now prohibited by default
Safer posture for a public package. Opt in with DangerousTools::allow(); prohibit()/the facade re-lock. Adds a reflection test for the shipped default; docs (README, tools, SECURITY) updated. 100% coverage (784/784).
1 parent fe63b29 commit 12eaf72

5 files changed

Lines changed: 13 additions & 7 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ class WeatherTool implements Tool
103103

104104
### Dangerous tools
105105

106-
`shell_exec`, `file_write`, and `delete_file` are shipped but every call is gated. Lock them down with one static call (e.g. in a production service provider):
106+
`shell_exec`, `file_write`, `file_append`, `delete_file`, `mkdir`, `move_file`, and `db_query` are shipped but **prohibited by default**every call is gated like Laravel's `DB::prohibitDestructiveCommands()`. Opt in when you trust the environment:
107107

108108
```php
109109
use Kevariable\PhpclawLaravel\DangerousTools;
110110

111-
DangerousTools::prohibit(); // any dangerous tool now throws DangerousToolsProhibitedException
112-
DangerousTools::allow(); // re-enable (the default)
111+
DangerousTools::allow(); // enable (off by default) — any dangerous tool works
112+
DangerousTools::prohibit(); // re-lock; calls throw DangerousToolsProhibitedException
113113

114114
// or via the facade:
115115
Phpclaw::prohibitDangerousTools();

SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ Please include enough detail to reproduce the issue. You will get an acknowledge
99

1010
## Notes on the agent's powerful tools
1111

12-
This package can register tools that read the filesystem and make HTTP requests. The destructive/system tools (shell execution, process control, raw database queries, file writes/deletes) are intentionally **not** shipped enabled — they are only available if you add them yourself. Treat any agent that can run tools as a privileged actor and scope the `phpclaw.tools_root`, the registered tools, and the browser token accordingly.
12+
This package can register tools that read the filesystem and make HTTP requests. The dangerous tools (shell execution, file writes/appends/deletes, directory creation, file moves, raw database queries) ship registered but are **prohibited by default** — every call is gated and throws unless you explicitly call `Kevariable\PhpclawLaravel\DangerousTools::allow()`. Enable them only in environments you trust. Treat any agent that can run tools as a privileged actor and scope the `phpclaw.tools_root`, the registered tools, and the API/browser tokens accordingly.

docs/tools.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ use Kevariable\PhpclawLaravel\Facades\Phpclaw;
5757
Phpclaw::prohibitDangerousTools(); // e.g. in production
5858
```
5959

60-
They are allowed by default (like migration prohibition). Call `prohibit()` — typically in a production service providerto disable them. File tools remain path-scoped via `PathResolver`. See [SECURITY.md](../SECURITY.md).
60+
They are **prohibited by default** — call `DangerousTools::allow()` (e.g. in a service provider, or only in trusted/local environments) to enable them. `prohibit()` / the facade re-locks them. File tools remain path-scoped via `PathResolver`. See [SECURITY.md](../SECURITY.md).
6161

6262
## Adding a tool
6363

src/DangerousTools.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class DangerousTools
1010
{
11-
protected static bool $prohibited = false;
11+
protected static bool $prohibited = true;
1212

1313
public static function allow(): void
1414
{

tests/Unit/DangerousToolsTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55
use Kevariable\PhpclawLaravel\DangerousTools;
66
use Kevariable\PhpclawLaravel\Exceptions\DangerousToolsProhibitedException;
77

8-
it('allows by default and guards without throwing (happy path)', function () {
8+
it('ships prohibited by default (safety)', function () {
9+
$default = (new ReflectionClass(DangerousTools::class))->getDefaultProperties()['prohibited'];
10+
11+
expect($default)->toBeTrue();
12+
});
13+
14+
it('guards without throwing once allowed (happy path)', function () {
915
DangerousTools::allow();
1016
DangerousTools::guard();
1117

0 commit comments

Comments
 (0)