Skip to content

fix(appsec): send the normalized status code on end-invocation - #817

Open
CarlesDD wants to merge 1 commit into
mainfrom
ccapell/APPSEC-68818/fix-appsec-end-invocation-status-code
Open

fix(appsec): send the normalized status code on end-invocation#817
CarlesDD wants to merge 1 commit into
mainfrom
ccapell/APPSEC-68818/fix-appsec-end-invocation-status-code

Conversation

@CarlesDD

@CarlesDD CarlesDD commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

Reorders onEndingInvocation so the HTTP status code is resolved and tagged before AppSec runs, and passes that normalized value to processAppsecResponse instead of letting it read result.statusCode raw.

Motivation

extractHTTPStatusCodeTag normalizes cases the raw result does not cover: ALB and API Gateway v2 handlers may omit the status (defaults to 200), a buffered function returning nothing is a 502, and a streaming one is a 200. AppSec was publishing the raw value, so the WAF received a wrong or missing status for those triggers.

The 5xx early return stays nested on inferredSpan, so its behaviour is unchanged; it just moved behind the AppSec call so 5xx responses still reach the WAF.

APPSEC-68818

Testing Guidelines

src/appsec/index.spec.ts covers the normalized value winning over the raw one and the fallback for non-HTTP triggers. src/trace/listener.spec.ts adds cases over real event samples: API Gateway v2 without a status, ALB with no result, streaming with no result, the tag-before-AppSec ordering, and a 500 still reaching AppSec while short-circuiting.

src/appsec + src/trace: 475 tests passing. tsc, tslint and prettier clean.

Additional Notes

Shippable on its own: it fixes the status code the WAF receives today, with or without API Security. It is also a prerequisite for API Security on Lambda, where the sampling decision is taken off the span and needs http.status_code already set.

Types of Changes

  • Bug fix
  • New feature
  • Breaking change
  • Misc (docs, refactoring, dependency upgrade, etc.)

Check all that apply

  • This PR's description is comprehensive
  • This PR contains breaking changes that are documented in the description
  • This PR introduces new APIs or parameters that are documented and unlikely to change in the foreseeable future
  • This PR impacts documentation, and it has been updated (or a ticket has been logged)
  • This PR's changes are covered by the automated tests
  • This PR collects user input/sensitive content into Datadog
  • This PR passes the integration tests (ask a Datadog member to run the tests)

@CarlesDD CarlesDD self-assigned this Aug 27, 2026
@CarlesDD
CarlesDD marked this pull request as ready for review August 27, 2026 07:54
@CarlesDD
CarlesDD requested review from a team as code owners August 27, 2026 07:54
Comment thread src/appsec/index.ts
endInvocationChannel.publish({
span,
statusCode: result?.statusCode?.toString(),
statusCode: statusCode ?? result?.statusCode?.toString(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible that statusCode has different value from results.statusCode, assuming neither is null?

@litianningdatadog litianningdatadog left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left some comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants