Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,33 @@ public PrintWriter getWriter() throws IOException {

@Override
public void setHeader(String name, String value) {
checkForContentSecurityPolicy(name);
if (shouldInject) {
if (isContentLengthHeader(name)) {
return;
}
checkForContentSecurityPolicy(name);
}
super.setHeader(name, value);
}

@Override
public void addHeader(String name, String value) {
checkForContentSecurityPolicy(name);
if (shouldInject) {
if (isContentLengthHeader(name)) {
return;
}
checkForContentSecurityPolicy(name);
}
super.addHeader(name, value);
}

private boolean isContentLengthHeader(String name) {
return "content-length".equalsIgnoreCase(name);
}

private void checkForContentSecurityPolicy(String name) {
if (name != null) {
if (name.startsWith("Content-Security-Policy")) {
RumInjector.getTelemetryCollector().onContentSecurityPolicyDetected(servletVersion);
}
if ("content-security-policy".equalsIgnoreCase(name)) {
RumInjector.getTelemetryCollector().onContentSecurityPolicyDetected(servletVersion);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,33 @@ public PrintWriter getWriter() throws IOException {

@Override
public void setHeader(String name, String value) {
checkForContentSecurityPolicy(name);
if (shouldInject) {
if (isContentLengthHeader(name)) {
return;
}
checkForContentSecurityPolicy(name);
}
super.setHeader(name, value);
}

@Override
public void addHeader(String name, String value) {
checkForContentSecurityPolicy(name);
if (shouldInject) {
if (isContentLengthHeader(name)) {
return;
}
checkForContentSecurityPolicy(name);
}
super.addHeader(name, value);
}

private boolean isContentLengthHeader(String name) {
return "content-length".equalsIgnoreCase(name);
}

private void checkForContentSecurityPolicy(String name) {
if (name != null) {
if (name.startsWith("Content-Security-Policy")) {
RumInjector.getTelemetryCollector().onContentSecurityPolicyDetected(servletVersion);
}
if ("content-security-policy".equalsIgnoreCase(name)) {
RumInjector.getTelemetryCollector().onContentSecurityPolicyDetected(servletVersion);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ class SpringBootBasedTest extends HttpServerTest<ConfigurableApplicationContext>
true
}

@Override
boolean testRumInjection() {
true
}

@Override
Serializable expectedServerSpanRoute(ServerEndpoint endpoint) {
switch (endpoint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,27 @@ class TestController {
}
}

@RequestMapping(value = "/gimme-xml", produces = "text/xml")
@ResponseBody
String gimmeXml() {
"<test/>"
}

@RequestMapping(value = "/gimme-html", produces = "text/html")
@ResponseBody
String gimmeHtml() {
"\n" +
"<!doctype html>\n" +
"<html>\n" +
" <head>\n" +
" <title>This is the title of the webpage!</title>\n" +
" </head>\n" +
" <body>\n" +
" <p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p>\n" +
" </body>\n" +
"</html>"
}

@ExceptionHandler
ResponseEntity handleException(Throwable throwable) {
new ResponseEntity(throwable.message, HttpStatus.INTERNAL_SERVER_ERROR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ class SpringBootBasedTest extends HttpServerTest<ConfigurableApplicationContext>
true
}

@Override
boolean testRumInjection() {
true
}

@Override
void assertEndpointDiscovery(final List<?> endpoints) {
final discovered = endpoints.collectEntries { [(it.method): it] } as Map<String, Endpoint>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,27 @@ class TestController {
}
}

@RequestMapping(value = "/gimme-xml", produces = "text/xml")
@ResponseBody
String gimmeXml() {
"<test/>"
}

@RequestMapping(value = "/gimme-html", produces = "text/html")
@ResponseBody
String gimmeHtml() {
"\n" +
"<!doctype html>\n" +
"<html>\n" +
" <head>\n" +
" <title>This is the title of the webpage!</title>\n" +
" </head>\n" +
" <body>\n" +
" <p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p>\n" +
" </body>\n" +
"</html>"
}

@RequestMapping(value = "/discovery",
method = [RequestMethod.POST, RequestMethod.PATCH, RequestMethod.PUT],
consumes = MediaType.APPLICATION_JSON_VALUE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ class SpringBootBasedTest extends HttpServerTest<ConfigurableApplicationContext>
true
}

@Override
boolean testRumInjection() {
true
}

@Override
Map<String, Serializable> expectedExtraErrorInformation(ServerEndpoint endpoint) {
// latest DispatcherServlet throws if no handlers have been found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,27 @@ class TestController {
}
}

@RequestMapping(value = "/gimme-xml", produces = "text/xml")
@ResponseBody
String gimmeXml() {
"<test/>"
}

@RequestMapping(value = "/gimme-html", produces = "text/html")
@ResponseBody
String gimmeHtml() {
"\n" +
"<!doctype html>\n" +
"<html>\n" +
" <head>\n" +
" <title>This is the title of the webpage!</title>\n" +
" </head>\n" +
" <body>\n" +
" <p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p>\n" +
" </body>\n" +
"</html>"
}

@ExceptionHandler
ResponseEntity handleException(Throwable throwable) {
new ResponseEntity(throwable.message, HttpStatus.INTERNAL_SERVER_ERROR)
Expand Down