Skip to content

Commit 6a0f467

Browse files
committed
Merge branch 'main' into taegyunkim/prof-12836-test-cleanup
2 parents dbcdc56 + ab2bedf commit 6a0f467

File tree

324 files changed

+3451
-2652
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

324 files changed

+3451
-2652
lines changed

.claude/CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ This project has custom skills that provide specialized workflows. **Always chec
2323
**Use whenever:** Formatting code, validating style/types/security, or before committing changes.
2424

2525
**Purpose:** Runs targeted linting and code quality checks using `hatch run lint:*`:
26-
- Formats code with Black and Ruff auto-fixes
26+
- Formats code with `ruff check` and `ruff format`
2727
- Validates style, types, and security
2828
- Checks spelling and documentation
2929
- Validates test infrastructure (suitespec, riotfile, etc.)

.claude/skills/lint/SKILL.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ hatch run lint:typing -- path/to/file.py
4848
### Code Formatting
4949

5050
#### `fmt` - Format code (recommended for most edits)
51-
Formats and validates code style using Black and Ruff.
51+
Formats and validates code style using Ruff.
5252

5353
**Usage:**
5454
```bash
@@ -63,7 +63,7 @@ hatch run lint:fmt -- ddtrace/contrib/flask/
6363
```
6464

6565
**What it does:**
66-
1. Runs Black formatter
66+
1. Runs the Ruff formatter
6767
2. Runs Ruff with --fix to auto-fix issues
6868
3. Re-validates with style checks
6969

