Skip to content

fix(client): security hardening - #429

Open
david-ruiz-cko wants to merge 5 commits into
masterfrom
fix/INT-1919-security-hardening
Open

david-ruiz-cko wants to merge 5 commits into
masterfrom
fix/INT-1919-security-hardening

Conversation

@david-ruiz-cko

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

Copy link
Copy Markdown
Contributor

Summary

Security hardening and improved error handling of CheckoutApiException, the OAuth token request and the API client logs. No changes to the public API; CheckoutUtils gains three static helpers marked @internal, as describeFailure is.

Changes

  • 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/CheckoutUtils.php: new internal helpers responseOf, statusOf and bodyOf, used by error handling; describeFailure uses them.
  • lib/Checkout/OAuthSdkCredentials.php: improved error handling of the token request; unused import removed.
  • lib/Checkout/ApiClient.php: security hardening of a log line.
  • README.md: http_metadata described.

Design notes:

  • The helpers follow describeFailure: static, @internal, in CheckoutUtils, because the exception, the OAuth credentials and the API client read a failed response the same way. Each one returns null instead of throwing, so error handling cannot fail while it builds its own error.
  • Bodies are read with rewind() and getContents(), and the result is used only when it is text. The same code is backported to the maintenance lines, where an exception inside __toString() cannot be caught before PHP 7.4.
  • Cookies are removed only from the exception's http_metadata; getHttpMetadata and the metadata of successful responses are unchanged.
  • CheckoutApiException builds its metadata itself instead of calling CheckoutUtils::getHttpMetadata: it takes any PSR-7 response, leaves the cookies out, checks the type of each value and never throws, while getHttpMetadata is public, takes Guzzle's response and keeps every header of successful responses. Merging them would change that public method.
  • http_metadata is built from any PSR-7 response, not only Guzzle's, 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, so it ignores padding or control characters in a name without a pattern on response data.

API Reference

None.

Breaking changes

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

  • 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; there is no compatible way to keep a header and leave it out. Migration: none.
  • CheckoutApiException::$http_metadata is now set for an HTTP client that returns a PSR-7 response other than Guzzle's, and is null when the response's values cannot be read. Before, building it failed. Migration: none.
  • When the body of a failed response cannot be read, error_details is an empty array and the exception is still raised. Before, the read error reached the caller. Migration: none.
  • A failed OAuth token request whose response cannot be read raises CheckoutException, as for any other token failure. Migration: none.
  • The SDK's info log line for a file upload is POST <path>. Migration: none, unless code parsed the log.

Tests

  • Existing tests pass (vendor/bin/phpunit on PHP 8.4: 1793 tests, 0 failures, 0 deprecations; phpcs and phpstan 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: 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: failed responses that cannot be read, a response with a text status code, a failed token request with an unreadable body, response headers kept with and without cookies, metadata of another PSR-7 response, the status taken from the response, and the upload log line. Most of the added lines are those response fixtures.

Related

None.

Improve error handling of CheckoutApiException, the OAuth token request and
the API client logs, so a failed response is described without copying data
the SDK does not control.
@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/OAuthSdkCredentials.php

Operational gates

  • ✅ jira_ticket (PSR-7)
  • ✅ independent_review

Files analysed: 6


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/OAuthSdkCredentials.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.

Security hardening that removes file paths and cookie headers from logs/exceptions, improves error handling for unreadable responses, and fixes an OAuth integration test to use amount_allocations instead of the deprecated marketplace object. The changes are defensive, internally consistent, and well-tested.

What I checked

  • The file path removal from the upload log line (POST <path> instead of POST <path> file: <filepath>) is a correct security fix that matches the README and test coverage.
  • The plainHeaderName character-loop approach for cookie header filtering is correctly case-insensitive and strips control/padding characters before comparison, covering the unicode zero-width space and CRLF injection cases tested in errorMetadataOfAnotherPsr7ResponseIsKeptWithoutCookies.
  • The bodyOf helper correctly uses rewind() + getContents() instead of __toString() to avoid uncatchable exceptions on older PHP, and returns null on any Throwable so body reading cannot propagate into error construction.
  • json_decode((string)CheckoutUtils::bodyOf($response), true) in tokenFailureMessage casts null to the empty string "", which json_decode returns null for — this is safe because the subsequent is_array($body) check handles it correctly.
  • The move of $body = json_decode(...) inside the try-catch in OAuthSdkCredentials::getAccessToken is correct: a body-read failure now raises CheckoutException rather than propagating raw.
  • The statusOf helper's is_int($status) guard correctly handles PSR-7 1.0 implementations that may return non-integer values without return types declared.
  • The metadataWithoutCookies method returns null when any of reason/status/protocol are wrong types, which is consistent with the stated contract and tested by errorMetadataIsLeftEmptyWhenItsHeadersCannotBeRead.
  • The describeFailure refactor to use self::statusOf(self::responseOf($failure)) is correct and no longer calls getResponse() twice or accesses getStatusCode() without null-guarding.
  • The OAuth integration test change from MarketplaceData/marketplace to AmountAllocations/amount_allocations is appropriate given the sandbox now rejects the old field, and the allocation amount of 10 matches the payment amount.

⚠️ 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 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/OAuthSdkCredentials.php

Operational gates

  • ✅ jira_ticket (PSR-7)
  • ✅ independent_review

Files analysed: 6


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/OAuthSdkCredentials.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/OAuthSdkCredentials.php
  • security_sensitive_path:test/Checkout/Tests/OAuthIntegrationTest.php

Operational gates

  • ✅ jira_ticket (PSR-7)
  • ✅ independent_review

Files analysed: 7


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/OAuthSdkCredentials.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/OAuthSdkCredentials.php
  • security_sensitive_path:test/Checkout/Tests/OAuthIntegrationTest.php

Operational gates

  • ✅ jira_ticket (PSR-7)
  • ✅ independent_review

Files analysed: 7


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/OAuthSdkCredentials.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/OAuthSdkCredentials.php
  • security_sensitive_path:test/Checkout/Tests/OAuthIntegrationTest.php

Operational gates

  • ✅ jira_ticket (PSR-7)
  • ✅ independent_review

Files analysed: 7


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/OAuthSdkCredentials.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