Skip to content

Commit 2491b2d

Browse files
committed
feat(appsec): enable api security for lambda
1 parent 1e6a308 commit 2491b2d

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

ddtrace/appsec/_handlers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
from typing import Any
55
from typing import Dict
66
from typing import Optional
7+
from typing import Union
78

89
import xmltodict
910

1011
from ddtrace._trace.span import Span
1112
from ddtrace.appsec._asm_request_context import _call_waf
1213
from ddtrace.appsec._asm_request_context import _call_waf_first
1314
from ddtrace.appsec._asm_request_context import get_blocked
15+
from ddtrace.appsec._asm_request_context import set_body_response
1416
from ddtrace.appsec._constants import SPAN_DATA_NAMES
1517
from ddtrace.appsec._http_utils import extract_cookies_from_headers
1618
from ddtrace.appsec._http_utils import normalize_headers
@@ -131,6 +133,7 @@ def _on_lambda_start_response(
131133
span: Span,
132134
status_code: str,
133135
response_headers: Dict[str, str],
136+
response_body: Optional[Union[str, Dict[str, Any]]],
134137
):
135138
if not (asm_config._asm_enabled and span.span_type in asm_config._asm_http_span_types):
136139
return
@@ -156,6 +159,10 @@ def _on_lambda_start_response(
156159

157160
_call_waf(("aws_lambda",))
158161

162+
if asm_config._api_security_feature_active:
163+
if response_body:
164+
set_body_response(response_body)
165+
159166

160167
# ASGI
161168

ddtrace/appsec/_processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def on_span_start(self, span: Span) -> None:
189189
if skip_event:
190190
core.discard_item("appsec_skip_next_lambda_event")
191191
log.debug(
192-
"appsec: ignoring unsupported lamdba event",
192+
"appsec: ignoring unsupported lambda event",
193193
)
194194
span.set_metric(APPSEC.UNSUPPORTED_EVENT_TYPE, 1.0)
195195
return

ddtrace/settings/asm.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,8 @@ def __init__(self):
246246
self._asm_processed_span_types.add(SpanTypes.SERVERLESS)
247247
self._asm_http_span_types.add(SpanTypes.SERVERLESS)
248248

249-
# As a first step, only Threat Management in monitoring mode should be enabled in AWS Lambda
249+
# Disable all features that are not supported in Lambda
250250
tracer_config._remote_config_enabled = False
251-
self._api_security_enabled = False
252251
self._ep_enabled = False
253252
self._iast_supported = False
254253

0 commit comments

Comments
 (0)