Repository navigation
fix(client): security hardening - #431
david-ruiz-cko wants to merge 4 commits into
Conversation
Backport the security hardening of the main line to the 3.2.x line: input validation of request headers and improved error handling of the API client, the OAuth token request and CheckoutApiException. The test script passes the container only the variables the workflows set.
🔴 Risk Classification: MAJORApproval route: AI Review + Human Approval Required Classification reasons
Operational gates
Files analysed: 35 wall-e 2026.06.19-02 · policy |
🔬 Debug — why this classification?Each reason code emitted by the classifier, its source clause in the AI in SDLC Control Framework, and what it means.
Kinds:
See issue #3 for the proposal to formalise this map as Appendix A of the standards doc. wall-e 2026.06.19-02 · debug |
🟠 Advisory review: Concerns worth a lookThis PR needs a human approval. Before you give it, these are the things I'd want resolved. This is a broad security hardening PR adding Concerns
This is not an approval. wall-e cannot auto-approve this PR — it is an opinion to help whoever does. Advisory review · us.anthropic.claude-sonnet-4-6 · wall-e 2026.06.19-02 |
🔴 Risk Classification: MAJORApproval route: AI Review + Human Approval Required Classification reasons
Operational gates
Files analysed: 35 wall-e 2026.06.19-02 · policy |
🔬 Debug — why this classification?Each reason code emitted by the classifier, its source clause in the AI in SDLC Control Framework, and what it means.
Kinds:
See issue #3 for the proposal to formalise this map as Appendix A of the standards doc. wall-e 2026.06.19-02 · debug |
🔴 Risk Classification: MAJORApproval route: AI Review + Human Approval Required Classification reasons
Operational gates
Files analysed: 35 wall-e 2026.06.19-02 · policy |
🔬 Debug — why this classification?Each reason code emitted by the classifier, its source clause in the AI in SDLC Control Framework, and what it means.
Kinds:
See issue #3 for the proposal to formalise this map as Appendix A of the standards doc. wall-e 2026.06.19-02 · debug |
🔴 Risk Classification: MAJORApproval route: AI Review + Human Approval Required Classification reasons
Operational gates
Files analysed: 35 wall-e 2026.06.19-02 · policy |
🔬 Debug — why this classification?Each reason code emitted by the classifier, its source clause in the AI in SDLC Control Framework, and what it means.
Kinds:
See issue #3 for the proposal to formalise this map as Appendix A of the standards doc. wall-e 2026.06.19-02 · debug |
|



