Skip to content

fix(client): set default timeouts and check token status and subdomain - #427

Open
rodrigojara-cko wants to merge 3 commits into
maintenance/3.2.xfrom
fix/INT-1852-default-http-timeouts-3.2.x
Open

rodrigojara-cko wants to merge 3 commits into
maintenance/3.2.xfrom
fix/INT-1852-default-http-timeouts-3.2.x

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, and a subdomain with a trailing newline is no longer accepted. The timeout and token status changes of master, for the 3.2.x line, plus the trailing newline check of the subdomain that master already has (here the subdomain is not used instead of throwing, see Design notes). This line has no OAuth error code in the token messages, so the status message is the status only.

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.
  • lib/Checkout/CheckoutAuthorizationException.php: tokenRequestFailed($statusCode) factory ("OAuth token request failed with status ").
  • lib/Checkout/EnvironmentSubdomain.php: the subdomain pattern gets the D modifier, so $ no longer matches before a final newline (master already has it).
  • 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/EnvironmentSubdomainTest.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 check is a new factory next to the existing invalidAccessTokenResponse(). 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. With the D modifier a subdomain with a trailing newline is treated like any other invalid subdomain on this line: it is not used and the default hosts apply, instead of the request failing later on the malformed host; master rejects it with an exception, which on this line would be a stricter change than the fix needs. 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 with the Guzzle message. 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 patch of this line (3.2.11, 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.
  • A subdomain with a trailing newline (for example read from a file with its line ending) is not used and the default API host applies, as for any other value outside the pattern; it used to be placed in the request host, where the request then failed. Needed so the check means what it says. Migration: trim the value.

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), and token responses with nine statuses other than 200 rejected and 200 accepted, and a subdomain with a trailing newline not used.

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


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, rejects non-200 OAuth token responses, and fixes the subdomain regex to reject trailing newlines; all three changes are backed by targeted new tests and match the stated intent.

What I checked

  • The status-code check in OAuthSdkCredentials.php is placed after the try/catch that converts Guzzle exceptions, so a non-200 response (which Guzzle won't throw on because http_errors defaults to false in the SDK's own client) is correctly caught by the new explicit check.
  • DEFAULT_CONNECT_TIMEOUT_SECONDS and DEFAULT_TIMEOUT_SECONDS are set only on the DefaultHttpClientBuilder constructed in the constructor; the httpClientBuilder() setter replaces that builder entirely, so a custom builder correctly keeps its own options without any extra guard needed.
  • The /D modifier fix in EnvironmentSubdomain.php is correct: without D, PCRE's $ matches before a terminal newline, so 'abc\n' would have passed the regex and been used as a subdomain; the test confirms the fix.
  • The tokenRequestFailed factory and the check are consistent: the check fires before the body is decoded, so a non-200 response with a syntactically valid body is still rejected, which is what the test suite exercises with http_errors => false.
  • The silent-server tests use SHORT_TIMEOUT_SECONDS=1 and assert elapsed < MAX_ELAPSED_SECONDS=10, giving a 9-second margin that should be safe even on slow CI runners.
  • The secret_marker assertion in tokenRequestToServerThatNeverAnswersFailsWithCheckoutException uses assertFalse(strpos(...) !== false) which is equivalent to assertStringNotContainsString; it is slightly convoluted but logically correct.
  • No existing tests are removed or weakened; the docblock change in HttpClientOptionsTest.php is a narrowing clarification (TLS → TLS) that doesn't affect test logic.

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-3.2.x branch from e4d61a1 to 69886aa 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: 9


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): default timeouts, token status and subdomain check Dec 1, 2026
@rodrigojara-cko
rodrigojara-cko force-pushed the fix/INT-1852-default-http-timeouts-3.2.x branch from 69886aa to 928fa10 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: 9


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): default timeouts, token status and subdomain check fix(client): set default timeouts and check token status and subdomain Dec 1, 2026
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.
The subdomain pattern ended with $, which also matches before a final
newline, so a value such as one read from a file with its line ending was
accepted and placed in the request host. With the D modifier such a value
is not used as a subdomain and the default host applies, as for any other
value outside the pattern.
@rodrigojara-cko
rodrigojara-cko force-pushed the fix/INT-1852-default-http-timeouts-3.2.x branch from 928fa10 to bc9e614 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: 9


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