Skip to content

Release 2.11

Choose a tag to compare

@igorpocta igorpocta released this 03 Nov 07:54
· 1 commit to main since this release

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: true with 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 (no logDirectory, 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:::2 was accepted and could become the client IP from X-Forwarded-For); trusted-proxy matching canonicalizes IPv6 (2001:DB8::1 = 2001:db8::1) and IPv4-mapped IPv6 (::ffff:10.0.0.1 matches 10.0.0.0/8)
  • ErrorResponseBuilder matches sensitive context keys by whole words (camelCase / snake_case / kebab-case): passwordHash, pinCode, api_key, x-auth-token are still removed, but author, issuingAuthority, shipping, pinned, hashtags validation 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 to PHP_INT_MIN with a 200
  • BasicAuthMiddleware: scheme name is case-insensitive per RFC 7235 (basic works), Basicx <token> is rejected
  • CORS: a request without Origin against an origin whitelist gets no CORS headers (used to send Access-Control-Allow-Origin: * next to Allow-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/anyOf variant restricts its discriminator property to its mapped value(s) (strict validators no longer see ambiguous oneOf); the variant property keeps description / nullable / example / deprecated; numeric-string mapping keys ('1') stay strings for string properties
  • #[QueryParameter(schema: new Schema(...))] is converted fully - items, minItems / maxItems, uniqueItems, description, composition - and format: on the attribute is written to the spec (format: date restricts DateTime parameters to YYYY-MM-DD at runtime too)
  • Explicit parameter type: wins over the schema type for runtime conversion
  • #[SecurityScheme] on a controller is now written to components.securitySchemes (it was silently ignored); config entries with the same name win; flows (oauth2) and openIdConnectUrl are no longer dropped from configured schemes
  • #[Tag(hidden: true)] hides the tag from tags and from operations (the built-in OpenApiController tag no longer leaks)
  • #[Alias] endpoints get a generated operationId instead of copying the explicit one (ids must be unique)
  • #[OpenApiMerge] deep-merges into generated responses / request bodies (adding headers to 200 keeps its description and content)
  • Unused-schema filter follows discriminator.mapping and component names containing - or . (no more dangling $ref)
  • #[Response(ref: SomeInterface::class)] produces a schema; JsonContent(properties: [Property(required: true)]) emits the required list; multipart array properties are type: array, items: string, nullable scalars get nullable: true; exclusiveMinimum / exclusiveMaximum / uniqueItems pass 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; DateTime properties parse the form value; nested object without a configured serializer is a clear RuntimeStateException
  • Mutable \DateTime controller arguments no longer TypeError (createFromInterface)
  • Variadic controller arguments (string ...$tags) no longer 500 on getDefaultValue()
  • ApiTestClient closes its output buffer when the application throws (PHPUnit "risky" tests, shifted buffers)
  • FileResponse sends Content-Length: 0 for empty files
  • ApiExtension compiles without a productionMode parameter (no "Undefined array key" warning)
  • RequestUri::getPath() / getQuery() and ApiRequest::getPath() share one implementation

New (optional)

  • RateLimitMiddleware(..., errorHandler: ErrorHandler) - autowired by the DI extension
  • Sabservis\Api\Utils\JsonDecoder::decode() - 64-bit-safe JSON decoding
  • Router::routeSignature() - route shape used for duplicate detection
  • Schema::addSecurityScheme() / getSecuritySchemes(), Schema::addTag(..., hidden:)