Skip to content

fix(client): security hardening - #482

Merged
rodrigojara-cko merged 3 commits into
masterfrom
fix/INT-1818-security-hardening
Nov 25, 2026
Merged

rodrigojara-cko merged 3 commits into
masterfrom
fix/INT-1818-security-hardening

Conversation

@rodrigojara-cko

@rodrigojara-cko rodrigojara-cko commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Security hardening of the HTTP layer, with both HTTP clients. Improved error handling: the errors of the HTTP layer are SDK error types.

Changes

  • src/services/http.js: security hardening; every request uses the SDK's own policy with both HTTP clients; errors thrown as SDK error types; connection errors keep the client's error as cause.
  • src/services/errors.js: determineError returns an SDK error unchanged; doc added.
  • src/api/reports/reports.js: the report file download uses the SDK's own policy; doc types corrected.
  • types/dist/api/reports/reports.d.ts: getReportFile returns Promise<Buffer>, as documented.
  • types/dist/services/errors.d.ts: cause declared on ApiError.
  • test/http/responsePolicy.js (new), test/errors/determineError-unit.js (new): tests for both HTTP clients against local HTTP servers, and for the error mapping.

Design notes:

  • One policy in the API client applies to every request, with both HTTP clients; no option per endpoint.
  • One documented exception covers the report file download. It is marked with an internal config flag set only by getReportFile, as the existing csv and formData flags; it cannot be set from the Checkout options. It follows a single response, to an https location, or to a plain-http one only when both the API base and the location are on a loopback host, so local tests can use plain HTTP servers; any other response of that request is an error. Of the request headers, only User-Agent and Accept are sent to that location: an allowlist, applied with axios to the request headers and again to the application's default headers merged into them; the application's axios params default is not added to that location.
  • Each HTTP client has its own helpers for sending a request and for the errors of a request without a response, shared by every request.
  • With axios, the policy is set on each call; the application's axios defaults still apply where the policy sets nothing. SDK requests use axios's built-in http/https transport, whatever the application's transport default. A custom adapter function or interceptor, and a replaced global fetch, are application code and are used as configured.
  • A token is sent only when the token response has a non-empty string access_token and token_type (RFC 6749, section 5.1); otherwise the request that needed it gives an AuthenticationError with the status only and is not sent. The check is made where the token is used, so access.request still returns the parsed token response as before; a 2xx body the client cannot parse, or that axios refuses under the application's parsing defaults, is an AuthenticationError with the status only.
  • The errors of that policy carry the status and the request id only.
  • determineError returns SDK errors unchanged, so the error type thrown by the HTTP layer reaches the caller; the status mapping is not duplicated.
  • Connection errors keep their previous body; cause holds the client's error name, message and code only.
  • The tests use local HTTP servers instead of nock, so the requests each client sends are observed with both clients.

API Reference

None.

Breaking changes

Type declarations: getReportFile returns Promise<Buffer> instead of Promise<Object> (the value it already returned), and ApiError declares an optional cause. Both are source-compatible.

Behaviour changes, released as a minor version:

  • Security hardening: every request uses the SDK's own policy with both HTTP clients, whatever the application's axios defaults. Some API responses that were handled as a success now return an error with their status code: the SDK error of that status (ApiError when there is no specific one). The report file download keeps working, with the SDK's own policy. It cannot be kept compatible: handling these responses in the SDK is the security hardening itself. Migration: where such a response was expected, check http_code of the error, or body.status of an AuthenticationError.
  • The error of a response with status 300 or 304 carries the status and the request id only, instead of the response body. Needed so no error of that policy repeats a response it did not use.
  • A request that needs a token, when the token response has no usable access_token and token_type, gives an AuthenticationError with body.status and is not sent. Before, it was sent with an unusable authorization. Needed so no request is sent with an unusable authorization and no error repeats the token response. Migration: check body.status of the AuthenticationError.
  • With fetch, access.request gives an AuthenticationError with body.status for a 2xx body that is not JSON, instead of a parse error; with axios, a 2xx body that axios refuses under the application's parsing defaults gives the same error instead of an ApiError with the body. Any body the client parses is returned as before. Needed so the error is an SDK error that does not repeat the token response.
  • SDK requests no longer use the application's axios transport default. It cannot be kept compatible: the policy above holds only with the built-in transport.
  • The report file download sends only the User-Agent and Accept request headers to the file location; other configured headers are sent to the API only. Needed so the file location receives no header meant for the API.
  • createAccessToken, an internal function not exported from the package entry point, throws SDK error types instead of plain objects or Error. Needed so the errors of the HTTP layer are SDK errors.
  • Some error responses that threw a TypeError now return the SDK error of their status. Kept as an SDK error type because the errors of the HTTP layer must be SDK errors.
  • Connection errors have a cause property; their type, http_code and body are unchanged, except that the body no longer repeats input the HTTP client rejects. Needed so no error repeats that input.
  • determineError, called directly with an SDK error, returns it unchanged instead of a new ApiError. Needed so the error types above reach the caller.

