Skip to content

fix(client): set default timeouts and check the token status - #425

Open
rodrigojara-cko wants to merge 2 commits into
masterfrom
fix/INT-1852-default-http-timeouts
Open

rodrigojara-cko wants to merge 2 commits into
masterfrom
fix/INT-1852-default-http-timeouts

Conversation

@rodrigojara-cko

@rodrigojara-cko rodrigojara-cko commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The HTTP client the SDK creates had no timeout (Guzzle's default, wait forever), so a request to an API that accepted the connection and never answered kept the caller waiting with no limit. That client now has a 10 second connect timeout and a 60 second total timeout. The token response is also accepted only with status 200.

Changes

  • lib/Checkout/AbstractCheckoutSdkBuilder.php: the client the SDK creates gets connect_timeout 10 and timeout 60 (DEFAULT_CONNECT_TIMEOUT_SECONDS, DEFAULT_TIMEOUT_SECONDS); a builder set with httpClientBuilder() keeps its own options.
  • lib/Checkout/OAuthSdkCredentials.php: a token response with a status other than 200 throws CheckoutAuthorizationException; its message comes from tokenStatusMessage(), now shared with tokenFailureMessage() ("OAuth token request failed with status ", plus the OAuth error code when the server sent one).
  • README.md: an "HTTP timeouts" section with the defaults, the exceptions and how to set other bounds; the custom CA client example sets timeouts.
  • Tests: test/Checkout/Tests/HttpClientTimeoutsTest.php (new), test/Checkout/Tests/OAuthTokenStatusTest.php (new), test/Checkout/Tests/HttpClientOptionsTest.php (docblock).

Design notes: the defaults go only on the client the SDK creates, never on a client the application configured. The token check accepts 200 only, the success status of a token response (RFC 6749 section 5.1), as the Java SDK does; with http_errors set to false the old code checked the body only. The status message has one source, tokenStatusMessage(), used both for an error status Guzzle throws and for one it returns. The exception type follows http_errors: with Guzzle's default (true) an error status is thrown by Guzzle and keeps the existing CheckoutException, as does any other failure of the request; with http_errors set to false the response comes back to the SDK, which throws CheckoutAuthorizationException like the existing invalid token response check. Guzzle's timeout is a total for the request, so 60 seconds also bounds a large upload or report download; the README says to pass a client with a longer timeout for those. A token request that times out keeps the existing CheckoutException and its message ("OAuth token request failed: GuzzleHttp\Exception\ConnectException (cURL error 28)"). DEFAULT_CONNECT_TIMEOUT_SECONDS and DEFAULT_TIMEOUT_SECONDS are public so a custom client can reuse them. The tests against a server that never answers use a 1 second client, to check how the error surfaces; the default values are checked on the client configuration.

API Reference

None. No request or response changes.

Breaking changes

None in the public signatures. Behaviour changes, released as a minor version (a correction of requests that could wait with no limit):

  • A request through the client the SDK creates that gets no answer now fails after the bound (10 s to connect, 60 s in total, sending and receiving the body included) with a CheckoutApiException, or a CheckoutException for a token request, instead of waiting with no limit. This cannot be kept compatible: the bound is the fix. Migration: to use other bounds, set a DefaultHttpClientBuilder with your own timeout and connect_timeout through httpClientBuilder().
  • A token response with a status other than 200 now throws CheckoutAuthorizationException, with any client: with http_errors set to false any such status, and with the default client a 2xx other than 200 or a 3xx that is not followed. These responses used to be accepted when the body looked valid. Kept strict because a token from a response that is not a success is not a valid token. Migration: none expected; the token endpoint answers 200 on success.

Tests

  • Existing tests pass
  • Serialization tests cover every new or changed property: not applicable, no request or response type changed
  • README updated if documented usage changed

The new tests check the defaults on the client the SDK creates (static keys, OAuth and the Previous platform), a custom client keeping its options, an API request and a token request against a local server that never answers (the client secret absent from the token error), token responses with nine statuses other than 200 rejected, a 400 keeping its OAuth error code, and 200 accepted.

Related

None.

@rodrigojara-cko
rodrigojara-cko requested a review from a team December 1, 2026 11:32
@agent-wall-e

agent-wall-e Bot commented Dec 1, 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/OAuthTokenStatusTest.php

Operational gates

  • ✅ jira_ticket (INT-1852)
  • ✅ independent_review

Files analysed: 7


wall-e 2026.06.19-02 · policy 6b4ce2b3b45a…

@agent-wall-e

agent-wall-e Bot commented Dec 1, 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/OAuthTokenStatusTest.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 1, 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.

Adds default connect/request timeouts to the SDK-created HTTP client and rejects non-200 token responses; the diff matches the stated intent and the new tests cover both behaviours correctly.

What I checked

  • The status-code check in OAuthSdkCredentials.php is placed after the try/catch block that catches Throwable, so a non-200 response (which Guzzle won't throw on because http_errors is false in the SDK's internal token request) is correctly caught and throws CheckoutAuthorizationException rather than being silently accepted.
  • The existing tokenFailureMessage path, which runs when Guzzle does throw (e.g. with http_errors defaulting to true in some configurations), now delegates to tokenStatusMessage — the refactor looks correct and the error-code extraction logic is preserved.
  • DEFAULT_CONNECT_TIMEOUT_SECONDS and DEFAULT_TIMEOUT_SECONDS are public constants, which matches the stated design goal of letting callers reference them when building custom clients.
  • The httpClientBuilder() override path correctly replaces the entire DefaultHttpClientBuilder (including its default-timeout options) rather than merging, so a caller-provided builder is used as-is — consistent with the documented behaviour.
  • The reflection-based test helper reads the private httpClientBuilder field to get the Guzzle client config; this is fragile against field renames but is acceptable in a test context and correctly validates the defaults.
  • The silent-server test uses a 1-second timeout and asserts elapsed < 10 seconds, giving a 10× safety margin — the timing assertion is not flaky under normal CI load.
  • OAuthTokenStatusTest uses MockHandler with http_errors=false, which is exactly the configuration the SDK's internal token client uses, making the status-check test representative of real behaviour.
  • The README example for a custom CA client now includes timeout values matching the new defaults, keeping the documentation consistent with the code.

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

@rodrigojara-cko
rodrigojara-cko force-pushed the fix/INT-1852-default-http-timeouts branch from 0dba770 to ee30642 Compare December 1, 2026 15:30
@agent-wall-e

agent-wall-e Bot commented Dec 1, 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/OAuthTokenStatusTest.php

Operational gates

  • ✅ jira_ticket (INT-1852)
  • ✅ independent_review

Files analysed: 7


wall-e 2026.06.19-02 · policy 6b4ce2b3b45a…

@agent-wall-e

agent-wall-e Bot commented Dec 1, 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/OAuthTokenStatusTest.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

@rodrigojara-cko rodrigojara-cko changed the title fix(client): set default timeouts on the sdk http client fix(client): set default timeouts and check the token status Dec 1, 2026
@rodrigojara-cko
rodrigojara-cko force-pushed the fix/INT-1852-default-http-timeouts branch from ee30642 to 9a9b381 Compare December 1, 2026 16:52
@agent-wall-e

agent-wall-e Bot commented Dec 1, 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/OAuthTokenStatusTest.php

Operational gates

  • ✅ jira_ticket (INT-1852)
  • ✅ independent_review

Files analysed: 7


wall-e 2026.06.19-02 · policy 6b4ce2b3b45a…

@agent-wall-e

agent-wall-e Bot commented Dec 1, 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/OAuthTokenStatusTest.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

The HTTP client the SDK creates had no timeout, so a server that accepts the
connection and never answers blocked the request forever. That client now
uses connect_timeout 10 s and timeout 60 s, and a request over either bound
fails with CheckoutApiException (CheckoutException on the OAuth token
request).

Behaviour change: before, no timeout; now 10 s to connect and 60 s for the
whole request. A client passed with httpClientBuilder(), including a
DefaultHttpClientBuilder built with your own config, is used as is and does
not get these defaults; set connect_timeout and timeout on it to override.
The token response was only checked for its body, so a response with a
status other than 200, the success status of a token response, was
accepted when its body was valid: any status when the HTTP client does not
throw on error statuses (http_errors set to false), and with any client the
1xx, 3xx and 2xx other than 200 statuses Guzzle does not throw on. Such a
response now throws CheckoutAuthorizationException with the message "OAuth
token request failed with status <code>", through the new
CheckoutAuthorizationException::tokenRequestFailed() factory.
@rodrigojara-cko
rodrigojara-cko force-pushed the fix/INT-1852-default-http-timeouts branch from 9a9b381 to 50c3dec Compare December 3, 2026 16:04
@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
  • security_sensitive_path:test/Checkout/Tests/OAuthTokenStatusTest.php

Operational gates

  • ✅ jira_ticket (INT-1852)
  • ✅ 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).
security_sensitive_path — test/Checkout/Tests/OAuthTokenStatusTest.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 3, 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