Why Project Trust?
When you run PsySH in a project directory, it can automatically:- Load the project’s
vendor/autoload.php(Composer autoloader) - Use a local PsySH installation from
vendor/bin/psysh - Execute configuration files from
.psysh.php
Trust Modes
PsySH supports three trust modes, defined insrc/Configuration.php:52-54:
Prompt Mode (Default)
src/ProjectTrust.php:234-258.
Always Trust Mode
.psysh.php:
Never Trust Mode
.psysh.php:
Command-Line Flags
Trust This Project
bin/psysh:40-46:
Don’t Trust This Project
Trust Persistence
Trusted projects are stored in a JSON file for persistence across sessions.Trust File Location
Fromsrc/ProjectTrust.php:449-457:
- Linux/macOS:
~/.config/psysh/trusted_projects.json - Windows:
%APPDATA%\PsySH\trusted_projects.json
Trust File Format
The trust file stores an array of trusted project root paths:src/ProjectTrust.php:430-444:
Session-Only Trust
If the trust file cannot be written (permissions issue), PsySH falls back to session-only trust:src/ProjectTrust.php:172-190:
Project Root Detection
PsySH determines the project root by walking up directories looking forcomposer.json.
From src/ProjectTrust.php:276-284:
Path Normalization
Paths are normalized to absolute, real paths: Fromsrc/ProjectTrust.php:263-271:
/path/to/project and /path/to/project/ are treated as the same project.
Restricted Mode
When a project is not trusted, PsySH runs in restricted mode:What’s Disabled
- Composer Autoload:
vendor/autoload.phpis not loaded - Local Configuration:
.psysh.phpis not loaded - Local PsySH Binary: Won’t switch to local
vendor/bin/psysh
Autoload Warning
Fromsrc/ProjectTrust.php:210-225:
Local PsySH Detection
PsySH can detect and use a local installation, but only if trusted.Detection Logic
Frombin/psysh:256-283, the launcher looks for:
composer.jsonwith"name": "psy/psysh"composer.lockwithpsy/psyshpackage
bin/psysh:240-245:
Environment Variables
PSYSH_TRUST_PROJECT
Controls trust mode globally:src/ProjectTrust.php:64-78:
PSYSH_UNTRUSTED_PROJECT
Internal variable set by the launcher to pass context between global and local PsySH instances.Configuration
In .psysh.php
Set the trust mode in your global config:Programmatic Usage
Best Practices
Use prompt mode (default)
Use prompt mode (default)
The default prompt mode provides the best balance of security and convenience:
- You’re protected from accidentally running untrusted code
- You can quickly trust projects you recognize
- Trust decisions persist across sessions
Review trust prompts carefully
Review trust prompts carefully
When prompted to trust a project, verify:
- Is this a project you created or control?
- Do you trust the code in
vendor/autoload.php? - Is the
.psysh.phpconfig file safe?
Audit your trusted projects
Audit your trusted projects
Periodically review Remove projects you no longer work with or trust.
~/.config/psysh/trusted_projects.json:Use --no-trust-project for exploration
Use --no-trust-project for exploration
When exploring unfamiliar codebases:This prevents any project code from executing automatically.
Never use 'always' mode on shared systems
Never use 'always' mode on shared systems
Security Considerations
Troubleshooting
Trust prompt not appearing
Trust prompt not appearing
If you’re not seeing trust prompts:Check your trust mode:Solution: Ensure mode is set to
'prompt' or not set at all.Cannot save trust settings
Cannot save trust settings
Project not loading despite trust
Project not loading despite trust
If autoload isn’t loading even after trusting:Verify project is in trust file:Check for path mismatches: The stored path must exactly match the normalized path.Re-trust the project:
How to untrust a project
How to untrust a project
Edit the trust file manually:Or delete the trust file entirely to start fresh: