Skip to content

Commit 4c421c0

Browse files
authored
[fix](fe) Mask sensitive headers in stream load logs (#62108)
FE stream load REST logs printed full request headers, which could leak Authorization and token values into INFO logs. Changes: - Mask values for a small set of sensitive headers (e.g., Authorization, token) in getAllHeaders() - Add isSensitiveHeader() helper to centralize the masking decision
1 parent a1910e4 commit 4c421c0

2 files changed

Lines changed: 59 additions & 1 deletion

File tree

fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/LoadAction.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,12 +671,21 @@ private String getAllHeaders(HttpServletRequest request) {
671671
Enumeration<String> headerNames = request.getHeaderNames();
672672
while (headerNames.hasMoreElements()) {
673673
String headerName = headerNames.nextElement();
674-
String headerValue = request.getHeader(headerName);
674+
String headerValue = isSensitiveHeader(headerName) ? "***MASKED***" : request.getHeader(headerName);
675675
headers.append(headerName).append(":").append(headerValue).append(", ");
676676
}
677677
return headers.toString();
678678
}
679679

680+
private boolean isSensitiveHeader(String headerName) {
681+
return "Authorization".equalsIgnoreCase(headerName)
682+
|| "Proxy-Authorization".equalsIgnoreCase(headerName)
683+
|| "Cookie".equalsIgnoreCase(headerName)
684+
|| "Set-Cookie".equalsIgnoreCase(headerName)
685+
|| "token".equalsIgnoreCase(headerName)
686+
|| "Auth-Token".equalsIgnoreCase(headerName);
687+
}
688+
680689
private Backend selectBackendForGroupCommit(String clusterName, HttpServletRequest req, long tableId)
681690
throws LoadException {
682691
ConnectContext ctx = new ConnectContext();
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.doris.httpv2.rest;
19+
20+
import jakarta.servlet.http.HttpServletRequest;
21+
import org.junit.Assert;
22+
import org.junit.Test;
23+
import org.mockito.Mockito;
24+
25+
import java.lang.reflect.Method;
26+
import java.util.Arrays;
27+
import java.util.Collections;
28+
29+
public class LoadActionTest {
30+
31+
@Test
32+
public void testGetAllHeadersMasksSensitiveHeaders() throws Exception {
33+
LoadAction action = new LoadAction();
34+
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
35+
Mockito.when(request.getHeaderNames()).thenReturn(Collections.enumeration(Arrays.asList(
36+
"Authorization", "Cookie", "Set-Cookie", "token", "label")));
37+
Mockito.when(request.getHeader("label")).thenReturn("load_label");
38+
39+
Method method = LoadAction.class.getDeclaredMethod("getAllHeaders", HttpServletRequest.class);
40+
method.setAccessible(true);
41+
String headers = (String) method.invoke(action, request);
42+
43+
Assert.assertTrue(headers.contains("Authorization:***MASKED***"));
44+
Assert.assertTrue(headers.contains("Cookie:***MASKED***"));
45+
Assert.assertTrue(headers.contains("Set-Cookie:***MASKED***"));
46+
Assert.assertTrue(headers.contains("token:***MASKED***"));
47+
Assert.assertTrue(headers.contains("label:load_label"));
48+
}
49+
}

0 commit comments

Comments
 (0)