Skip to content

fix(client): security hardening - #431

Open
david-ruiz-cko wants to merge 4 commits into
maintenance/3.2.xfrom
fix/INT-1919-security-hardening-3.2.x
Open

david-ruiz-cko wants to merge 4 commits into
maintenance/3.2.xfrom
fix/INT-1919-security-hardening-3.2.x

Conversation

@david-ruiz-cko

@david-ruiz-cko david-ruiz-cko commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

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; CheckoutUtils gains 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 helpers describeFailure, responseOf, statusOf, bodyOf and contentsOf for error messages, log lines and response reads.
  • lib/Checkout/CheckoutApiException.php: security hardening of http_metadata and error_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: invalidAuthorization names 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_metadata described.
  • .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:

  • The test script lists the variables the workflows set instead of passing every CHECKOUT_* variable of the calling shell, so a local run sees what CI sees.
  • The change follows the main line file by file. Where this line differs, the code is written for PHP 5.6: no parameter or return types, array(), isset instead of ??, and a private static list instead of a private constant array.
  • PHP 5.6 has no \Throwable, so each request is guarded by catch (\Exception) and then catch (\Throwable). A catch that names a class which does not exist is valid on 5.6. Both share one private ApiClient::failure() so that the log line and the message stay the same.
  • The PHP attribute is written on its own line before each parameter, and those signatures list one parameter per line, so PHP 5.6 and 7 read it as a comment and it applies from PHP 8.2.
  • Parameters that carry credentials are marked, including the request and header objects that contain them. Credentials are covered, not payment data.
  • Error messages and log lines repeat only text the SDK controls: the messages of exceptions the SDK raises itself, a failure's class, the HTTP status, the transport error number and the standard OAuth error code. For API requests the response body stays available in error_details.
  • Header values the HTTP client cannot send are refused before the request, in ApiClient::getHeaders, the one place headers are built.
  • A header value that is not scalar (for example an object or a nested list as idempotency key, which this line does not type) is refused before the check casts it to text: below PHP 8, casting an object without __toString is a fatal error that no catch can handle. The caller gets the same CheckoutApiException as when the HTTP client refused it before.
  • Bodies are read through contentsOf (rewind() and getContents()), and the result is used only when it is text, because an exception inside __toString() cannot be caught before PHP 7.4. The text/csv check is strict for the same reason. The other internal helpers follow describeFailure: static, @internal, in CheckoutUtils, and each returns null instead of throwing.
  • Cookies are removed only from the exception's http_metadata; the metadata of successful responses is unchanged. http_metadata is built from any PSR-7 response, and is null when 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.
  • PHP 5.6 has no anonymous classes, so the test doubles are small named classes, one file each, under test/Checkout/Tests/.
  • Size: this backports two changes of the main line in one PR, about 780 changed lines in 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 CheckoutUtils helpers are @internal). Behaviour changes (patch release):

  • A CheckoutApiException raised 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.
  • A failed OAuth token request raises CheckoutException with OAuth token request failed with status N, plus the OAuth error code (for example (invalid_client)) when the server returns a standard one, or OAuth token request failed: <failure class> (cURL error N). Before, the message was the HTTP client's. Migration: none, unless code parsed the message.
  • On PHP 7 and later, an \Error raised while a request is sent (for example a TypeError from an HTTP client option or the serializer) is wrapped in CheckoutApiException, and during the OAuth token request in CheckoutException. Before, it reached the caller unwrapped. Migration: catch CheckoutException (or CheckoutApiException).
  • A request header value the HTTP client cannot send fails before the request with CheckoutApiException, with the message Checkout\CheckoutArgumentException: Invalid header value. Migration: none.
  • An authorization value that is not text (for example null or an array), or an empty list on the previous and custom platforms, fails before the request with CheckoutApiException. 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 __toString is sent as its text. Migration: none.
  • CheckoutAuthorizationException::invalidAuthorization() called with a value that is not one of the AuthorizationType values gives Operation requires a supported authorization type; the SDK itself passes only those values. Migration: none.
  • A value passed to secretKey() that is neither a string nor an object with __toString fails with CheckoutArgumentException (the invalid key message). Migration: none.
  • CheckoutApiException::$http_metadata no longer lists the Set-Cookie and Set-Cookie2 headers of the failed response. The API does not use cookies, so they are not part of its error data. Migration: none.
  • CheckoutApiException::$http_metadata is set for a PSR-7 response other than Guzzle's and is null when the response's values cannot be read; error_details is an empty array when the body cannot be read. Before, the read error reached the caller. Migration: none.
  • The SDK's error log line for a failed request is <path> error: followed by the same description, and the info log line for a file upload is POST <path>. Migration: none, unless code parsed the log.
  • A put or patch call on ApiClient with a null body sends the request with no body, as post does and as on the main line. Before, it failed with an unwrapped TypeError. Migration: none.
  • A successful response whose body or Content-Type cannot be read as text gives a result with http_metadata only, and the OAuth token request gives invalid 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; ErrorHandlingTest also 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 with amount_allocations instead of the marketplace object, which the payment request no longer has in the API and the sandbox now refuses.

  • test/Checkout/Tests/SandboxTestFixture.php: retriable takes its optional predicate untyped (documented callable|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 over lib/. 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.

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.
@david-ruiz-cko
david-ruiz-cko requested a review from a team December 3, 2026 10:18
@agent-wall-e

agent-wall-e Bot commented Dec 3, 2026

Copy link
Copy Markdown

🔴 Risk Classification: MAJOR

Approval route: AI Review + Human Approval Required
Rollback controls: Change-freeze window + documented rollback plan

Classification reasons

  • security_sensitive_path:lib/Checkout/OAuthAccessToken.php
  • security_sensitive_path:lib/Checkout/OAuthSdkCredentials.php
  • security_sensitive_path:lib/Checkout/Sessions/SessionSecretSdkCredentials.php
  • security_sensitive_path:lib/Checkout/Sessions/SessionsClient.php
  • security_sensitive_path:test/Checkout/Tests/OAuthIntegrationTest.php

Operational gates

  • ✅ jira_ticket (PSR-7)
  • ✅ independent_review

Files analysed: 35


wall-e 2026.06.19-02 · policy 6b4ce2b3b45a…

@agent-wall-e

agent-wall-e Bot commented Dec 3, 2026

Copy link
Copy Markdown
🔬 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.

Reason code Kind Clause Meaning
security_sensitive_path — lib/Checkout/OAuthAccessToken.php classifying §2.1 M4/M5 Path matched a sensitive pattern (auth, secrets, crypto, PCI, migrations, network IaC).
security_sensitive_path — lib/Checkout/OAuthSdkCredentials.php classifying §2.1 M4/M5 Path matched a sensitive pattern (auth, secrets, crypto, PCI, migrations, network IaC).
security_sensitive_path — lib/Checkout/Sessions/SessionSecretSdkCredentials.php classifying §2.1 M4/M5 Path matched a sensitive pattern (auth, secrets, crypto, PCI, migrations, network IaC).
security_sensitive_path — lib/Checkout/Sessions/SessionsClient.php classifying §2.1 M4/M5 Path matched a sensitive pattern (auth, secrets, crypto, PCI, migrations, network IaC).
security_sensitive_path — test/Checkout/Tests/OAuthIntegrationTest.php classifying §2.1 M4/M5 Path matched a sensitive pattern (auth, secrets, crypto, PCI, migrations, network IaC).

Kinds:

  • classifying — this rule contributed to the chosen tier.
  • informational — context only; did not by itself decide the tier.

See issue #3 for the proposal to formalise this map as Appendix A of the standards doc.

wall-e 2026.06.19-02 · debug

@agent-wall-e

agent-wall-e Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

🟠 Advisory review: Concerns worth a look

This 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 #[\SensitiveParameter] attributes, improved error handling, input validation, and a large test file; the changes are generally correct but there is one concrete logic bug in OAuthSdkCredentials::tokenFailureMessage and a potential behaviour change in SdkAuthorization::getAuthorizationHeader that could break existing callers.

Concerns

  • In OAuthSdkCredentials::tokenFailureMessage, CheckoutUtils::bodyOf($response) returns string|null, but the code does (string)CheckoutUtils::bodyOf($response) — when bodyOf returns null, this produces the string "null", which then gets passed to json_decode. json_decode("null", true) returns PHP null, not an array, so the is_array($body) guard saves the error code path, but the cast is still misleading and inconsistent with how bodyOf is used elsewhere (the diff shows bodyOf returning null to signal unreadable, not "null").
  • In SdkAuthorization::getAuthorizationHeader, the previous code for PlatformType::$previous/$custom returned the credential directly without validation; the new code throws CheckoutAuthorizationException if the credential is not a string or non-empty string array. This is a breaking behaviour change for any caller passing a non-string credential on those platform types — the PR description does not list this as a behaviour change, and no migration note is given.
  • In CheckoutApiException::from, the diff moves serialization out of post/put/patch (those methods now pass $body raw to invoke), but the truncated diff does not show how invoke handles the unserialised body — if serialization was moved into invoke/failure, this needs verification that the body is still serialized exactly once and in the right place.
  • In CheckoutUtils::describeFailure, the __DIR__ . DIRECTORY_SEPARATOR check for SDK-owned exceptions relies on file-system path prefix matching, which could be fooled by a directory named lib/Checkout outside the SDK being on the include path, or by symlinks; this is a minor trust boundary issue worth noting.
  • The plainHeaderName loop in CheckoutApiException correctly strips non-alphanumeric/hyphen characters from header names before the set-cookie check, but if a PSR-7 implementation returns header names as numeric keys (which is non-conformant but possible), strtolower((string)$name) on an integer produces the integer as a string — this is harmless but worth confirming the assumption holds for the HTTP client in use.
  • The ErrorHandlingStringableKey test double's __toString injects \r\nX: y after $cleanReads reads, but $cleanReads === 0 is documented as 'returns $text on every read' — the condition $this->cleanReads === 0 || $this->reads++ < $this->cleanReads is correct for that, so this is fine.
  • The OAuthIntegrationTest hardcodes a sub-entity ID (ent_ocw5i74vowfg2edpy66izhts2u) and processing channel ID (pc_a6dabcfa2o3ejghb3sjuotdzzy) — these are sandbox-specific values that will silently make the integration test pass or fail depending on the sandbox state, not a blocker but worth flagging for the reviewer.

⚠️ The diff was too large to read in full, so this review covers only part of the change.


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

@agent-wall-e

agent-wall-e Bot commented Dec 4, 2026

Copy link
Copy Markdown

🔴 Risk Classification: MAJOR

Approval route: AI Review + Human Approval Required
Rollback controls: Change-freeze window + documented rollback plan

Classification reasons

  • security_sensitive_path:lib/Checkout/OAuthAccessToken.php
  • security_sensitive_path:lib/Checkout/OAuthSdkCredentials.php
  • security_sensitive_path:lib/Checkout/Sessions/SessionSecretSdkCredentials.php
  • security_sensitive_path:lib/Checkout/Sessions/SessionsClient.php
  • security_sensitive_path:test/Checkout/Tests/OAuthIntegrationTest.php

Operational gates

  • ✅ jira_ticket (PSR-7)
  • ✅ independent_review

Files analysed: 35


wall-e 2026.06.19-02 · policy 6b4ce2b3b45a…

@agent-wall-e

agent-wall-e Bot commented Dec 4, 2026

Copy link
Copy Markdown
🔬 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.

Reason code Kind Clause Meaning
security_sensitive_path — lib/Checkout/OAuthAccessToken.php classifying §2.1 M4/M5 Path matched a sensitive pattern (auth, secrets, crypto, PCI, migrations, network IaC).
security_sensitive_path — lib/Checkout/OAuthSdkCredentials.php classifying §2.1 M4/M5 Path matched a sensitive pattern (auth, secrets, crypto, PCI, migrations, network IaC).
security_sensitive_path — lib/Checkout/Sessions/SessionSecretSdkCredentials.php classifying §2.1 M4/M5 Path matched a sensitive pattern (auth, secrets, crypto, PCI, migrations, network IaC).
security_sensitive_path — lib/Checkout/Sessions/SessionsClient.php classifying §2.1 M4/M5 Path matched a sensitive pattern (auth, secrets, crypto, PCI, migrations, network IaC).
security_sensitive_path — test/Checkout/Tests/OAuthIntegrationTest.php classifying §2.1 M4/M5 Path matched a sensitive pattern (auth, secrets, crypto, PCI, migrations, network IaC).

Kinds:

  • classifying — this rule contributed to the chosen tier.
  • informational — context only; did not by itself decide the tier.

See issue #3 for the proposal to formalise this map as Appendix A of the standards doc.

wall-e 2026.06.19-02 · debug

@agent-wall-e

agent-wall-e Bot commented Dec 4, 2026

Copy link
Copy Markdown

🔴 Risk Classification: MAJOR

Approval route: AI Review + Human Approval Required
Rollback controls: Change-freeze window + documented rollback plan

Classification reasons

  • security_sensitive_path:lib/Checkout/OAuthAccessToken.php
  • security_sensitive_path:lib/Checkout/OAuthSdkCredentials.php
  • security_sensitive_path:lib/Checkout/Sessions/SessionSecretSdkCredentials.php
  • security_sensitive_path:lib/Checkout/Sessions/SessionsClient.php
  • security_sensitive_path:test/Checkout/Tests/OAuthIntegrationTest.php

Operational gates

  • ✅ jira_ticket (PSR-7)
  • ✅ independent_review

Files analysed: 35


wall-e 2026.06.19-02 · policy 6b4ce2b3b45a…

@agent-wall-e

agent-wall-e Bot commented Dec 4, 2026

Copy link
Copy Markdown
🔬 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.

Reason code Kind Clause Meaning
security_sensitive_path — lib/Checkout/OAuthAccessToken.php classifying §2.1 M4/M5 Path matched a sensitive pattern (auth, secrets, crypto, PCI, migrations, network IaC).
security_sensitive_path — lib/Checkout/OAuthSdkCredentials.php classifying §2.1 M4/M5 Path matched a sensitive pattern (auth, secrets, crypto, PCI, migrations, network IaC).
security_sensitive_path — lib/Checkout/Sessions/SessionSecretSdkCredentials.php classifying §2.1 M4/M5 Path matched a sensitive pattern (auth, secrets, crypto, PCI, migrations, network IaC).
security_sensitive_path — lib/Checkout/Sessions/SessionsClient.php classifying §2.1 M4/M5 Path matched a sensitive pattern (auth, secrets, crypto, PCI, migrations, network IaC).
security_sensitive_path — test/Checkout/Tests/OAuthIntegrationTest.php classifying §2.1 M4/M5 Path matched a sensitive pattern (auth, secrets, crypto, PCI, migrations, network IaC).

Kinds:

  • classifying — this rule contributed to the chosen tier.
  • informational — context only; did not by itself decide the tier.

See issue #3 for the proposal to formalise this map as Appendix A of the standards doc.

wall-e 2026.06.19-02 · debug

@agent-wall-e

agent-wall-e Bot commented Dec 4, 2026

Copy link
Copy Markdown

🔴 Risk Classification: MAJOR

Approval route: AI Review + Human Approval Required
Rollback controls: Change-freeze window + documented rollback plan

Classification reasons

  • security_sensitive_path:lib/Checkout/OAuthAccessToken.php
  • security_sensitive_path:lib/Checkout/OAuthSdkCredentials.php
  • security_sensitive_path:lib/Checkout/Sessions/SessionSecretSdkCredentials.php
  • security_sensitive_path:lib/Checkout/Sessions/SessionsClient.php
  • security_sensitive_path:test/Checkout/Tests/OAuthIntegrationTest.php

Operational gates

  • ✅ jira_ticket (PSR-7)
  • ✅ independent_review

Files analysed: 35


wall-e 2026.06.19-02 · policy 6b4ce2b3b45a…

@agent-wall-e

agent-wall-e Bot commented Dec 4, 2026

Copy link
Copy Markdown
🔬 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.

Reason code Kind Clause Meaning
security_sensitive_path — lib/Checkout/OAuthAccessToken.php classifying §2.1 M4/M5 Path matched a sensitive pattern (auth, secrets, crypto, PCI, migrations, network IaC).
security_sensitive_path — lib/Checkout/OAuthSdkCredentials.php classifying §2.1 M4/M5 Path matched a sensitive pattern (auth, secrets, crypto, PCI, migrations, network IaC).
security_sensitive_path — lib/Checkout/Sessions/SessionSecretSdkCredentials.php classifying §2.1 M4/M5 Path matched a sensitive pattern (auth, secrets, crypto, PCI, migrations, network IaC).
security_sensitive_path — lib/Checkout/Sessions/SessionsClient.php classifying §2.1 M4/M5 Path matched a sensitive pattern (auth, secrets, crypto, PCI, migrations, network IaC).
security_sensitive_path — test/Checkout/Tests/OAuthIntegrationTest.php classifying §2.1 M4/M5 Path matched a sensitive pattern (auth, secrets, crypto, PCI, migrations, network IaC).

Kinds:

  • classifying — this rule contributed to the chosen tier.
  • informational — context only; did not by itself decide the tier.

See issue #3 for the proposal to formalise this map as Appendix A of the standards doc.

wall-e 2026.06.19-02 · debug

@sonarqubecloud

sonarqubecloud Bot commented Dec 4, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants