Skip to content

Commit e358144

Browse files
committed
Polish "Exclude cookie headers by default from HTTP traces"
See gh-22829
1 parent 5ff5157 commit e358144

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

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

Lines changed: 2 additions & 3 deletions
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/src/test/java/org/springframework/boot/actuate/trace/http/HttpExchangeTracerTests.java

Lines changed: 24 additions & 0 deletions
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)