Service HTTP Security Headers
CAS has ability to control, on a per-service basis, whether certain security-related HTTP headers should be injected into the response. While headers are typically enabled and defined globally as part of the CAS Security Filter, the strategy described here allows one to disable/enable the injection of these headers for certain applications and service requests and override the global defaults.
Global Configuration
The following settings and properties are available from the CAS configuration catalog:
cas.http-web-request.cors.enabledWhether CORS should be enabled for http requests.
falseWhether CORS should be enabled for http requests.
cas.http-web-request.header.enabledAllow CAS to inject and enforce http security headers via an http filter that are outlined here for caching, HSTS, etc.
trueAllow CAS to inject and enforce http security headers via an http filter that are outlined here for caching, HSTS, etc.
cas.http-web-request.allow-multi-value-parametersWhether CAS should accept multi-valued parameters in incoming requests.
falseWhether CAS should accept multi-valued parameters in incoming requests. Example block would to prevent requests where more than one service parameter is specified.
cas.http-web-request.characters-to-forbidCharacters to block in incoming requests.
noneCharacters to block in incoming requests. none is a special value. Separate characters by a space.
cas.http-web-request.cors.allow-credentialsThe Access-Control-Allow-Credentials header Indicates whether or not the response to the request can be exposed when the credentials flag is true.
trueThe Access-Control-Allow-Credentials header Indicates whether or not the response to the request can be exposed when the credentials flag is true. When used as part of a response to a preflight request, this indicates whether or not the actual request can be made using credentials. Note that simple GET requests are not preflighted, and so if a request is made for a resource with credentials, if this header is not returned with the resource, the response is ignored by the browser and not returned to web content.
cas.http-web-request.cors.allow-headersThe Access-Control-Allow-Headers header is used in response to a preflight request to indicate which HTTP headers can be used when making the actual request.
The Access-Control-Allow-Headers header is used in response to a preflight request to indicate which HTTP headers can be used when making the actual request. Default is everything.
cas.http-web-request.cors.allow-methodsThe Access-Control-Allow-Methods header specifies the method or methods allowed when accessing the resource.
The Access-Control-Allow-Methods header specifies the method or methods allowed when accessing the resource. This is used in response to a pre-flight request. The conditions under which a request is pre-flighted are discussed above. Default is everything.
cas.http-web-request.cors.allow-origin-patternsComma-separated list of origin patterns to allow.
Comma-separated list of origin patterns to allow. Unlike allowed origins which only supports *, origin patterns are more flexible (for example https://*.example.com) and can be used when credentials are allowed. When no allowed origin patterns or allowed origins are set, CORS support is disabled.
cas.http-web-request.cors.allow-originsThe Origin header indicates the origin of the cross-site access request or preflight request.
The Origin header indicates the origin of the cross-site access request or preflight request. The origin is a URI indicating the server from which the request initiated. When credentials are allowed, '*' cannot be used and origin patterns should be configured instead. It does not include any path information, but only the server name.
cas.http-web-request.cors.exposed-headersThe Access-Control-Expose-Headers header lets a server accept headers that browsers are allowed to access.
The Access-Control-Expose-Headers header lets a server accept headers that browsers are allowed to access.
cas.http-web-request.cors.max-ageThe Access-Control-Max-Age header indicates how long the results of a preflight request can be cached.
3600The Access-Control-Max-Age header indicates how long the results of a preflight request can be cached.
cas.http-web-request.custom-headersCustom response headers to inject into the response as needed.
Custom response headers to inject into the response as needed.
cas.http-web-request.header.cacheWhen true, will inject the following headers into the response for non-static resources.
trueCache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: 0
cas.http-web-request.header.cache-control-static-resourcesFiles with these extensions are considered static, so they will be cached by browsers.
css|js|png|txt|jpg|ico|jpeg|bmp|gifFiles with these extensions are considered static, so they will be cached by browsers. The value is part of a RegEx.
cas.http-web-request.header.content-security-policyHelps you reduce XSS risks on modern browsers by declaring what dynamic resources are allowed to load via a HTTP Header.
script-src 'self' 'unsafe-inline' 'unsafe-eval' https://www.googletagmanager.com https://www.google.com; object-src 'none'; worker-src 'self' blob: 'unsafe-inline';Helps you reduce XSS risks on modern browsers by declaring what dynamic resources are allowed to load via a HTTP Header. Header value is made up of one or more directives. Multiple directives are separated with a semicolon. @nonce@ is a specific value which is replaced by a generated random value saved as the request attribute 'contentSecurityPolicyGeneratedNonce'.
cas.http-web-request.header.hstsWhen true, will inject the following headers into the response: Strict-Transport-Security: ... .
trueWhen true, will inject the following headers into the response: Strict-Transport-Security: ....
cas.http-web-request.header.hsts-optionsControl the value of the Strict-Transport-Security header.
max-age=15768000 ; includeSubDomainsControl the value of the Strict-Transport-Security header.
cas.http-web-request.header.xcontentWhen true, will inject the following headers into the response: X-Content-Type-Options: nosniff .
trueWhen true, will inject the following headers into the response: X-Content-Type-Options: nosniff.
cas.http-web-request.header.xframeWhen true, will inject the following headers into the response: X-Frame-Options: DENY .
trueWhen true, will inject the following headers into the response: X-Frame-Options: DENY.
cas.http-web-request.header.xframe-optionsWill inject values into the X-Frame-Options header into the response.
DENYWill inject values into the X-Frame-Options header into the response.
cas.http-web-request.header.xssWhen true, will inject the following headers into the response: X-XSS-Protection: 1; mode=block .
trueWhen true, will inject the following headers into the response: X-XSS-Protection: 1; mode=block.
cas.http-web-request.header.xss-optionsWill inject values into the X-XSS-Protection header into the response.
1; mode=blockWill inject values into the X-XSS-Protection header into the response.
cas.http-web-request.only-post-paramsParameters that are only allowed and accepted during posts.
passwordParameters that are only allowed and accepted during posts.
cas.http-web-request.params-to-checkParameters to sanitize and cross-check in incoming requests.
ticket,service,renew,gateway,warn,method,target,SAMLart,pgtUrl,pgt,pgtId,pgtIou,targetService,entityId,tokenParameters to sanitize and cross-check in incoming requests. Separate parameter names by a comma. The special value * instructs the Filter to check all parameters.
cas.http-web-request.pattern-to-blockSpecify a regular expression that would be checked against the request URL.
Specify a regular expression that would be checked against the request URL. If a successful match is found, the request would be blocked.
cas.http-web-request.web.encodingControl and specify the encoding for all http requests.
Control and specify the encoding for all http requests.
cas.http-web-request.web.force-encodingWhether specified encoding should be forced for every request.
trueWhether specified encoding should be forced for every request. Whether the specified encoding is supposed to override existing request and response encodings
Required settings may be needed to activate or affect the feature; review them even when they have a default. Optional settings only need to be set to change a default or to turn on the behavior they control. Third party settings belong to libraries such as Spring Boot that CAS builds on; their own documentation may have more detail.
Notes on configuration
Configuration Metadata
The collection of configuration properties listed in this section are automatically generated from the CAS source and components that contain the actual field definitions, types, descriptions, modules, etc. This metadata may not always be 100% accurate, or could be lacking details and sufficient explanations.
Be Selective
This section is meant as a guide only. Do NOT copy/paste the entire collection of settings into your CAS configuration; rather pick only the properties that you need. Do NOT enable settings unless you are certain of their purpose and do NOT copy settings into your configuration only to keep them as reference. All these ideas lead to upgrade headaches, maintenance nightmares and premature aging.
YAGNI
Note that for nearly ALL use cases, declaring and configuring properties listed here is sufficient. You should NOT have to explicitly massage a CAS XML/Java/etc configuration file to design an authentication handler, create attribute release policies, etc. CAS at runtime will auto-configure all required changes for you. If you are unsure about the meaning of a given CAS setting, do NOT turn it on without hesitation. Review the codebase or better yet, ask questions to clarify the intended behavior.
Naming Convention
Property names can be specified in very relaxed terms. For instance cas.someProperty, cas.some-property, cas.some_property are all valid names. While all
forms are accepted by CAS, there are certain components (in CAS and other frameworks used) whose activation at runtime is conditional on a property value, where
this property is required to have been specified in CAS configuration using kebab case. This is both true for properties that are owned by CAS as well as those
that might be presented to the system via an external library or framework such as Spring Boot, etc.
When possible, properties should be stored in lower-case kebab format, such as cas.property-name=value.
The only possible exception to this rule is when naming actuator endpoints; The name of the
actuator endpoints (i.e. ssoSessions) MUST remain in camelCase mode.
Settings and properties that are controlled by the CAS platform directly always begin with the prefix cas. All other settings are controlled and provided
to CAS via other underlying frameworks and may have their own schemas and syntax. BE CAREFUL with
the distinction. Unrecognized properties are rejected by CAS and/or frameworks upon which CAS depends. This means if you somehow misspell a property definition
or fail to adhere to the dot-notation syntax and such, your setting is entirely refused by CAS and likely the feature it controls will never be activated in the
way you intend.
Validation
Configuration properties are automatically validated on CAS startup to report issues with configuration binding, especially if defined CAS settings cannot be recognized or validated by the configuration schema. Additional validation processes are also handled via Configuration Metadata and property migrations applied automatically on startup by Spring Boot and family.
Indexed Settings
CAS settings able to accept multiple values are typically documented with an index, such as cas.some.setting[0]=value. The index [0] is meant to be
incremented by the adopter to allow for distinct multiple configuration blocks.
Service HTTP Headers
The following properties are available and recognized by CAS for various modules and features:
| Name | Default Value | Type | Group |
|---|---|---|---|
httpHeaderEnableCacheControl
|
true
|
BOOLEAN
|
HTTP_HEADERS
|
httpHeaderEnableXContentOptions
|
true
|
BOOLEAN
|
HTTP_HEADERS
|
httpHeaderEnableStrictTransportSecurity
|
true
|
BOOLEAN
|
HTTP_HEADERS
|
httpHeaderStrictTransportSecurity
|
|
STRING
|
HTTP_HEADERS
|
httpHeaderEnableXFrameOptions
|
true
|
BOOLEAN
|
HTTP_HEADERS
|
httpHeaderXFrameOptions
|
DENY
|
STRING
|
HTTP_HEADERS
|
httpHeaderEnableContentSecurityPolicy
|
true
|
STRING
|
HTTP_HEADERS
|
httpHeaderEnableXSSProtection
|
true
|
BOOLEAN
|
HTTP_HEADERS
|
A sample JSON file follows:
1
2
3
4
5
6
7
8
9
10
11
12
13
{
"@class" : "org.apereo.cas.services.CasRegisteredService",
"serviceId" : "^https://.+",
"name" : "sample service",
"id" : 100,
"properties" : {
"@class" : "java.util.HashMap",
"httpHeaderEnableXContentOptions" : {
"@class" : "org.apereo.cas.services.DefaultRegisteredServiceProperty",
"values" : [ "java.util.HashSet", [ "true" ] ]
}
}
}
CORS Policies
Cross-origin resource sharing (CORS) policies can also be defined per application in form of service properties.
The following properties are available and recognized by CAS for various modules and features:
| Name | Default Value | Type | Group |
|---|---|---|---|
corsAllowCredentials
|
false
|
BOOLEAN
|
CORS
|
corsMaxAge
|
|
INTEGER
|
CORS
|
corsAllowedOrigins
|
|
STRING
|
CORS
|
corsAllowedOriginPatterns
|
|
STRING
|
CORS
|
corsAllowedMethods
|
|
STRING
|
CORS
|
corsAllowedHeaders
|
|
STRING
|
CORS
|
corsExposedHeaders
|
|
STRING
|
CORS
|
A sample JSON file follows:
1
2
3
4
5
6
7
8
9
10
11
12
13
{
"@class" : "org.apereo.cas.services.CasRegisteredService",
"serviceId" : "^https://.+",
"name" : "sample service",
"id" : 100,
"properties" : {
"@class" : "java.util.HashMap",
"corsMaxAge" : {
"@class" : "org.apereo.cas.services.DefaultRegisteredServiceProperty",
"values" : [ "java.util.HashSet", [ "1000" ] ]
}
}
}