Skip to content

Commit 77f5874

Browse files
committed
Merge pull request #22829 from emilytsanova
* gh-22829: Polish "Exclude cookie headers by default from HTTP traces" Exclude cookie headers by default from HTTP traces Closes gh-22829
2 parents 8bcf518 + e358144 commit 77f5874

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/trace/http/HttpTraceProperties.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,8 +37,7 @@ public class HttpTraceProperties {
3737

3838
/**
3939
* Items to be included in the trace. Defaults to request headers (excluding
40-
* Authorization but including Cookie), response headers (including Set-Cookie), and
41-
* time taken.
40+
* Authorization and Cookie), response headers (excluding Set-Cookie), and time taken.
4241
*/
4342
private Set<Include> include = new HashSet<>(Include.defaultIncludes());
4443

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json

-1
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,6 @@
653653
"defaultValue": [
654654
"request-headers",
655655
"response-headers",
656-
"cookies",
657656
"errors"
658657
]
659658
},

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/http/Include.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
* Include options for HTTP tracing.
2525
*
2626
* @author Wallace Wadge
27+
* @author Emily Tsanova
28+
* @author Joseph Beeton
2729
* @since 2.0.0
2830
*/
2931
public enum Include {
@@ -55,6 +57,7 @@ public enum Include {
5557
PRINCIPAL,
5658

5759
/**
60+
*
5861
* Include the remote address.
5962
*/
6063
REMOTE_ADDRESS,
@@ -75,7 +78,6 @@ public enum Include {
7578
Set<Include> defaultIncludes = new LinkedHashSet<>();
7679
defaultIncludes.add(Include.REQUEST_HEADERS);
7780
defaultIncludes.add(Include.RESPONSE_HEADERS);
78-
defaultIncludes.add(Include.COOKIE_HEADERS);
7981
defaultIncludes.add(Include.TIME_TAKEN);
8082
DEFAULT_INCLUDES = Collections.unmodifiableSet(defaultIncludes);
8183
}

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/http/HttpExchangeTracerTests.java

+24
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import org.springframework.boot.actuate.trace.http.HttpTrace.Request;
3131
import org.springframework.http.HttpHeaders;
32+
import org.springframework.http.MediaType;
3233
import org.springframework.util.LinkedMultiValueMap;
3334
import org.springframework.util.MultiValueMap;
3435

@@ -270,6 +271,29 @@ void timeTakenCanBeIncluded() {
270271
assertThat(trace.getTimeTaken()).isNotNull();
271272
}
272273

274+
@Test
275+
void defaultIncludes() {
276+
HttpHeaders requestHeaders = new HttpHeaders();
277+
requestHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
278+
requestHeaders.set(HttpHeaders.COOKIE, "value");
279+
requestHeaders.set(HttpHeaders.AUTHORIZATION, "secret");
280+
HttpExchangeTracer tracer = new HttpExchangeTracer(Include.defaultIncludes());
281+
HttpTrace trace = tracer.receivedRequest(createRequest(requestHeaders));
282+
HttpHeaders responseHeaders = new HttpHeaders();
283+
responseHeaders.set(HttpHeaders.SET_COOKIE, "test=test");
284+
responseHeaders.setContentLength(0);
285+
tracer.sendingResponse(trace, createResponse(responseHeaders), this::createPrincipal, () -> "sessionId");
286+
assertThat(trace.getTimeTaken()).isNotNull();
287+
assertThat(trace.getPrincipal()).isNull();
288+
assertThat(trace.getSession()).isNull();
289+
assertThat(trace.getTimestamp()).isNotNull();
290+
assertThat(trace.getRequest().getMethod()).isEqualTo("GET");
291+
assertThat(trace.getRequest().getRemoteAddress()).isNull();
292+
assertThat(trace.getResponse().getStatus()).isEqualTo(204);
293+
assertThat(trace.getRequest().getHeaders()).containsOnlyKeys(HttpHeaders.ACCEPT);
294+
assertThat(trace.getResponse().getHeaders()).containsOnlyKeys(HttpHeaders.CONTENT_LENGTH);
295+
}
296+
273297
private TraceableRequest createRequest() {
274298
return createRequest(Collections.singletonMap(HttpHeaders.ACCEPT, Arrays.asList("application/json")));
275299
}

0 commit comments

Comments
 (0)