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
31 changes: 0 additions & 31 deletions server/configs/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -122,37 +122,6 @@ management.server.port=@@shutdownPort@@
#jsonaccesslog.condition-if=attributeName
#jsonaccesslog.condition-unless=attributeName

## START OF CSP ENFORCE BLOCK (DO NOT CHANGE THIS TEXT)
#useLocalBuild#csp.enforce=\
#useLocalBuild# default-src 'self' ; /* Limit the default to only the current server */\
#useLocalBuild# connect-src 'self' ${CONNECTION.SOURCES} ; /* Limit allowed connection sources */\
#useLocalBuild# object-src 'none' ; /* These tags are not currently used by LKS */\
#useLocalBuild# style-src 'self' 'unsafe-inline' ${STYLE.SOURCES} ; /* We currently have a few inline <style> tags that we are weeding out */\
#useLocalBuild# img-src 'self' data: ${IMAGE.SOURCES} ; /* Limit image loading locations */\
#useLocalBuild# font-src 'self' data: ${FONT.SOURCES} ; /* Limit font source loading locations */\
#useLocalBuild# script-src 'unsafe-eval' 'strict-dynamic' 'nonce-${REQUEST.SCRIPT.NONCE}' ; /* Limit scripts to those with nonces or transitive scripts */\
#useLocalBuild# base-uri 'self' ; /* Limit the base tags to only source from current server */\
#useLocalBuild# ${UPGRADE.INSECURE.REQUESTS} /* Conditionally add upgrade-secure-requests directive if HTTPS is required */\
#useLocalBuild# frame-ancestors 'self' ; /* Limit iframe content destinations (who can load this server's content into an iframe) */\
#useLocalBuild# frame-src 'self' ${FRAME.SOURCES} ; /* Limit iframe content sources (from what servers can this server's iframe content be loaded) */\
#useLocalBuild# report-uri /admin-contentSecurityPolicyReport.api?cspVersion=e12&${CSP.REPORT.PARAMS} ; /* Report any encountered CSP violations to the local server */
## END OF CSP ENFORCE BLOCK (DO NOT CHANGE THIS TEXT)

## START OF CSP REPORT BLOCK (DO NOT CHANGE THIS TEXT)
csp.report=\
default-src 'self' ; /* Limit the default to only the current server */\
connect-src 'self' ${CONNECTION.SOURCES} ; /* Limit allowed connection sources */\
object-src 'none' ; /* These tags are not currently used by LKS */\
style-src 'self' 'unsafe-inline' ${STYLE.SOURCES} ; /* We currently have a few inline <style> tags that we are weeding out */\
img-src 'self' data: ${IMAGE.SOURCES} ; /* Limit image loading locations */\
font-src 'self' data: ${FONT.SOURCES} ; /* Limit font source loading locations */\
script-src 'unsafe-eval' 'strict-dynamic' 'nonce-${REQUEST.SCRIPT.NONCE}' ; /* Limit scripts to those with nonces or transitive scripts */\
base-uri 'self' ; /* Limit the base tags to only source from current server */\
frame-ancestors 'self' ; /* Limit iframe content destinations (who can load this server's content into an iframe) */\
frame-src 'self' ${FRAME.SOURCES} ; /* Limit iframe content sources (from what servers can this server's iframe content be loaded) */\
report-uri /admin-contentSecurityPolicyReport.api?cspVersion=r12&${CSP.REPORT.PARAMS} ; /* Report any encountered CSP violations to the local server */
## END OF CSP REPORT BLOCK (DO NOT CHANGE THIS TEXT)

## Use a custom logging configuration
#logging.config=path/to/alternative/log4j2.xml

Expand Down
31 changes: 0 additions & 31 deletions server/configs/webapps/embedded/config/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -107,34 +107,3 @@ mail.smtpUser=Anonymous
## property name after the "context.additionalWebapps." prefix, and the value is the location of the webapp on disk
#context.additionalWebapps.firstContextPath=@@/my/webapp/path@@
#context.additionalWebapps.secondContextPath=@@/my/other/webapp/path@@

## Strong enforce content security policy. Uncomment this when you've tested the strong report-only policy (configured
## by default via server code and shown below).
#csp.enforce=\
# default-src 'self' ; /* Limit the default to only the current server */\
# connect-src 'self' ${CONNECTION.SOURCES} ; /* Limit allowed connection sources */\
# object-src 'none' ; /* These tags are not currently used by LKS */\
# style-src 'self' 'unsafe-inline' ${STYLE.SOURCES} ; /* We currently have a few inline <style> tags that we are weeding out */\
# img-src 'self' data: ${IMAGE.SOURCES} ; /* Limit image loading locations */\
# font-src 'self' data: ${FONT.SOURCES} ; /* Limit font source loading locations */\
# script-src 'unsafe-eval' 'strict-dynamic' 'nonce-${REQUEST.SCRIPT.NONCE}' ; /* Limit scripts to those with nonces or transitive scripts */\
# base-uri 'self' ; /* Limit the base tags to only source from current server */\
# frame-ancestors 'self' ; /* Limit iframe content destinations (who can load this server's content into an iframe) */\
# frame-src 'self' ${FRAME.SOURCES} ; /* Limit iframe content sources (from what servers can this server's iframe content be loaded) */\
# report-uri /admin-contentSecurityPolicyReport.api?cspVersion=e11&${CSP.REPORT.PARAMS} ; /* Report any encountered CSP violations to the supplied URL */

