Skip to content

fix(client): security hardening - #430

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

david-ruiz-cko wants to merge 4 commits into
maintenance/4.3.xfrom
fix/INT-1919-security-hardening-4.3.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 4.3.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/Forward/ForwardClient.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 follows this line: Guzzle 6 and 7, PHPUnit 5.7 and 9, and psr/http-message 1.0, whose methods have no return types.
  • The PHP attribute is written on its own line before each parameter, and those signatures list one parameter per line, so the code loads on PHP 7.1 and the attribute 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.
  • ErrorHandlingTest::everySensitiveParameterIsMarked checks every method and class in lib/. It reads attributes, so it runs from PHP 8.0 and is skipped on 7.1 and 7.4.
  • \Throwable is 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 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.
  • The internal helpers follow describeFailure: static, @internal, in CheckoutUtils, and each returns null instead of throwing, so error handling cannot fail while it builds its own error.
  • 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.
  • 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.
  • Most of the size is the test file, one case per input shape; the library change is about 530 lines across 23 files, mostly parameter attributes on their own lines.

API Reference

None.

Breaking changes

None in the public API (the five new CheckoutUtils helpers are @internal). Behaviour changes (patch release):

  • 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, with its class (and the transport error number when there is one). Before, it reached the caller unwrapped. Migration: catch CheckoutException (or CheckoutApiException).
  • 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. 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.
  • 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.
  • 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 value passed to secretKey() that is neither a string nor an object with __toString fails with CheckoutArgumentException (the invalid key message) instead of a TypeError. Migration: none.
  • A request header value the HTTP client cannot send fails before the request with CheckoutApiException, as before, with the message Checkout\CheckoutArgumentException: Invalid header value. Migration: none.
  • An authorization value that is not text (for example null or an array) 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 the previous and custom platforms a number or an object with __toString is sent as its text; before, the HTTP client refused an object. Migration: none.
  • 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. The SDK's own clients always pass a request. 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.
  • A response whose body cannot be read as text gives a result without data on success, and invalid access token response for 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 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/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 over lib/. Cases that depend on the PHP or psr/http-message version are skipped where they cannot apply.

Related

None.

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.
@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: 27


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: Looks good to me

This 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 #[\SensitiveParameter] attributes throughout the SDK, hardens error handling by catching \Throwable instead of \Exception, validates credentials/headers before use, strips cookies from exception metadata, and cleans up error messages to avoid leaking sensitive data. The diff matches the stated intent and the logic looks correct.

What I checked

  • The body serialization move in ApiClient::post/put/patch (bodies now passed raw to invoke rather than pre-serialized) needs invoke to handle serialization — the truncated diff doesn't show invoke's body, so this cannot be fully verified, but the PR description states it was moved inside error handling on the main line.
  • In OAuthSdkCredentials::tokenFailureMessage, CheckoutUtils::bodyOf($response) returns string|null, and (string)null produces "", so json_decode("", true) returns null — the null-coalescing path works correctly, no bug here.
  • The plainHeaderName cookie-stripping logic in CheckoutApiException uses a character loop rather than a regex, which is correct per the design notes and avoids ReDoS; the approach is sound.
  • The describeFailure path that checks strpos($failure->getFile(), __DIR__ . DIRECTORY_SEPARATOR) === 0 correctly scopes SDK-authored messages to files under lib/Checkout/, including this helper itself — the assumption holds as long as the helper stays in that directory.
  • The SdkAuthorization::getAuthorizationHeader refactor adds validation that the credential is text before returning, which is a behaviour change (previously non-string credentials would silently produce a broken header); this is the intended hardening.
  • The CheckoutAuthorizationException::invalidAuthorization change uses get_class_vars(AuthorizationType::class) to enumerate known types — this works correctly for a class of static public properties and does not expose sensitive data in the message.
  • The Docker script change correctly limits passed env vars to the explicit list and uses ${ENV_ARGS[@]+"${ENV_ARGS[@]}"} to safely handle an empty array in bash, avoiding word-splitting issues.
  • The OAuthIntegrationTest assertion change from a substring match to an exact equality match on the cURL error message is intentional and correct per the new message format, but it makes the test brittle to Guzzle version differences in error numbering — acceptable for a controlled CI environment.
  • The large new ErrorHandlingTest file uses @before rather than setUp for compatibility with PHPUnit 5.7, consistent with the stated PHPUnit version range.

⚠️ 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: 27


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: 27


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: 27


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