Repository navigation
fix(client): security hardening - #430
david-ruiz-cko wants to merge 4 commits into
Conversation
Backport the security hardening of the main line to the 4.3.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: 27 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: Looks good to meThis PR still needs a human approval — wall-e cannot auto-approve it. For what it's worth, I read the diff and found nothing I'd block on. This PR adds What I checked
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: 27 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: 27 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: 27 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 4.3.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/Forward/ForwardClient.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.ErrorHandlingTest::everySensitiveParameterIsMarkedchecks every method and class inlib/. It reads attributes, so it runs from PHP 8.0 and is skipped on 7.1 and 7.4.\Throwableis caught, not only\Exception, so every failure raised while a request is sent reaches the caller as an SDK exception. Request bodies are serialized inside that handling, as on the main line.error_details.ApiClient::getHeaders, the one place headers are built.describeFailure: static,@internal, inCheckoutUtils, and each returnsnullinstead of throwing, so error handling cannot fail while it builds its own error.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.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.API Reference
None.
Breaking changes
None in the public API (the five new
CheckoutUtilshelpers are@internal). Behaviour changes (patch release):\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, with its class (and the transport error number when there is one). Before, it reached the caller unwrapped. Migration: catchCheckoutException(orCheckoutApiException).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. 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.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.<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.secretKey()that is neither a string nor an object with__toStringfails withCheckoutArgumentException(the invalid key message) instead of aTypeError. Migration: none.CheckoutApiException, as before, with the messageCheckout\CheckoutArgumentException: Invalid header value. Migration: none.nullor an array) 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 the previous and custom platforms a number or an object with__toStringis sent as its text; before, the HTTP client refused an object. Migration: none.putorpatchcall onApiClientwith anullbody sends the request with no body, aspostdoes and as on the main line. Before, it failed with an unwrappedTypeError. The SDK's own clients always pass a request. 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.invalid access token responsefor the OAuth token request. Migration: none.Tests
Existing tests pass (
bash .github/scripts/phpunit-in-docker.sh <v>on PHP 7.1, 7.4, 8.1 and 8.4: phpstan clean, every error is a sandbox test without credentials, the same set as the unchanged line; phpcs clean)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/ErrorHandlingTest.php(new): errors and log lines of the builders, the OAuth token request, failed API requests with each kind of key, the sessions, Issuing, Forward, Workflows and webhooks clients, custom header values, 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.Related
None.