|
@@ -155,7 +155,7 @@ public class RequestInitializationFilter implements Filter {
|
|
|
} catch (Throwable e) {
|
|
|
LOGGER.error("can't load application: " + e.getMessage(),e);
|
|
|
if (!(new PwmURL(req).isResourceURL())) {
|
|
|
- respondWithUnavalailbleError(req, resp);
|
|
|
+ respondWithUnavailableError(req, resp);
|
|
|
return;
|
|
|
}
|
|
|
return;
|
|
@@ -191,7 +191,7 @@ public class RequestInitializationFilter implements Filter {
|
|
|
LOGGER.error(logMsg,e);
|
|
|
}
|
|
|
if (!(new PwmURL(req).isResourceURL())) {
|
|
|
- respondWithUnavalailbleError(req, resp);
|
|
|
+ respondWithUnavailableError(req, resp);
|
|
|
return;
|
|
|
}
|
|
|
return;
|
|
@@ -200,7 +200,7 @@ public class RequestInitializationFilter implements Filter {
|
|
|
filterChain.doFilter(req, resp);
|
|
|
}
|
|
|
|
|
|
- private void respondWithUnavalailbleError(final HttpServletRequest req, final HttpServletResponse resp)
|
|
|
+ private void respondWithUnavailableError( final HttpServletRequest req, final HttpServletResponse resp)
|
|
|
throws ServletException, IOException
|
|
|
{
|
|
|
ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_APP_UNAVAILABLE);
|
|
@@ -307,84 +307,86 @@ public class RequestInitializationFilter implements Filter {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ final boolean includeXSessionID = Boolean.parseBoolean(config.readAppProperty(AppProperty.HTTP_HEADER_SEND_XSESSIONID));
|
|
|
+ if (includeXSessionID && pwmSession != null) {
|
|
|
+ resp.setHeader(HttpHeader.XSessionID, pwmSession.getSessionStateBean().getSessionID());
|
|
|
+ }
|
|
|
+
|
|
|
+ final boolean includeContentLanguage = Boolean.parseBoolean(config.readAppProperty(AppProperty.HTTP_HEADER_SEND_CONTENT_LANGUAGE));
|
|
|
+ if (includeContentLanguage) {
|
|
|
+ resp.setHeader(HttpHeader.Content_Language, pwmRequest.getLocale().toLanguageTag());
|
|
|
+ }
|
|
|
+
|
|
|
+ addStaticResponseHeaders( pwmApplication, resp.getHttpServletResponse() );
|
|
|
+
|
|
|
+
|
|
|
+ if (pwmSession != null) {
|
|
|
+ final String contentPolicy;
|
|
|
+ if (pwmRequest.getURL().isConfigGuideURL() || pwmRequest.getURL().isConfigManagerURL()) {
|
|
|
+ contentPolicy = config.readAppProperty(AppProperty.SECURITY_HTTP_CONFIG_CSP_HEADER);
|
|
|
+ } else {
|
|
|
+ contentPolicy = config.readSettingAsString(PwmSetting.SECURITY_CSP_HEADER);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (contentPolicy != null && !contentPolicy.isEmpty()) {
|
|
|
+ final String nonce = pwmRequest.getCspNonce();
|
|
|
+ final String expandedPolicy = contentPolicy.replace("%NONCE%", nonce);
|
|
|
+ resp.setHeader(HttpHeader.ContentSecurityPolicy, expandedPolicy);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void addStaticResponseHeaders(final PwmApplication pwmApplication, final HttpServletResponse resp) throws PwmUnrecoverableException
|
|
|
+ {
|
|
|
+ final Configuration config = pwmApplication.getConfig();
|
|
|
+
|
|
|
final String serverHeader = config.readAppProperty(AppProperty.HTTP_HEADER_SERVER);
|
|
|
final boolean includeXInstance = Boolean.parseBoolean(config.readAppProperty(AppProperty.HTTP_HEADER_SEND_XINSTANCE));
|
|
|
- final boolean includeXSessionID = Boolean.parseBoolean(config.readAppProperty(AppProperty.HTTP_HEADER_SEND_XSESSIONID));
|
|
|
final boolean includeXVersion = Boolean.parseBoolean(config.readAppProperty(AppProperty.HTTP_HEADER_SEND_XVERSION));
|
|
|
final boolean includeXContentTypeOptions = Boolean.parseBoolean(config.readAppProperty(AppProperty.HTTP_HEADER_SEND_XCONTENTTYPEOPTIONS));
|
|
|
final boolean includeXXSSProtection = Boolean.parseBoolean(config.readAppProperty(AppProperty.HTTP_HEADER_SEND_XXSSPROTECTION));
|
|
|
+ final boolean includeXFrameDeny = config.readSettingAsBoolean(PwmSetting.SECURITY_PREVENT_FRAMING);
|
|
|
+ final boolean includeXAmb = Boolean.parseBoolean(config.readAppProperty(AppProperty.HTTP_HEADER_SEND_XAMB));
|
|
|
|
|
|
- final boolean sendNoise = Boolean.parseBoolean(config.readAppProperty(AppProperty.HTTP_HEADER_SEND_XNOISE));
|
|
|
-
|
|
|
- if (sendNoise) {
|
|
|
- final int noiseLength = Integer.parseInt(config.readAppProperty(AppProperty.HTTP_HEADER_NOISE_LENGTH));
|
|
|
- resp.setHeader(
|
|
|
- HttpHeader.XNoise,
|
|
|
- PwmRandom.getInstance().alphaNumericString(PwmRandom.getInstance().nextInt(noiseLength)+11)
|
|
|
- );
|
|
|
+ {
|
|
|
+ final String noiseHeader = makeNoiseHeader( config );
|
|
|
+ if (noiseHeader != null) {
|
|
|
+ resp.setHeader( HttpHeader.XNoise.getHttpName(), noiseHeader );
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (includeXVersion) {
|
|
|
- resp.setHeader(HttpHeader.XVersion, PwmConstants.SERVLET_VERSION);
|
|
|
+ resp.setHeader(HttpHeader.XVersion.getHttpName(), PwmConstants.SERVLET_VERSION);
|
|
|
}
|
|
|
|
|
|
if (includeXContentTypeOptions) {
|
|
|
- resp.setHeader(HttpHeader.XContentTypeOptions, "nosniff");
|
|
|
+ resp.setHeader(HttpHeader.XContentTypeOptions.getHttpName(), "nosniff");
|
|
|
}
|
|
|
|
|
|
if (includeXXSSProtection) {
|
|
|
- resp.setHeader(HttpHeader.XXSSProtection, "1");
|
|
|
+ resp.setHeader(HttpHeader.XXSSProtection.getHttpName(), "1");
|
|
|
}
|
|
|
|
|
|
if (includeXInstance) {
|
|
|
- resp.setHeader(HttpHeader.XInstance, String.valueOf(pwmApplication.getInstanceID()));
|
|
|
- }
|
|
|
-
|
|
|
- if (includeXSessionID && pwmSession != null) {
|
|
|
- resp.setHeader(HttpHeader.XSessionID, pwmSession.getSessionStateBean().getSessionID());
|
|
|
+ resp.setHeader(HttpHeader.XInstance.getHttpName(), String.valueOf(pwmApplication.getInstanceID()));
|
|
|
}
|
|
|
|
|
|
if (serverHeader != null && !serverHeader.isEmpty()) {
|
|
|
final String value = MacroMachine.forNonUserSpecific(pwmApplication, null).expandMacros(serverHeader);
|
|
|
- resp.setHeader(HttpHeader.Server, value);
|
|
|
+ resp.setHeader(HttpHeader.Server.getHttpName(), value);
|
|
|
}
|
|
|
|
|
|
- // ----- non-resource urls only for the following operations -----
|
|
|
-
|
|
|
- final boolean includeXFrameDeny = config.readSettingAsBoolean(PwmSetting.SECURITY_PREVENT_FRAMING);
|
|
|
- final boolean includeXAmb = Boolean.parseBoolean(config.readAppProperty(AppProperty.HTTP_HEADER_SEND_XAMB));
|
|
|
- final boolean includeContentLanguage = Boolean.parseBoolean(config.readAppProperty(AppProperty.HTTP_HEADER_SEND_CONTENT_LANGUAGE));
|
|
|
-
|
|
|
if (includeXFrameDeny) {
|
|
|
- resp.setHeader(HttpHeader.XFrameOptions, "DENY");
|
|
|
+ resp.setHeader(HttpHeader.XFrameOptions.getHttpName(), "DENY");
|
|
|
}
|
|
|
|
|
|
if (includeXAmb) {
|
|
|
- resp.setHeader(HttpHeader.XAmb, PwmConstants.X_AMB_HEADER.get(
|
|
|
+ resp.setHeader(HttpHeader.XAmb.getHttpName(), PwmConstants.X_AMB_HEADER.get(
|
|
|
PwmRandom.getInstance().nextInt(PwmConstants.X_AMB_HEADER.size())
|
|
|
));
|
|
|
}
|
|
|
|
|
|
- if (includeContentLanguage) {
|
|
|
- resp.setHeader(HttpHeader.Content_Language, pwmRequest.getLocale().toLanguageTag());
|
|
|
- }
|
|
|
-
|
|
|
- resp.setHeader(HttpHeader.Cache_Control, "no-cache, no-store, must-revalidate, proxy-revalidate");
|
|
|
-
|
|
|
- if (pwmSession != null) {
|
|
|
- final String contentPolicy;
|
|
|
- if (pwmRequest.getURL().isConfigGuideURL() || pwmRequest.getURL().isConfigManagerURL()) {
|
|
|
- contentPolicy = config.readAppProperty(AppProperty.SECURITY_HTTP_CONFIG_CSP_HEADER);
|
|
|
- } else {
|
|
|
- contentPolicy = config.readSettingAsString(PwmSetting.SECURITY_CSP_HEADER);
|
|
|
- }
|
|
|
-
|
|
|
- if (contentPolicy != null && !contentPolicy.isEmpty()) {
|
|
|
- final String nonce = pwmRequest.getCspNonce();
|
|
|
- final String expandedPolicy = contentPolicy.replace("%NONCE%", nonce);
|
|
|
- resp.setHeader(HttpHeader.ContentSecurityPolicy, expandedPolicy);
|
|
|
- }
|
|
|
- }
|
|
|
+ resp.setHeader(HttpHeader.Cache_Control.getHttpName(), "no-cache, no-store, must-revalidate, proxy-revalidate");
|
|
|
}
|
|
|
|
|
|
|
|
@@ -685,4 +687,15 @@ public class RequestInitializationFilter implements Filter {
|
|
|
return StringUtil.mapToString(values);
|
|
|
}
|
|
|
|
|
|
+ private static String makeNoiseHeader(final Configuration configuration) {
|
|
|
+ final boolean sendNoise = Boolean.parseBoolean(configuration.readAppProperty(AppProperty.HTTP_HEADER_SEND_XNOISE));
|
|
|
+
|
|
|
+ if (sendNoise) {
|
|
|
+ final int noiseLength = Integer.parseInt(configuration.readAppProperty(AppProperty.HTTP_HEADER_NOISE_LENGTH));
|
|
|
+ return PwmRandom.getInstance().alphaNumericString(PwmRandom.getInstance().nextInt(noiseLength)+11);
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
}
|