2016-02-03 10:20:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Red Hat, Inc. and/or its affiliates
|
|
|
|
* and other contributors as indicated by the @author tags.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2015-07-17 11:45:43 +00:00
|
|
|
package org.keycloak.models;
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2020-06-17 12:31:08 +00:00
|
|
|
public enum BrowserSecurityHeaders {
|
|
|
|
|
|
|
|
X_FRAME_OPTIONS("xFrameOptions", "X-Frame-Options", "SAMEORIGIN"),
|
|
|
|
CONTENT_SECURITY_POLICY("contentSecurityPolicy", "Content-Security-Policy", ContentSecurityPolicyBuilder.create().build()),
|
|
|
|
CONTENT_SECURITY_POLICY_REPORT_ONLY("contentSecurityPolicyReportOnly", "Content-Security-Policy-Report-Only", ""),
|
|
|
|
X_CONTENT_TYPE_OPTIONS("xContentTypeOptions", "X-Content-Type-Options", "nosniff"),
|
|
|
|
X_ROBOTS_TAG("xRobotsTag", "X-Robots-Tag", "none"),
|
|
|
|
X_XSS_PROTECTION("xXSSProtection", "X-XSS-Protection", "1; mode=block"),
|
|
|
|
STRICT_TRANSPORT_SECURITY("strictTransportSecurity", "Strict-Transport-Security", "max-age=31536000; includeSubDomains"),
|
|
|
|
REFERRER_POLICY("referrerPolicy", "Referrer-Policy", "no-referrer"),
|
|
|
|
;
|
|
|
|
|
|
|
|
private final String key;
|
|
|
|
private final String headerName;
|
|
|
|
private final String defaultValue;
|
|
|
|
|
|
|
|
BrowserSecurityHeaders(String key, String headerName, String defaultValue) {
|
|
|
|
this.key = key;
|
|
|
|
this.headerName = headerName;
|
|
|
|
this.defaultValue = defaultValue;
|
|
|
|
}
|
2019-10-16 08:33:55 +00:00
|
|
|
|
2020-06-17 12:31:08 +00:00
|
|
|
public String getKey() {
|
|
|
|
return key;
|
|
|
|
}
|
2019-10-16 08:33:55 +00:00
|
|
|
|
2020-06-17 12:31:08 +00:00
|
|
|
public String getHeaderName() {
|
|
|
|
return headerName;
|
|
|
|
}
|
2019-10-16 08:33:55 +00:00
|
|
|
|
2020-06-17 12:31:08 +00:00
|
|
|
public String getDefaultValue() {
|
|
|
|
return defaultValue;
|
|
|
|
}
|
2019-10-16 08:33:55 +00:00
|
|
|
|
2020-06-17 12:31:08 +00:00
|
|
|
@Deprecated // should be removed eventually
|
|
|
|
public static final Map<String, String> realmDefaultHeaders;
|
2015-07-17 11:45:43 +00:00
|
|
|
|
|
|
|
static {
|
|
|
|
|
2016-03-11 14:25:21 +00:00
|
|
|
Map<String, String> dh = new HashMap<>();
|
2020-06-17 12:31:08 +00:00
|
|
|
dh.put(X_FRAME_OPTIONS.getKey(), X_FRAME_OPTIONS.getDefaultValue());
|
|
|
|
dh.put(CONTENT_SECURITY_POLICY.getKey(), CONTENT_SECURITY_POLICY.getDefaultValue());
|
|
|
|
dh.put(CONTENT_SECURITY_POLICY_REPORT_ONLY.getKey(), CONTENT_SECURITY_POLICY_REPORT_ONLY.getDefaultValue());
|
|
|
|
dh.put(X_CONTENT_TYPE_OPTIONS.getKey(), X_CONTENT_TYPE_OPTIONS.getDefaultValue());
|
|
|
|
dh.put(X_ROBOTS_TAG.getKey(), X_ROBOTS_TAG.getDefaultValue());
|
|
|
|
dh.put(X_XSS_PROTECTION.getKey(), X_XSS_PROTECTION.getDefaultValue());
|
|
|
|
dh.put(STRICT_TRANSPORT_SECURITY.getKey(), STRICT_TRANSPORT_SECURITY.getDefaultValue());
|
|
|
|
|
|
|
|
realmDefaultHeaders = Collections.unmodifiableMap(dh);
|
2015-07-17 11:45:43 +00:00
|
|
|
}
|
2019-10-16 08:33:55 +00:00
|
|
|
}
|