@@ -94,20 +94,21 @@ hatch run lint:style -- ddtrace/
9494
```
9595

9696
**What it validates:**
97-
- Black formatting
97+
- Ruff formatting
9898
- Ruff linting rules
9999
- Cython linting
100100
- C code formatting
101101
- CMake formatting
102102

103103
**When to use:** To verify style compliance before committing without auto-fixes.
104104

105-
#### `black_check` - Check Black formatting
106-
Validates Python code formatting with Black (no auto-fix).
105+
#### `format_check` - Check formatting
106+
107+
Validates Python code formatting with `ruff format` (no auto-fix).
107108

108109
**Usage:**
109110
```bash
110-
hatch run lint:black_check -- ddtrace/tracer.py
111+
hatch run lint:format_check -- ddtrace/tracer.py
111112
```
112113

113114
**When to use:** Quick check of Python formatting before committing.

.sg/rules/pep765-control-flow-in-finally.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
id: pep765-control-flow-in-finally
22
message: Control flow statement in finally block (PEP 765)
3-
severity: warning
3+
severity: error
44
language: python
55
rule:
66
any:

benchmarks/bm/iast_fixtures/str_methods.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ def get_random_string_join(mystring: str) -> Text:
832832

833833
def get_random_string_seed(
834834
length=12,
835-
allowed_chars="abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
835+
allowed_chars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
836836
): # type: (int, str) -> str
837837
"""
838838
Returns a securely generated random string.
@@ -1180,13 +1180,13 @@ def do_add_re_compile():
11801180
import re
11811181

11821182
invalid_unicode_no_surrogate = (
1183-
"[\u0001-\u0008\u000B\u000E-\u001F\u007F-\u009F\uFDD0-\uFDEF"
1184-
"\uFFFE\uFFFF\U0001FFFE\U0001FFFF\U0002FFFE\U0002FFFF"
1185-
"\U0003FFFE\U0003FFFF\U0004FFFE\U0004FFFF\U0005FFFE\U0005FFFF"
1186-
"\U0006FFFE\U0006FFFF\U0007FFFE\U0007FFFF\U0008FFFE\U0008FFFF"
1187-
"\U0009FFFE\U0009FFFF\U000AFFFE\U000AFFFF\U000BFFFE\U000BFFFF"
1188-
"\U000CFFFE\U000CFFFF\U000DFFFE\U000DFFFF\U000EFFFE\U000EFFFF"
1189-
"\U000FFFFE\U000FFFFF\U0010FFFE\U0010FFFF]"
1183+
"[\u0001-\u0008\u000b\u000e-\u001f\u007f-\u009f\ufdd0-\ufdef"
1184+
"\ufffe\uffff\U0001fffe\U0001ffff\U0002fffe\U0002ffff"
1185+
"\U0003fffe\U0003ffff\U0004fffe\U0004ffff\U0005fffe\U0005ffff"
1186+
"\U0006fffe\U0006ffff\U0007fffe\U0007ffff\U0008fffe\U0008ffff"
1187+
"\U0009fffe\U0009ffff\U000afffe\U000affff\U000bfffe\U000bffff"
1188+
"\U000cfffe\U000cffff\U000dfffe\U000dffff\U000efffe\U000effff"
1189+
"\U000ffffe\U000fffff\U0010fffe\U0010ffff]"
11901190
) # noqa:F401
11911191
_ = re.compile(invalid_unicode_no_surrogate[:-1] + eval('"\\uD800-\\uDFFF"') + "]") # pylint:disable=eval-used
11921192

conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Local plugins: https://docs.pytest.org/en/3.10.1/writing_plugins.html#local-conftest-plugins
66
Hook reference: https://docs.pytest.org/en/3.10.1/reference.html#hook-reference
77
"""
8+
89
import os
910
import re
1011
import sys

ddtrace/_trace/sampler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
Any `sampled = False` trace won't be written, and can be ignored by the instrumentation.
44
"""
5+
56
import json
67
from json.decoder import JSONDecodeError
78
from typing import Dict

ddtrace/_trace/utils_valkey.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,17 @@ def _set_span_tags(
5050
@contextmanager
5151
def _instrument_valkey_cmd(pin, config_integration, instance, args):
5252
query = stringify_cache_args(args, cmd_max_len=config_integration.cmd_max_length)
53-
with core.context_with_data(
54-
"valkey.command",
55-
span_name=schematize_cache_operation(valkeyx.CMD, cache_provider=valkeyx.APP),
56-
pin=pin,
57-
service=trace_utils.ext_service(pin, config_integration),
58-
span_type=SpanTypes.VALKEY,
59-
resource=query.split(" ")[0] if config_integration.resource_only_command else query,
60-
) as ctx, ctx.span as span:
53+
with (
54+
core.context_with_data(
55+
"valkey.command",
56+
span_name=schematize_cache_operation(valkeyx.CMD, cache_provider=valkeyx.APP),
57+
pin=pin,
58+
service=trace_utils.ext_service(pin, config_integration),
59+
span_type=SpanTypes.VALKEY,
60+
resource=query.split(" ")[0] if config_integration.resource_only_command else query,
61+
) as ctx,
62+
ctx.span as span,
63+
):
6164
_set_span_tags(span, pin, config_integration, args, instance, query)
6265
yield ctx
6366

ddtrace/appsec/_constants.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -81,43 +81,43 @@ class APPSEC(metaclass=Constant_Class):
8181
USER_LOGIN_EVENT_PREFIX_PUBLIC: Literal["appsec.events.users.login"] = "appsec.events.users.login"
8282
USER_LOGIN_USERID: Literal["_dd.appsec.usr.id"] = "_dd.appsec.usr.id"
8383
USER_LOGIN_USERNAME: Literal["_dd.appsec.usr.login"] = "_dd.appsec.usr.login"
84-
USER_LOGIN_EVENT_SUCCESS_TRACK: Literal[
84+
USER_LOGIN_EVENT_SUCCESS_TRACK: Literal["appsec.events.users.login.success.track"] = (
8585
"appsec.events.users.login.success.track"
86-
] = "appsec.events.users.login.success.track"
87-
USER_LOGIN_EVENT_FAILURE_TRACK: Literal[
86+
)
87+
USER_LOGIN_EVENT_FAILURE_TRACK: Literal["appsec.events.users.login.failure.track"] = (
8888
"appsec.events.users.login.failure.track"
89-
] = "appsec.events.users.login.failure.track"
89+
)
9090
USER_SIGNUP_EVENT: Literal["appsec.events.users.signup.track"] = "appsec.events.users.signup.track"
9191
USER_SIGNUP_EVENT_USERNAME: Literal["appsec.events.users.signup.usr.login"] = "appsec.events.users.signup.usr.login"
9292
USER_SIGNUP_EVENT_USERID: Literal["appsec.events.users.signup.usr.id"] = "appsec.events.users.signup.usr.id"
93-
USER_SIGNUP_EVENT_MODE: Literal[
93+
USER_SIGNUP_EVENT_MODE: Literal["_dd.appsec.events.users.signup.auto.mode"] = (
9494
"_dd.appsec.events.users.signup.auto.mode"
95-
] = "_dd.appsec.events.users.signup.auto.mode"
96-
AUTO_LOGIN_EVENTS_SUCCESS_MODE: Literal[
95+
)
96+
AUTO_LOGIN_EVENTS_SUCCESS_MODE: Literal["_dd.appsec.events.users.login.success.auto.mode"] = (
9797
"_dd.appsec.events.users.login.success.auto.mode"
98-
] = "_dd.appsec.events.users.login.success.auto.mode"
99-
AUTO_LOGIN_EVENTS_FAILURE_MODE: Literal[
98+
)
99+
AUTO_LOGIN_EVENTS_FAILURE_MODE: Literal["_dd.appsec.events.users.login.failure.auto.mode"] = (
100100
"_dd.appsec.events.users.login.failure.auto.mode"
101-
] = "_dd.appsec.events.users.login.failure.auto.mode"
101+
)
102102
AUTO_LOGIN_EVENTS_COLLECTION_MODE: Literal["_dd.appsec.user.collection_mode"] = "_dd.appsec.user.collection_mode"
103103
BLOCKED: Literal["appsec.blocked"] = "appsec.blocked"
104104
EVENT: Literal["appsec.event"] = "appsec.event"
105-
AUTO_USER_INSTRUMENTATION_MODE: Literal[
105+
AUTO_USER_INSTRUMENTATION_MODE: Literal["DD_APPSEC_AUTO_USER_INSTRUMENTATION_MODE"] = (
106106
"DD_APPSEC_AUTO_USER_INSTRUMENTATION_MODE"
107-
] = "DD_APPSEC_AUTO_USER_INSTRUMENTATION_MODE"
108-
AUTO_USER_INSTRUMENTATION_MODE_ENABLED: Literal[
107+
)
108+
AUTO_USER_INSTRUMENTATION_MODE_ENABLED: Literal["DD_APPSEC_AUTOMATED_USER_EVENTS_TRACKING_ENABLED"] = (
109109
"DD_APPSEC_AUTOMATED_USER_EVENTS_TRACKING_ENABLED"
110-
] = "DD_APPSEC_AUTOMATED_USER_EVENTS_TRACKING_ENABLED"
110+
)
111111
USER_MODEL_LOGIN_FIELD: Literal["DD_USER_MODEL_LOGIN_FIELD"] = "DD_USER_MODEL_LOGIN_FIELD"
112112
USER_MODEL_EMAIL_FIELD: Literal["DD_USER_MODEL_EMAIL_FIELD"] = "DD_USER_MODEL_EMAIL_FIELD"
113113
USER_MODEL_NAME_FIELD: Literal["DD_USER_MODEL_NAME_FIELD"] = "DD_USER_MODEL_NAME_FIELD"
114114
PROPAGATION_HEADER: Literal["_dd.p.ts"] = "_dd.p.ts"
115-
OBFUSCATION_PARAMETER_KEY_REGEXP: Literal[
115+
OBFUSCATION_PARAMETER_KEY_REGEXP: Literal["DD_APPSEC_OBFUSCATION_PARAMETER_KEY_REGEXP"] = (
116116
"DD_APPSEC_OBFUSCATION_PARAMETER_KEY_REGEXP"
117-
] = "DD_APPSEC_OBFUSCATION_PARAMETER_KEY_REGEXP"
118-
OBFUSCATION_PARAMETER_VALUE_REGEXP: Literal[
117+
)
118+
OBFUSCATION_PARAMETER_VALUE_REGEXP: Literal["DD_APPSEC_OBFUSCATION_PARAMETER_VALUE_REGEXP"] = (
119119
"DD_APPSEC_OBFUSCATION_PARAMETER_VALUE_REGEXP"
120-
] = "DD_APPSEC_OBFUSCATION_PARAMETER_VALUE_REGEXP"
120+
)
121121
RC_CLIENT_ID: Literal["_dd.rc.client_id"] = "_dd.rc.client_id"
122122
WAF_ERROR: Literal["_dd.appsec.waf.error"] = "_dd.appsec.waf.error"
123123
RASP_ERROR: Literal["_dd.appsec.rasp.error"] = "_dd.appsec.rasp.error"
@@ -148,9 +148,9 @@ class IAST(metaclass=Constant_Class):
148148
ENV_SINK_POINTS_ENABLED: Literal["DD_IAST_SINK_POINTS_ENABLED"] = "DD_IAST_SINK_POINTS_ENABLED"
149149
ENV_PROPAGATION_DEBUG: Literal["DD_IAST_PROPAGATION_DEBUG"] = "DD_IAST_PROPAGATION_DEBUG"
150150
ENV_REQUEST_SAMPLING: Literal["DD_IAST_REQUEST_SAMPLING"] = "DD_IAST_REQUEST_SAMPLING"
151-
DD_IAST_VULNERABILITIES_PER_REQUEST: Literal[
151+
DD_IAST_VULNERABILITIES_PER_REQUEST: Literal["DD_IAST_VULNERABILITIES_PER_REQUEST"] = (
152152
"DD_IAST_VULNERABILITIES_PER_REQUEST"
153-
] = "DD_IAST_VULNERABILITIES_PER_REQUEST"
153+
)
154154
DD_IAST_MAX_CONCURRENT_REQUESTS: Literal["DD_IAST_MAX_CONCURRENT_REQUESTS"] = "DD_IAST_MAX_CONCURRENT_REQUESTS"
155155
ENV_TELEMETRY_REPORT_LVL: Literal["DD_IAST_TELEMETRY_VERBOSITY"] = "DD_IAST_TELEMETRY_VERBOSITY"
156156
LAZY_TAINT: Literal["_DD_IAST_LAZY_TAINT"] = "_DD_IAST_LAZY_TAINT"
@@ -185,9 +185,9 @@ class IAST_SPAN_TAGS(metaclass=Constant_Class):
185185

186186
TELEMETRY_REQUEST_TAINTED: Literal["_dd.iast.telemetry.request.tainted"] = "_dd.iast.telemetry.request.tainted"
187187
TELEMETRY_EXECUTED_SINK: Literal["_dd.iast.telemetry.executed.sink"] = "_dd.iast.telemetry.executed.sink"
188-
TELEMETRY_SUPPRESSED_VULNERABILITY: Literal[
188+
TELEMETRY_SUPPRESSED_VULNERABILITY: Literal["_dd.iast.telemetry.suppressed.vulnerabilities"] = (
189189
"_dd.iast.telemetry.suppressed.vulnerabilities"
190-
] = "_dd.iast.telemetry.suppressed.vulnerabilities"
190+
)
191191
TELEMETRY_EXECUTED_SOURCE: Literal["_dd.iast.telemetry.executed.source"] = "_dd.iast.telemetry.executed.source"
192192

193193

@@ -252,9 +252,9 @@ class SPAN_DATA_NAMES(metaclass=Constant_Class):
252252
REQUEST_BODY: Literal["http.request.body"] = "http.request.body"
253253
REQUEST_QUERY: Literal["http.request.query"] = "http.request.query"
254254
REQUEST_HEADERS_NO_COOKIES: Literal["http.request.headers"] = "http.request.headers"
255-
REQUEST_HEADERS_NO_COOKIES_CASE: Literal[
255+
REQUEST_HEADERS_NO_COOKIES_CASE: Literal["http.request.headers_case_sensitive"] = (
256256
"http.request.headers_case_sensitive"
257-
] = "http.request.headers_case_sensitive"
257+
)
258258
REQUEST_URI_RAW: Literal["http.request.uri"] = "http.request.uri"
259259
REQUEST_ROUTE: Literal["http.request.route"] = "http.request.route"
260260
REQUEST_METHOD: Literal["http.request.method"] = "http.request.method"
@@ -287,12 +287,12 @@ class API_SECURITY(metaclass=Constant_Class):
287287
SAMPLE_RATE: Literal["DD_API_SECURITY_REQUEST_SAMPLE_RATE"] = "DD_API_SECURITY_REQUEST_SAMPLE_RATE"
288288
SAMPLE_DELAY: Literal["DD_API_SECURITY_SAMPLE_DELAY"] = "DD_API_SECURITY_SAMPLE_DELAY"
289289
MAX_PAYLOAD_SIZE: Literal[0x1000000] = 0x1000000 # 16MB maximum size
290-
ENDPOINT_COLLECTION: Literal[
290+
ENDPOINT_COLLECTION: Literal["DD_API_SECURITY_ENDPOINT_COLLECTION_ENABLED"] = (
291291
"DD_API_SECURITY_ENDPOINT_COLLECTION_ENABLED"
292-
] = "DD_API_SECURITY_ENDPOINT_COLLECTION_ENABLED"
293-
ENDPOINT_COLLECTION_LIMIT: Literal[
292+
)
293+
ENDPOINT_COLLECTION_LIMIT: Literal["DD_API_SECURITY_ENDPOINT_COLLECTION_MESSAGE_LIMIT"] = (
294294
"DD_API_SECURITY_ENDPOINT_COLLECTION_MESSAGE_LIMIT"
295-
] = "DD_API_SECURITY_ENDPOINT_COLLECTION_MESSAGE_LIMIT"
295+
)
296296

297297

298298
class WAF_CONTEXT_NAMES(metaclass=Constant_Class):
@@ -376,9 +376,9 @@ class EXPLOIT_PREVENTION(metaclass=Constant_Class):
376376
STACK_TRACE_ENABLED: Literal["DD_APPSEC_STACK_TRACE_ENABLED"] = "DD_APPSEC_STACK_TRACE_ENABLED"
377377
MAX_STACK_TRACES: Literal["DD_APPSEC_MAX_STACK_TRACES"] = "DD_APPSEC_MAX_STACK_TRACES"
378378
MAX_STACK_TRACE_DEPTH: Literal["DD_APPSEC_MAX_STACK_TRACE_DEPTH"] = "DD_APPSEC_MAX_STACK_TRACE_DEPTH"
379-
STACK_TOP_PERCENT: Literal[
379+
STACK_TOP_PERCENT: Literal["DD_APPSEC_MAX_STACK_TRACE_DEPTH_TOP_PERCENT"] = (
380380
"DD_APPSEC_MAX_STACK_TRACE_DEPTH_TOP_PERCENT"
381-
] = "DD_APPSEC_MAX_STACK_TRACE_DEPTH_TOP_PERCENT"
381+
)
382382

383383
class TYPE(metaclass=Constant_Class):
384384
CMDI: Literal["command_injection"] = "command_injection"

ddtrace/appsec/_iast/_overhead_control_engine.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
limit. It will measure operations being executed in a request and it will deactivate detection
44
(and therefore reduce the overhead to nearly 0) if a certain threshold is reached.
55
"""
6+
67
from ddtrace._trace.sampler import RateSampler
78
from ddtrace._trace.span import Span
89
from ddtrace.appsec._iast._utils import _is_iast_debug_enabled

ddtrace/appsec/_iast/_patch_modules.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
The module uses wrapt's function wrapping capabilities to intercept calls to security-sensitive
1111
functions and enable taint tracking and vulnerability detection.
1212
"""
13+
1314
import functools
1415
from typing import Callable
1516
from typing import Optional
@@ -110,12 +111,7 @@ def unpatch(self):
110111

111112
def __repr__(self):
112113
"""Return a string representation of the IASTFunction instance."""
113-
return (
114-
f"IASTFunction(name={self.name}, "
115-
f"function={self.function}, "
116-
f"hook={self.hook}, "
117-
f"force={self.force})"
118-
)
114+
return f"IASTFunction(name={self.name}, function={self.function}, hook={self.hook}, force={self.force})"
119115

120116

121117
class WrapFunctonsForIAST:

0 commit comments

Comments
 (0)