Skip to content

Commit 26940a2

Browse files
committed
check that JSONPath has a leading $ for aws payload tagging environment variable
1 parent 242af42 commit 26940a2

File tree

3 files changed

+191
-0
lines changed

3 files changed

+191
-0
lines changed

ddtrace/_trace/utils_botocore/aws_payload_tagging.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ def _validate_json_paths(self, paths: Optional[str]) -> bool:
121121
# otherwise validate that we have valid JSONPaths
122122
for path in paths.split(","):
123123
if path:
124+
# Require JSONPath to start with "$"
125+
if not path.startswith("$"):
126+
return False
124127
try:
125128
parse(path)
126129
except Exception:

tests/contrib/botocore/test.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3931,6 +3931,38 @@ def test_aws_payload_tagging_sqs(self):
39313931
trace_in_message = "MessageAttributes" in response["Messages"][0]
39323932
assert trace_in_message is False
39333933

3934+
@pytest.mark.snapshot(ignores=snapshot_ignores)
3935+
@mock_sqs
3936+
def test_aws_payload_tagging_sqs_invalid_config(self):
3937+
with self.override_config(
3938+
"botocore",
3939+
dict(payload_tagging_request="non_json_path", payload_tagging_response="$..Attr ibutes.PlatformCredential"),
3940+
):
3941+
pin = Pin(service=self.TEST_SERVICE)
3942+
pin._tracer = self.tracer
3943+
pin.onto(self.sqs_client)
3944+
message_attributes = {
3945+
"one": {"DataType": "String", "StringValue": "one"},
3946+
"two": {"DataType": "String", "StringValue": "two"},
3947+
"three": {"DataType": "String", "StringValue": "three"},
3948+
"four": {"DataType": "String", "StringValue": "four"},
3949+
"five": {"DataType": "String", "StringValue": "five"},
3950+
"six": {"DataType": "String", "StringValue": "six"},
3951+
"seven": {"DataType": "String", "StringValue": "seven"},
3952+
"eight": {"DataType": "String", "StringValue": "eight"},
3953+
"nine": {"DataType": "String", "StringValue": "nine"},
3954+
"ten": {"DataType": "String", "StringValue": "ten"},
3955+
}
3956+
self.sqs_client.send_message(
3957+
QueueUrl=self.sqs_test_queue["QueueUrl"], MessageBody="world", MessageAttributes=message_attributes
3958+
)
3959+
3960+
self.sqs_client.receive_message(
3961+
QueueUrl=self.sqs_test_queue["QueueUrl"],
3962+
MessageAttributeNames=["_datadog"],
3963+
WaitTimeSeconds=2,
3964+
)
3965+
39343966
@pytest.mark.snapshot(ignores=snapshot_ignores)
39353967
@mock_sns
39363968
@mock_sqs
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
[[
2+
{
3+
"name": "sqs.command",
4+
"service": "aws.sqs",
5+
"resource": "sqs.listqueues",
6+
"trace_id": 0,
7+
"span_id": 1,
8+
"parent_id": 0,
9+
"type": "http",
10+
"error": 0,
11+
"meta": {
12+
"_dd.base_service": "tests.contrib.botocore",
13+
"_dd.p.dm": "-0",
14+
"_dd.p.tid": "686be1a100000000",
15+
"aws.agent": "botocore",
16+
"aws.operation": "ListQueues",
17+
"aws.region": "us-east-1",
18+
"aws.requestid": "0VVK8P7HYGMWNR72ZOMDKVN5YWBEMTQB06KZ8UIJFXZCTWB8EOE7",
19+
"aws_service": "sqs",
20+
"component": "botocore",
21+
"http.status_code": "200",
22+
"language": "python",
23+
"region": "us-east-1",
24+
"runtime-id": "7455813a717c4f2db67e4941325daca2",
25+
"span.kind": "client"
26+
},
27+
"metrics": {
28+
"_dd.measured": 1,
29+
"_dd.top_level": 1,
30+
"_dd.tracer_kr": 1.0,
31+
"_sampling_priority_v1": 1,
32+
"process_id": 46598,
33+
"retry_attempts": 0
34+
},
35+
"duration": 13548000,
36+
"start": 1751900577380009000
37+
}],
38+
[
39+
{
40+
"name": "sqs.command",
41+
"service": "aws.sqs",
42+
"resource": "sqs.createqueue",
43+
"trace_id": 1,
44+
"span_id": 1,
45+
"parent_id": 0,
46+
"type": "http",
47+
"error": 0,
48+
"meta": {
49+
"_dd.base_service": "tests.contrib.botocore",
50+
"_dd.p.dm": "-0",
51+
"_dd.p.tid": "686be1a100000000",
52+
"aws.agent": "botocore",
53+
"aws.operation": "CreateQueue",
54+
"aws.region": "us-east-1",
55+
"aws.requestid": "K4YVEQB22VBV7J7O70UXR6OJ2UJIOHP75492EF9JZ2TWGB8B7YRX",
56+
"aws.sqs.queue_name": "Test",
57+
"aws_service": "sqs",
58+
"component": "botocore",
59+
"http.status_code": "200",
60+
"language": "python",
61+
"queuename": "Test",
62+
"region": "us-east-1",
63+
"runtime-id": "7455813a717c4f2db67e4941325daca2",
64+
"span.kind": "client"
65+
},
66+
"metrics": {
67+
"_dd.measured": 1,
68+
"_dd.top_level": 1,
69+
"_dd.tracer_kr": 1.0,
70+
"_sampling_priority_v1": 1,
71+
"process_id": 46598,
72+
"retry_attempts": 0
73+
},
74+
"duration": 5525000,
75+
"start": 1751900577393879000
76+
}],
77+
[
78+
{
79+
"name": "sqs.command",
80+
"service": "test-botocore-tracing.sqs",
81+
"resource": "sqs.sendmessage",
82+
"trace_id": 2,
83+
"span_id": 1,
84+
"parent_id": 0,
85+
"type": "http",
86+
"error": 0,
87+
"meta": {
88+
"_dd.base_service": "tests.contrib.botocore",
89+
"_dd.p.dm": "-0",
90+
"_dd.p.tid": "686be1a100000000",
91+
"aws.agent": "botocore",
92+
"aws.operation": "SendMessage",
93+
"aws.region": "us-east-1",
94+
"aws.requestid": "IJFLTU6W4ECLHWB7LW92UT17VYSEKQ08GBSJD7N5U6TQ1AD9Q22Y",
95+
"aws.sqs.queue_name": "Test",
96+
"aws_account": "000000000000",
97+
"aws_service": "sqs",
98+
"component": "botocore",
99+
"http.status_code": "200",
100+
"language": "python",
101+
"queuename": "Test",
102+
"region": "us-east-1",
103+
"runtime-id": "7455813a717c4f2db67e4941325daca2",
104+
"span.kind": "client"
105+
},
106+
"metrics": {
107+
"_dd.measured": 1,
108+
"_dd.top_level": 1,
109+
"_dd.tracer_kr": 1.0,
110+
"_sampling_priority_v1": 1,
111+
"process_id": 46598,
112+
"retry_attempts": 0
113+
},
114+
"duration": 15291000,
115+
"start": 1751900577404725000
116+
}],
117+
[
118+
{
119+
"name": "sqs.command",
120+
"service": "test-botocore-tracing.sqs",
121+
"resource": "sqs.receivemessage",
122+
"trace_id": 3,
123+
"span_id": 1,
124+
"parent_id": 0,
125+
"type": "http",
126+
"error": 0,
127+
"meta": {
128+
"_dd.base_service": "tests.contrib.botocore",
129+
"_dd.p.dm": "-0",
130+
"_dd.p.tid": "686be1a100000000",
131+
"aws.agent": "botocore",
132+
"aws.operation": "ReceiveMessage",
133+
"aws.region": "us-east-1",
134+
"aws.requestid": "KU9VQAAZ4ZJP5SEV02OTOAUX89HMHSP63ND7QTFBG7EMDCA28W0D",
135+
"aws.sqs.queue_name": "Test",
136+
"aws_account": "000000000000",
137+
"aws_service": "sqs",
138+
"component": "botocore",
139+
"http.status_code": "200",
140+
"language": "python",
141+
"queuename": "Test",
142+
"region": "us-east-1",
143+
"runtime-id": "7455813a717c4f2db67e4941325daca2",
144+
"span.kind": "client"
145+
},
146+
"metrics": {
147+
"_dd.measured": 1,
148+
"_dd.top_level": 1,
149+
"_dd.tracer_kr": 1.0,
150+
"_sampling_priority_v1": 1,
151+
"process_id": 46598,
152+
"retry_attempts": 0
153+
},
154+
"duration": 103000,
155+
"start": 1751900577427944000
156+
}]]

0 commit comments

Comments
 (0)