Skip to content

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

Merged
CarlesDD merged 8 commits into
mainfrom
ccapell/APPSEC-68818/fix-appsec-end-invocation-status-code
Aug 31, 2026
Merged

fix(appsec): send the normalized status code on end-invocation#817
CarlesDD merged 8 commits 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?

Two fixes on the AppSec end-invocation payload:

  • Reorders onEndingInvocation so the HTTP status code is resolved and tagged before AppSec runs, and publishes that normalized value.
  • Normalizes the response headers matching what the extractor already does for request headers.

Motivation

AppSec was publishing the raw result.statusCode and raw response headers, so the WAF got no status at all when the handler omitted one and response headers in a different shape from the request ones.

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 Outdated
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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

only for non-http triggers, but the tracer drops those end-invocation messages away, so it was dead code. removed.

@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

Comment thread src/trace/listener.ts
Comment thread src/appsec/headers.ts Outdated
for (const [key, value] of Object.entries(headers)) {
const lowerKey = key.toLowerCase();
if (!(lowerKey in result) && value !== undefined) {
result[lowerKey] = value;

@litianningdatadog litianningdatadog Aug 28, 2026

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.

if we plan to keep this normalizeHeaders() generic, you may want to expand header value to support input type such as number and bool and stringfy in result?

@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.

Stamped. Left a non-blocker comment

@CarlesDD
CarlesDD merged commit b17f2f3 into main Aug 31, 2026
55 checks passed
@CarlesDD
CarlesDD deleted the ccapell/APPSEC-68818/fix-appsec-end-invocation-status-code branch August 31, 2026 13:16
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