Tests

  • Existing tests pass

  • Serialization tests cover every new or changed property (no request or response type changed)

  • README updated if documented usage changed (documented usage unchanged)

  • test/http/responsePolicy.js (new): every request method (GET, POST, PUT, PATCH, DELETE) with both HTTP clients against local HTTP servers: the requests each server receives, the error type and body, the report file download and the headers its file request sends, token responses that cannot be used (both clients, access.request included), the application's axios defaults (transport, strict JSON parsing and params included), error statuses, connection errors and the input the HTTP clients reject.

  • test/errors/determineError-unit.js (new): SDK errors unchanged and the status mapping as before.

The policy and error tests fail on the default branch; the tests of behaviour already in place pass on both.

Related

None.

@rodrigojara-cko
rodrigojara-cko requested a review from a team November 24, 2026 16:50
@agent-wall-e

agent-wall-e Bot commented Nov 24, 2026

Copy link
Copy Markdown

🟡 Risk Classification: MINOR

Approval route: AI Review + Human Approval
Rollback controls: Staged rollout + rollback

Classification reasons

  • exceeds_bounded_scope:379>250

Operational gates

  • ✅ jira_ticket (INT-1818)
  • ✅ independent_review

Files analysed: 5


wall-e 2026.06.19-02 · policy 6b4ce2b3b45a…

@agent-wall-e

agent-wall-e Bot commented Nov 24, 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
exceeds_bounded_scope — 379>250 classifying §2.1 M8 More than 250 non-test, non-doc, non-lockfile lines changed.

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

This comment has been minimized.

Security hardening of the HTTP layer, with both HTTP clients, and improved
error handling.
Helpers per HTTP client in the HTTP layer, more tests, and type
declarations aligned.
@rodrigojara-cko
rodrigojara-cko force-pushed the fix/INT-1818-security-hardening branch from 45382ec to 4df3d97 Compare November 24, 2026 20:48
@agent-wall-e

agent-wall-e Bot commented Nov 24, 2026

Copy link
Copy Markdown

🟡 Risk Classification: MINOR

Approval route: AI Review + Human Approval
Rollback controls: Staged rollout + rollback

Classification reasons

  • exceeds_bounded_scope:499>250

Operational gates

  • ✅ jira_ticket (INT-1818)
  • ✅ independent_review

Files analysed: 7


wall-e 2026.06.19-02 · policy 6b4ce2b3b45a…

@agent-wall-e

agent-wall-e Bot commented Nov 24, 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
exceeds_bounded_scope — 499>250 classifying §2.1 M8 More than 250 non-test, non-doc, non-lockfile lines changed.

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

HTTP layer response handling aligned across clients, with more tests.
@agent-wall-e

agent-wall-e Bot commented Nov 25, 2026

Copy link
Copy Markdown

🟡 Risk Classification: MINOR

Approval route: AI Review + Human Approval
Rollback controls: Staged rollout + rollback

Classification reasons

  • exceeds_bounded_scope:523>250

Operational gates

  • ✅ jira_ticket (INT-1818)
  • ✅ independent_review

Files analysed: 7


wall-e 2026.06.19-02 · policy 6b4ce2b3b45a…

@agent-wall-e

agent-wall-e Bot commented Nov 25, 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
exceeds_bounded_scope — 523>250 classifying §2.1 M8 More than 250 non-test, non-doc, non-lockfile lines changed.

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

Copy link
Copy Markdown

@rodrigojara-cko
rodrigojara-cko merged commit 57064d6 into master Nov 25, 2026
6 checks passed
@rodrigojara-cko
rodrigojara-cko deleted the fix/INT-1818-security-hardening branch November 25, 2026 17:13
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