|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This is a **FIDO2/WebAuthn framework for PHP and Symfony**, providing passwordless authentication using security keys and biometric authenticators. It's organized as a monorepo that splits into multiple packages via git-split. |
| 8 | + |
| 9 | +## Development Commands |
| 10 | + |
| 11 | +All commands use **Castor** (PHP task runner) defined in `castor.php`. |
| 12 | + |
| 13 | +### Testing |
| 14 | +```bash |
| 15 | +# Run all tests |
| 16 | +castor phpunit |
| 17 | + |
| 18 | +# Run specific test(s) |
| 19 | +castor phpunit -- --filter=TestName |
| 20 | + |
| 21 | +# Run specific test file |
| 22 | +./bin/phpunit tests/library/Unit/SomeTest.php |
| 23 | + |
| 24 | +# JavaScript tests (Stimulus) |
| 25 | +castor js |
| 26 | +``` |
| 27 | + |
| 28 | +### Code Quality |
| 29 | +```bash |
| 30 | +# Check code style (Easy Coding Standard) |
| 31 | +castor ecs |
| 32 | + |
| 33 | +# Fix code style issues |
| 34 | +castor ecs_fix |
| 35 | + |
| 36 | +# Check refactoring opportunities (Rector) |
| 37 | +castor rector |
| 38 | + |
| 39 | +# Apply refactorings |
| 40 | +castor rector_fix |
| 41 | + |
| 42 | +# Static analysis (PHPStan at max level) |
| 43 | +castor phpstan |
| 44 | + |
| 45 | +# Architecture layer validation (Deptrac) |
| 46 | +castor deptrac |
| 47 | + |
| 48 | +# PHP syntax check |
| 49 | +castor lint |
| 50 | +``` |
| 51 | + |
| 52 | +### Before Submitting PR |
| 53 | +```bash |
| 54 | +# Run all fixes and checks in sequence |
| 55 | +castor prepare_pr |
| 56 | +``` |
| 57 | + |
| 58 | +## Architecture |
| 59 | + |
| 60 | +### Monorepo Structure |
| 61 | + |
| 62 | +Three main packages in `src/`: |
| 63 | + |
| 64 | +1. **`webauthn/`** (`web-auth/webauthn-lib`) - Core PHP library |
| 65 | + - Pure PHP FIDO2/WebAuthn implementation |
| 66 | + - No framework dependencies (besides Symfony components) |
| 67 | + - Handles attestation/assertion validation and cryptographic operations |
| 68 | + |
| 69 | +2. **`symfony/`** (`web-auth/webauthn-symfony-bundle`) - Symfony integration |
| 70 | + - Controllers, repositories, DI configuration |
| 71 | + - Security bundle integration |
| 72 | + - Doctrine ORM credential storage |
| 73 | + |
| 74 | +3. **`stimulus/`** (`web-auth/ux`) - Frontend Stimulus controllers |
| 75 | + - Browser WebAuthn API interaction |
| 76 | + |
| 77 | +Packages are split to separate repos via `.gitsplit.yml`. |
| 78 | + |
| 79 | +### Core Architectural Patterns |
| 80 | + |
| 81 | +**Ceremony Step Pattern** - Validation is decomposed into discrete steps: |
| 82 | +- Located in `src/webauthn/src/CeremonyStep/` |
| 83 | +- Each step implements specific WebAuthn specification requirements |
| 84 | +- Examples: `CheckChallenge`, `CheckSignature`, `CheckOrigin`, `CheckCounter` |
| 85 | +- Orchestrated by `CeremonyStepManager` |
| 86 | +- Steps are registered and executed in sequence during validation ceremonies |
| 87 | + |
| 88 | +**Attestation Statement Support Pattern** - Pluggable attestation format handlers: |
| 89 | +- Located in `src/webauthn/src/AttestationStatement/` |
| 90 | +- Supports: Android Key, Apple, FIDO U2F, Packed, TPM, None, Compound |
| 91 | +- Each format handler implements `AttestationStatementSupport` interface |
| 92 | +- Managed by `AttestationStatementSupportManager` |
| 93 | + |
| 94 | +**Repository Pattern**: |
| 95 | +- `PublicKeyCredentialSourceRepositoryInterface` - Credential storage |
| 96 | +- `PublicKeyCredentialUserEntityRepositoryInterface` - User entity management |
| 97 | +- Doctrine implementation: `DoctrineCredentialSourceRepository` |
| 98 | + |
| 99 | +**Event Dispatcher Pattern**: |
| 100 | +- PSR-14 event dispatcher for lifecycle hooks |
| 101 | +- Events in `src/webauthn/src/Event/` |
| 102 | + |
| 103 | +### Key Components |
| 104 | + |
| 105 | +**Core Validators** (entry points for validation logic): |
| 106 | +- `AuthenticatorAttestationResponseValidator` - Validates registration responses |
| 107 | +- `AuthenticatorAssertionResponseValidator` - Validates authentication responses |
| 108 | + |
| 109 | +**Ceremony Management**: |
| 110 | +- `CeremonyStepManager` in `src/webauthn/src/CeremonyStep/CeremonyStepManager.php` |
| 111 | +- Orchestrates ceremony steps for attestation and assertion validation |
| 112 | +- Steps can be registered/customized via dependency injection |
| 113 | + |
| 114 | +**Credential Management**: |
| 115 | +- `PublicKeyCredentialSource` - Represents stored credentials |
| 116 | +- `PublicKeyCredentialDescriptor` - References credentials |
| 117 | +- Counter validation to detect cloned authenticators |
| 118 | + |
| 119 | +**Symfony Bundle Integration**: |
| 120 | +- Controllers in `src/symfony/src/Controller/` |
| 121 | +- DI configuration in `src/symfony/src/DependencyInjection/` |
| 122 | +- Compiler passes for service registration |
| 123 | +- Security authenticator factory integration |
| 124 | + |
| 125 | +### Architectural Boundaries (Deptrac) |
| 126 | + |
| 127 | +Strict layer enforcement: |
| 128 | +- **Webauthn** (core) → Vendors + MetadataService only |
| 129 | +- **SymfonyBundle** → Vendors + Webauthn + MetadataService |
| 130 | +- **UX/Stimulus** → Vendors only |
| 131 | +- **MetadataService** → Vendors only |
| 132 | + |
| 133 | +Violations will fail CI checks via `castor deptrac`. |
| 134 | + |
| 135 | +## Development Workflow |
| 136 | + |
| 137 | +### Adding a New Ceremony Step |
| 138 | + |
| 139 | +1. Create class in `src/webauthn/src/CeremonyStep/` implementing `CeremonyStep` interface |
| 140 | +2. Register in `CeremonyStepManagerFactory` or via Symfony compiler pass |
| 141 | +3. Add unit tests in `tests/library/Unit/CeremonyStep/` |
| 142 | +4. Consider both attestation and assertion ceremony contexts |
| 143 | + |
| 144 | +### Adding a New Attestation Format |
| 145 | + |
| 146 | +1. Create support class in `src/webauthn/src/AttestationStatement/` |
| 147 | +2. Implement `AttestationStatementSupport` interface |
| 148 | +3. Register via Symfony bundle compiler pass |
| 149 | +4. Add comprehensive tests with real attestation examples in `tests/library/Unit/AttestationStatement/` |
| 150 | + |
| 151 | +### Test Structure |
| 152 | + |
| 153 | +Tests are in `tests/`: |
| 154 | +- `framework/` - Framework-level integration tests |
| 155 | +- `library/` - Core library unit tests (Unit & Functional subdirs) |
| 156 | +- `symfony/` - Symfony bundle functional tests |
| 157 | +- `MDS/` - Metadata Service tests |
| 158 | + |
| 159 | +## Important Context |
| 160 | + |
| 161 | +### Requirements |
| 162 | +- PHP 8.2+ |
| 163 | +- Extensions: ext-json, ext-openssl |
| 164 | +- Symfony 6.4, 7.0, or 8.0 |
| 165 | + |
| 166 | +### Code Standards |
| 167 | +- PSR-12 coding standard (enforced via ECS) |
| 168 | +- Strict types declared in all files |
| 169 | +- PHPStan at max level |
| 170 | +- Git-Flow branching strategy |
| 171 | +- Current development branch: **5.3.x** |
| 172 | +- Main branch for PRs: **5.2.x** |
| 173 | + |
| 174 | +### Key Dependencies |
| 175 | +- `spomky-labs/cbor-php` - CBOR encoding/decoding |
| 176 | +- `web-auth/cose-lib` - COSE cryptography |
| 177 | +- `spomky-labs/pki-framework` - PKI operations |
| 178 | + |
| 179 | +### Monorepo Development |
| 180 | +- Use `./link` script to link local packages for development |
| 181 | +- Changes in `src/*` affect corresponding split repositories |
| 182 | +- CI runs git-split automatically on push |
| 183 | + |
| 184 | +### Security |
| 185 | +- Private vulnerability reporting via GitHub Security Advisories |
| 186 | +- Contact: security@spomky-labs.com |
| 187 | +- **Never** file public issues for security vulnerabilities |
0 commit comments