Summary
Security hardening of the SDK builders, credentials, API client, error handling and several clients on the 3.2.x line, as released on the main line. No changes to the public API;
CheckoutUtilsgains five static helpers marked@internal.Changes
lib/Checkout/ApiClient.php: security hardening, input validation of request headers and improved error handling; request bodies are serialized inside the error handling.lib/Checkout/SdkAuthorization.php: security hardening and input validation.lib/Checkout/CheckoutUtils.php: new internal helpersdescribeFailure,responseOf,statusOf,bodyOfandcontentsOffor error messages, log lines and response reads.lib/Checkout/CheckoutApiException.php: security hardening ofhttp_metadataanderror_details; improved error handling when the response cannot be read; property docs.lib/Checkout/OAuthSdkCredentials.php: security hardening and improved error handling.lib/Checkout/AbstractStaticKeysCheckoutSdkBuilder.php: security hardening and input validation.lib/Checkout/CheckoutAuthorizationException.php:invalidAuthorizationnames only known authorization types.lib/Checkout/CheckoutConfiguration.php,lib/Checkout/OAuthAccessToken.php,lib/Checkout/AbstractStaticKeysSdkCredentials.php,lib/Checkout/StaticKeysSdkCredentials.php,lib/Checkout/Previous/PreviousStaticKeysSdkCredentials.php,lib/Checkout/Sessions/SessionSecretSdkCredentials.php: security hardening.lib/Checkout/CheckoutOAuthSdkBuilder.php,lib/Checkout/CheckoutStaticKeysSdkBuilder.php,lib/Checkout/Previous/CheckoutStaticKeysPreviousSdkBuilder.php: security hardening.lib/Checkout/CheckoutApi.php,lib/Checkout/Previous/CheckoutApi.php: security hardening.lib/Checkout/Sessions/SessionsClient.php,lib/Checkout/Issuing/IssuingClient.php,lib/Checkout/Workflows/WorkflowsClient.php,lib/Checkout/Webhooks/Previous/WebhooksClient.php: security hardening.README.md:http_metadatadescribed..github/scripts/phpunit-in-docker.sh: passes the container only the variables the workflows set, and runs when none of them is set.Design notes:
CHECKOUT_*variable of the calling shell, so a local run sees what CI sees.array(),issetinstead of??, and a private static list instead of a private constant array.\Throwable, so each request is guarded bycatch (\Exception)and thencatch (\Throwable). A catch that names a class which does not exist is valid on 5.6. Both share one privateApiClient::failure()so that the log line and the message stay the same.error_details.ApiClient::getHeaders, the one place headers are built.__toStringis a fatal error that no catch can handle. The caller gets the sameCheckoutApiExceptionas when the HTTP client refused it before.contentsOf(rewind()andgetContents()), and the result is used only when it is text, because an exception inside__toString()cannot be caught before PHP 7.4. Thetext/csvcheck is strict for the same reason. The other internal helpers followdescribeFailure: static,@internal, inCheckoutUtils, and each returnsnullinstead of throwing.http_metadata; the metadata of successful responses is unchanged.http_metadatais built from any PSR-7 response, and isnullwhen one of its values cannot be read or is not of the documented type. The header name check is a character loop, not a regular expression.test/Checkout/Tests/.lib/, mostly parameter attributes on their own lines; most of the rest is the test file, one case per input shape.API Reference
None.
Breaking changes
None in the public API (the five new
CheckoutUtilshelpers are@internal). Behaviour changes (patch release):CheckoutApiExceptionraised for a failure without an HTTP response has the message<failure class>followed by(cURL error N)when the transport gives one, or<SDK exception class>: <message>for errors the SDK raises itself. Before, the message was the whole failure rendered as text. With Guzzle 6, a connection failure keeps the status message with(0), as before. Migration: none, unless code parsed the message.CheckoutExceptionwithOAuth token request failed with status N, plus the OAuth error code (for example(invalid_client)) when the server returns a standard one, orOAuth token request failed: <failure class> (cURL error N). Before, the message was the HTTP client's. Migration: none, unless code parsed the message.\Errorraised while a request is sent (for example aTypeErrorfrom an HTTP client option or the serializer) is wrapped inCheckoutApiException, and during the OAuth token request inCheckoutException. Before, it reached the caller unwrapped. Migration: catchCheckoutException(orCheckoutApiException).CheckoutApiException, with the messageCheckout\CheckoutArgumentException: Invalid header value. Migration: none.nullor an array), or an empty list on the previous and custom platforms, fails before the request withCheckoutApiException. Before, it was sent without a usable value, so the request could not authenticate; none of the SDK's own credential classes produces such a value. On those platforms a number or an object with__toStringis sent as its text. Migration: none.CheckoutAuthorizationException::invalidAuthorization()called with a value that is not one of theAuthorizationTypevalues givesOperation requires a supported authorization type; the SDK itself passes only those values. Migration: none.secretKey()that is neither a string nor an object with__toStringfails withCheckoutArgumentException(the invalid key message). Migration: none.CheckoutApiException::$http_metadatano longer lists theSet-CookieandSet-Cookie2headers of the failed response. The API does not use cookies, so they are not part of its error data. Migration: none.CheckoutApiException::$http_metadatais set for a PSR-7 response other than Guzzle's and isnullwhen the response's values cannot be read;error_detailsis an empty array when the body cannot be read. Before, the read error reached the caller. Migration: none.<path> error:followed by the same description, and the info log line for a file upload isPOST <path>. Migration: none, unless code parsed the log.putorpatchcall onApiClientwith anullbody sends the request with no body, aspostdoes and as on the main line. Before, it failed with an unwrappedTypeError. Migration: none.Content-Typecannot be read as text gives a result withhttp_metadataonly, and the OAuth token request givesinvalid access token response. Before, the value was converted, which could stop PHP below 7.4. Migration: none.Tests
Existing tests pass (
bash .github/scripts/phpunit-in-docker.sh <v>on PHP 5.6 and 8.1: every error is a sandbox test without credentials; phpstan clean on 8.1;ErrorHandlingTestalso on 7.1, 7.4 and 8.4)Serialization tests cover every new or changed property (no request or response type changes)
README updated if documented usage changed
test/Checkout/Tests/OAuthIntegrationTest.php: expected messages of the failed token requests updated; the OAuth payment allocates its amount to the sub-entity withamount_allocationsinstead of themarketplaceobject, which the payment request no longer has in the API and the sandbox now refuses.test/Checkout/Tests/SandboxTestFixture.php:retriabletakes its optional predicate untyped (documentedcallable|null), so the fixture loads without a deprecation on PHP 8.4.test/Checkout/Tests/ErrorHandlingTest.php(new) and its test doubles: errors and log lines of the builders, the OAuth token request, failed API requests with each kind of key, the sessions, Issuing, Workflows and webhooks clients, custom header values (objects and nested lists included), response metadata with and without cookies, responses that cannot be read, and values of many shapes; and the check overlib/. Cases that depend on the PHP or psr/http-message version are skipped where they cannot apply, and each runs on at least one CI leg.Related
None.