Repository navigation
Release 2.11
What's Changed
Full code review of the library (10 commits since 2.10, tests 1637 → 1756). Security fixes in file serving, error handling and request parsing; strict input validation where values were silently corrupted; a large OpenAPI correctness pass. Some fixes change behaviour - read "Check before upgrading".
Security
FileResponse::setAllowedDirectories()fails closed: a non-existent directory throws instead of being silently dropped (a typo'd upload dir used to disable the check and serve any file);enforce: truewith an empty list denies everything;fromPath()rejects directories; symlink chains are capped at 32 hops (a symlink cycle used to exhaust memory)SimpleErrorHandler/PsrLogErrorHandler: a Tracy logging failure in production (nologDirectory, PSR-only setups, CLI) no longer turns every 4xx into a 500- Scheme-relative request URIs (
//evil.example/users/1) are routed literally instead of as/users/1(path confusion behind proxies/WAFs) IpMatcher: strict IPv6 validation (1:::2was accepted and could become the client IP fromX-Forwarded-For); trusted-proxy matching canonicalizes IPv6 (2001:DB8::1=2001:db8::1) and IPv4-mapped IPv6 (::ffff:10.0.0.1matches10.0.0.0/8)ErrorResponseBuildermatches sensitive context keys by whole words (camelCase / snake_case / kebab-case):passwordHash,pinCode,api_key,x-auth-tokenare still removed, butauthor,issuingAuthority,shipping,pinned,hashtagsvalidation fields are no longer silently dropped from 422 responses- JSON integer literals beyond 64 bits (
9223372036854775808) are rejected with 400 (JsonDecoder);json_decode()turned them into floats and data-mapper wrapped them toPHP_INT_MINwith a 200 BasicAuthMiddleware: scheme name is case-insensitive per RFC 7235 (basicworks),Basicx <token>is rejected- CORS: a request without
Originagainst an origin whitelist gets no CORS headers (used to sendAccess-Control-Allow-Origin: *next toAllow-Credentials: true)
⚠️ Check before upgrading
| Change | What to check |
|---|---|
Duplicate routes fail the container build (Duplicate route GET /users: A::list() and B::index()); /users/{id} vs /users/{slug} counts as a duplicate, #[Alias] included |
copy-pasted paths across controllers (last/first registered used to win silently) |
DateTimeParser is strict: no constructor fallback ('', now, tomorrow, +1 day, 15 January 2024 → 400/422) and calendar overflow (2024-02-30, 25:00) rejected; added Y-m-d\TH:i (datetime-local) and Y-m-d H:i:s |
query DateTime parameters and multipart DTO date fields relying on loose formats |
RateLimitMiddleware returns 429 as a response (with Retry-After, X-RateLimit-*) when an ErrorHandler is autowired - outer middlewares (CORS, RequestId) now decorate it; without a handler it still throws |
code catching the 429 exception around the chain |
RateLimitMiddleware: an ipLimits entry is counted per IP even for authenticated users (the per-IP allowance was checked against a cross-IP per-user counter) |
per-IP limits for logged-in users |
AuditLogMiddleware priority 500 → 400 (runs outside RateLimit/BasicAuth so 401/429 are audited) |
custom middleware ordered relative to it |
cors.enabled: true CORS is ordered by its priority (200) together with middlewares: entries (was always first) |
RequestIdMiddleware / EnforceHttpsMiddleware now run before CORS preflights |
Query parameter sent as an array (?q[]=x) for a scalar type → 400 (controller used to receive the string "Array") |
clients abusing bracket syntax |
Enum parameters follow the backing type: string-backed '1' now matches case One = '1'; int-backed rejects 1.5, 1e0, ' 1' |
numeric-string enum values |
Multipart DTO scalars are validated: count=abc, 12abc, price=1,5 → 422 (was a lossy cast to 0); empty "" on a non-nullable int/float/bool uses the property default, 422 without one |
HTML forms posting empty numeric fields |
Typed #[HeaderParameter] (DateTime, enum) no longer overwrites the raw header; the typed value is bound to the argument |
code reading the converted value back via getHeader() |
paths is always emitted in the OpenAPI document ({} when empty) |
consumers checking for its absence |
OpenAPI changes (regenerate and diff your spec)
- Required = non-nullable property without a default (union types included); properties with a default are optional and the default is emitted as
default;#[Property(required: true)]forces required on nullable properties; static properties are skipped - Discriminator: each
oneOf/anyOfvariant restricts its discriminator property to its mapped value(s) (strict validators no longer see ambiguousoneOf); the variant property keepsdescription/nullable/example/deprecated; numeric-string mapping keys ('1') stay strings forstringproperties #[QueryParameter(schema: new Schema(...))]is converted fully -items,minItems/maxItems,uniqueItems,description, composition - andformat:on the attribute is written to the spec (format: daterestrictsDateTimeparameters toYYYY-MM-DDat runtime too)- Explicit parameter
type:wins over the schema type for runtime conversion #[SecurityScheme]on a controller is now written tocomponents.securitySchemes(it was silently ignored); config entries with the same name win;flows(oauth2) andopenIdConnectUrlare no longer dropped from configured schemes#[Tag(hidden: true)]hides the tag fromtagsand from operations (the built-inOpenApiControllertag no longer leaks)#[Alias]endpoints get a generatedoperationIdinstead of copying the explicit one (ids must be unique)#[OpenApiMerge]deep-merges into generated responses / request bodies (addingheadersto200keeps its description and content)- Unused-schema filter follows
discriminator.mappingand component names containing-or.(no more dangling$ref) #[Response(ref: SomeInterface::class)]produces a schema;JsonContent(properties: [Property(required: true)])emits therequiredlist; multipartarrayproperties aretype: array, items: string, nullable scalars getnullable: true;exclusiveMinimum/exclusiveMaximum/uniqueItemspass through inline schemas
Fixes
- Multipart DTOs: nested objects sent as form fields (
owner[key]=...) are hydrated (was a TypeError), errors prefixed (owner.personId); promoted constructor defaults are applied;DateTimeproperties parse the form value; nested object without a configured serializer is a clearRuntimeStateException - Mutable
\DateTimecontroller arguments no longer TypeError (createFromInterface) - Variadic controller arguments (
string ...$tags) no longer 500 ongetDefaultValue() ApiTestClientcloses its output buffer when the application throws (PHPUnit "risky" tests, shifted buffers)FileResponsesendsContent-Length: 0for empty filesApiExtensioncompiles without aproductionModeparameter (no "Undefined array key" warning)RequestUri::getPath()/getQuery()andApiRequest::getPath()share one implementation
New (optional)
RateLimitMiddleware(..., errorHandler: ErrorHandler)- autowired by the DI extensionSabservis\Api\Utils\JsonDecoder::decode()- 64-bit-safe JSON decodingRouter::routeSignature()- route shape used for duplicate detectionSchema::addSecurityScheme()/getSecuritySchemes(),Schema::addTag(..., hidden:)