Skip to content

fix(appsec): treat empty request/response bodies as absent - #1321

Open
DenzoNL wants to merge 1 commit into
DataDog:mainfrom
DenzoNL:dennis.bogers/skip-empty-body-appsec-parsing
Open

fix(appsec): treat empty request/response bodies as absent#1321
DenzoNL wants to merge 1 commit into
DataDog:mainfrom
DenzoNL:dennis.bogers/skip-empty-body-appsec-parsing

Conversation

@DenzoNL

@DenzoNL DenzoNL commented Aug 5, 2026

Copy link
Copy Markdown

Overview

After enabling AppSec on our Node.js Lambdas, the extension logs this on nearly every invocation (~45k lines/day on one service):

DD_EXTENSION | INFO | aap: unable to parse body, it will not be analyzed for security activity: failed to parse body: EOF while parsing a value at line 1 column 0

Not all requests and responses have a body (GET/OPTIONS/HEAD, 204s, redirects), and event sources often represent that as an empty string rather than null. Body::reader() only returns None for null, so an empty body still gets parsed as JSON and fails with the EOF error above. RawPayload::response_body() has the same problem — it always returns Some, even for zero bytes.

An empty body isn't malformed and there's nothing to analyze, so skip it instead of logging a parse failure. Rather than adding a log exclusion rule on our side I figured I'd fix it upstream, since this seems like a bug.

Testing

  • Added unit tests for Body::reader() (absent, empty, base64) and for empty bodies in ApiGatewayResponse/RawPayload.
  • cargo test, cargo clippy --all-targets -- -D warnings, and cargo fmt --check pass locally.

Event sources commonly represent the absence of a body as an empty
string (GET/OPTIONS/HEAD requests, 204 or redirect responses). The
AppSec processor attempted to parse these as JSON, failing with
"EOF while parsing a value at line 1 column 0" and logging
"aap: unable to parse body" at INFO on every such invocation.

Skip body extraction entirely when the body is empty: there is
nothing to analyze, and no reason to log a parse failure.
@DenzoNL
DenzoNL marked this pull request as ready for review August 5, 2026 18:20
Copilot AI review requested due to automatic review settings August 5, 2026 18:20
@DenzoNL
DenzoNL requested a review from a team as a code owner August 5, 2026 18:20
@DenzoNL
DenzoNL requested a review from lym953 August 5, 2026 18:20

Copilot AI 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.

Pull request overview

Fixes noisy AppSec “failed to parse body: EOF …” logs by treating empty request/response bodies as absent (not malformed), aligning behavior with common event-source conventions (e.g., API Gateway using "" for no body).

Changes:

  • Update Body::reader() to return None for empty-string bodies (in addition to null), avoiding attempted JSON parsing of empty payloads.
  • Update RawPayload::response_body() to return None for zero-length raw responses.
  • Add unit tests covering absent/empty/base64 bodies and empty-body response formats.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
bottlecap/src/lifecycle/invocation/triggers/body.rs Treat empty string bodies as absent in Body::reader() and add focused unit tests.
bottlecap/src/appsec/processor/response.rs Skip returning a reader for empty raw response payloads; add tests for empty bodies in API Gateway + raw response parsing.

Comment on lines +20 to +22
/// Returns [`None`] if there is no body, including when it is an empty
/// string, which is how many event sources represent the absence of a
/// body (e.g, `GET` requests, `204` responses, etc...).
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