## Strict report-only content security policy that reports violations to this server. This matches the default report
## policy that's configured via server code; provided here to document the details and provide a starting point if
## overriding the default CSP is needed. This CSP will become the default *enforce* policy for 25.4 and beyond.
csp.report=\
default-src 'self' ; /* Limit the default to only the current server */\
connect-src 'self' ${CONNECTION.SOURCES} ; /* Limit allowed connection sources */\
object-src 'none' ; /* These tags are not currently used by LKS */\
style-src 'self' 'unsafe-inline' ${STYLE.SOURCES} ; /* We currently have a few inline <style> tags that we are weeding out */\
img-src 'self' data: ${IMAGE.SOURCES} ; /* Limit image loading locations */\
font-src 'self' data: ${FONT.SOURCES} ; /* Limit font source loading locations */\
script-src 'unsafe-eval' 'strict-dynamic' 'nonce-${REQUEST.SCRIPT.NONCE}' ; /* Limit scripts to those with nonces or transitive scripts */\
base-uri 'self' ; /* Limit the base tags to only source from current server */\
frame-ancestors 'self' ; /* Limit iframe content destinations (who can load this server's content into an iframe) */\
frame-src 'self' ${FRAME.SOURCES} ; /* Limit iframe content sources (from what servers can this server's iframe content be loaded) */\
report-uri /admin-contentSecurityPolicyReport.api?cspVersion=r11&${CSP.REPORT.PARAMS} ; /* Report any encountered CSP violations to the supplied URL */
38 changes: 23 additions & 15 deletions server/embedded/src/org/labkey/embedded/LabKeyServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public static void main(String[] args)

SpringApplication application = new SpringApplication(LabKeyServer.class);
application.addListeners(new ApplicationPidFileWriter("./labkey.pid"));
// A strong Content Security Policy that reports violations to this server
String strongCsp = """
// A strong Content Security Policy
String baseCsp = """
default-src 'self' ;
connect-src 'self' ${CONNECTION.SOURCES} ;
object-src 'none' ;
Expand All @@ -76,27 +76,35 @@ public static void main(String[] args)
font-src 'self' data: ${FONT.SOURCES} ;
script-src 'unsafe-eval' 'strict-dynamic' 'nonce-${REQUEST.SCRIPT.NONCE}' ;
base-uri 'self' ;
frame-src 'self' ${FRAME.SOURCES} ;
""";
// Add upgrade_insecure_requests substitution, frame-ancestors, and e12 version for enforce CSP
String enforceCsp = baseCsp + """
${UPGRADE.INSECURE.REQUESTS}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this not need a ; at the end?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The substitution adds the ;

This way, if running without HTTPS we don't get an extra semicolon

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

frame-ancestors 'self' ;
frame-src 'self' ${FRAME.SOURCES} ;
report-uri /admin-contentSecurityPolicyReport.api?cspVersion=r12&${CSP.REPORT.PARAMS}
report-uri /admin-contentSecurityPolicyReport.api?cspVersion=e12&${CSP.REPORT.PARAMS} ;
""";
// Leave out upgrade_insecure_requests and frame-ancestors directives, since they produce warnings on some browsers
String reportCsp = baseCsp + """
report-uri /admin-contentSecurityPolicyReport.api?cspVersion=r12&${CSP.REPORT.PARAMS} ;
""";
application.setDefaultProperties(Map.of(
"server.tomcat.basedir", ".",
"server.tomcat.accesslog.directory", logHome,
"server.tomcat.basedir", ".",
"server.tomcat.accesslog.directory", logHome,

// Enable HTTP compression for response content
"server.compression.enabled", "true",
// Enable HTTP compression for response content
"server.compression.enabled", "true",

"server.tomcat.accesslog.enabled", "true",
"server.tomcat.accesslog.pattern", "%h %l %u %t \"%r\" %s %b %D %S %I \"%{Referer}i\" \"%{User-Agent}i\" %{LABKEY.username}s %{X-Forwarded-For}i",
"jsonaccesslog.pattern", "%h %t %m %U %s %b %D %S \"%{Referer}i\" \"%{User-Agent}i\" %{LABKEY.username}s %{X-Forwarded-For}i",
"server.tomcat.accesslog.enabled", "true",
"server.tomcat.accesslog.pattern", "%h %l %u %t \"%r\" %s %b %D %S %I \"%{Referer}i\" \"%{User-Agent}i\" %{LABKEY.username}s %{X-Forwarded-For}i",
"jsonaccesslog.pattern", "%h %t %m %U %s %b %D %S \"%{Referer}i\" \"%{User-Agent}i\" %{LABKEY.username}s %{X-Forwarded-For}i",

// Issue 52415: Omit stack traces from Tomcat error pages by default, but propagate error messages
"server.error.include-stacktrace", "never",
"server.error.include-message", "always",
// Issue 52415: Omit stack traces from Tomcat error pages by default, but propagate error messages
"server.error.include-stacktrace", "never",
"server.error.include-message", "always",

"csp.report", strongCsp
"csp.enforce", enforceCsp,
"csp.report", reportCsp
));
application.setBannerMode(Banner.Mode.OFF);
application.run(args);
Expand Down