File tree Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 1
1
Unreleased Changes
2
2
------------------
3
3
4
+ * Issue - Validate that ` _X_AMZN_TRACE_ID ` ENV value contains only valid, non-control characters.
5
+
4
6
3.133.0 (2022-08-22)
5
7
------------------
6
8
Original file line number Diff line number Diff line change @@ -11,12 +11,21 @@ def call(context)
11
11
12
12
unless context . http_request . headers . key? ( 'x-amzn-trace-id' )
13
13
if ENV [ 'AWS_LAMBDA_FUNCTION_NAME' ] &&
14
- ( trace_id = ENV [ '_X_AMZN_TRACE_ID' ] )
14
+ ( trace_id = validate_header ( ENV [ '_X_AMZN_TRACE_ID' ] ) )
15
15
context . http_request . headers [ 'x-amzn-trace-id' ] = trace_id
16
16
end
17
17
end
18
18
@handler . call ( context )
19
19
end
20
+
21
+ private
22
+ def validate_header ( header_value )
23
+ if ( header_value . chars & ( 0 ..31 ) . map ( &:chr ) ) . any?
24
+ raise ArgumentError , 'Invalid _X_AMZN_TRACE_ID value: ' \
25
+ 'contains ASCII control characters'
26
+ end
27
+ header_value
28
+ end
20
29
end
21
30
22
31
# should be at the end of build so that
Original file line number Diff line number Diff line change @@ -87,6 +87,16 @@ module Plugins
87
87
resp = client . operation_with_trace_id ( trace_id : user_trace_id )
88
88
expect ( resp . context . http_request . headers [ 'x-amzn-trace-id' ] ) . to eq ( user_trace_id )
89
89
end
90
+
91
+ context 'X_AMX_TRACE_ID with invalid characters' do
92
+ let ( :env_trace_id ) { "invalid header" + 31 . chr }
93
+
94
+ it 'validates the trace-id and raises an error' do
95
+ expect do
96
+ client . operation_with_trace_id
97
+ end . to raise_error ( ArgumentError )
98
+ end
99
+ end
90
100
end
91
101
end
92
102
end
You can’t perform that action at this time.
0 commit comments