Skip to content

Commit

Permalink
[ZEPPELIN-2775] Strict-Transport-Security and X-XSS-Protection Headers
Browse files Browse the repository at this point in the history
### What is this PR for?
The HTTP Strict-Transport-Security response header (often abbreviated as HSTS) is a security feature that lets a web site tell browsers that it should only be communicated with using HTTPS, instead of using HTTP.
Note: The Strict-Transport-Security header is ignored by the browser when your site is accessed using HTTP; this is because an attacker may intercept HTTP connections and inject the header or remove it. When your site is accessed over HTTPS with no certificate errors, the browser knows your site is HTTPS capable and will honor the Strict-Transport-Security header.

The HTTP X-XSS-Protection response header is a feature of Internet Explorer, Chrome and Safari that stops pages from loading when they detect reflected cross-site scripting (XSS) attacks.

### What type of PR is it?
[Bug Fix | Improvement ]

### What is the Jira issue?
* [ZEPPELIN-2775](https://issues.apache.org/jira/browse/ZEPPELIN-2775)

### How should this be tested?
Make a curl call to Zeppelin? Go to Chrome Browser and select "More Tools" -> "Developer Tools" from the right-side menu. Under Network Section, select any request and check for "Response Headers". You should see below headers along with existing ones.

> strict-transport-security:max-age=631138519
> x-xss-protection:1; mode=block

<img width="1436" alt="screen shot 2017-07-14 at 8 19 14 pm" src="https://user-images.githubusercontent.com/6433184/28217231-16ce6cee-68d2-11e7-91aa-77ad083612c7.png">

### Questions:
* Does this needs documentation?

Author: krishna-pandey <krish.pandey21@gmail.com>

Closes apache#2492 from krishna-pandey/ZEPPELIN-2775 and squashes the following commits:

7d9978e [krishna-pandey] Modified Documentation as per review.
6733289 [krishna-pandey] Adding documentation for HTTP Security Headers
754d2d7 [krishna-pandey] Supplying String instead of Int (required for Response Header)
468231c [krishna-pandey] Added configurable Strict-Transport-Security and X-XSS-Protection Headers
  • Loading branch information
prabhjyotsingh committed Aug 3, 2017
1 parent 41a333a commit 09c381b
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 26 deletions.
3 changes: 2 additions & 1 deletion HDP-CHANGES.txt
@@ -1,6 +1,7 @@
Changes only in Hortonworks github and not in zeppelin 0.7.0 Apache Release

ZEPPELIN-1263 Should specify zeppelin's spark configuration through --conf arguments of spark-submit
ZEPPELIN-2775 Strict-Transport-Security and X-XSS-Protection Headers
ZEPPELIN-1263 Should specify zeppelin's spark configuration through --conf arguments of spark-submit
ZEPPELIN-2173 Duplicate user names populated in the Note permission box
ZEPPELIN-2014 Jetty Directory Listing on app, assets, components, and scripts
ZEPPELIN-2461 Masking Jetty Server version with User-configurable parameter
Expand Down
14 changes: 14 additions & 0 deletions conf/zeppelin-site.xml.template
Expand Up @@ -343,4 +343,18 @@
</property>
-->

<!--
<property>
<name>zeppelin.server.strict.transport</name>
<value>max-age=631138519</value>
<description>The HTTP Strict-Transport-Security response header is a security feature that lets a web site tell browsers that it should only be communicated with using HTTPS, instead of using HTTP. Enable this when Zeppelin is running on HTTPS. Value is in Seconds, the default value is equivalent to 20 years.</description>
</property>
-->
<!--
<property>
<name>zeppelin.server.xxss.protection</name>
<value>1</value>
<description>The HTTP X-XSS-Protection response header is a feature of Internet Explorer, Chrome and Safari that stops pages from loading when they detect reflected cross-site scripting (XSS) attacks. When value is set to 1 and a cross-site scripting attack is detected, the browser will sanitize the page (remove the unsafe parts).</description>
</property>
-->
</configuration>
72 changes: 67 additions & 5 deletions docs/_includes/themes/zeppelin/_navigation.html
Expand Up @@ -24,11 +24,73 @@
<ul class="dropdown-menu">
<li><a href="{{BASE_PATH}}/index.html">What is Apache Zeppelin ?</a></li>
<li role="separator" class="divider"></li>
<li class="title"><span><b>Getting Started</b><span></li>
<li><a href="{{BASE_PATH}}/install/install.html">Install</a></li>
<li><a href="{{BASE_PATH}}/install/configuration.html">Configuration</a></li>
<li><a href="{{BASE_PATH}}/quickstart/explorezeppelinui.html">Explore Zeppelin UI</a></li>
<li><a href="{{BASE_PATH}}/quickstart/tutorial.html">Tutorial</a></li>
<li><a href="{{BASE_PATH}}/quickstart/spark_with_zeppelin.html">Spark with Zeppelin</a></li>
<li><a href="{{BASE_PATH}}/quickstart/sql_with_zeppelin.html">SQL with Zeppelin</a></li>
<li><a href="{{BASE_PATH}}/quickstart/python_with_zeppelin.html">Python with Zeppelin</a></li>
</ul>
</li>

<li>
<a href="#" data-toggle="dropdown" class="dropdown-toggle">Usage<b class="caret"></b></a>
<ul class="dropdown-menu scrollable-menu">
<li class="title"><span>Dynamic Form</span></li>
<li><a href="{{BASE_PATH}}/usage/dynamic_form/intro.html">What is Dynamic Form?</a></li>
<li role="separator" class="divider"></li>
<li class="title"><span>Display System</span></li>
<li><a href="{{BASE_PATH}}/usage/display_system/basic.html#text">Text Display</a></li>
<li><a href="{{BASE_PATH}}/usage/display_system/basic.html#html">HTML Display</a></li>
<li><a href="{{BASE_PATH}}/usage/display_system/basic.html#table">Table Display</a></li>
<li><a href="{{BASE_PATH}}/usage/display_system/basic.html#network">Network</a></li>
<li><a href="{{BASE_PATH}}/usage/display_system/angular_backend.html">Angular Display using Backend API</a></li>
<li><a href="{{BASE_PATH}}/usage/display_system/angular_frontend.html">Angular Display using Frontend API</a></li>
<li role="separator" class="divider"></li>
<li class="title"><span>Interpreter</span></li>
<li><a href="{{BASE_PATH}}/usage/interpreter/overview.html">Overview</a></li>
<li><a href="{{BASE_PATH}}/usage/interpreter/interpreter_binding_mode.html">Interpreter Binding Mode</a></li>
<li><a href="{{BASE_PATH}}/usage/interpreter/user_impersonation.html">User Impersonation</a></li>
<li><a href="{{BASE_PATH}}/usage/interpreter/dependency_management.html">Dependency Management</a></li>
<li><a href="{{BASE_PATH}}/usage/interpreter/installation.html">Installing Interpreters</a></li>
<!--<li><a href="{{BASE_PATH}}/usage/interpreter/dynamic_loading.html">Dynamic Interpreter Loading (Experimental)</a></li>-->
<li><a href="{{BASE_PATH}}/usage/interpreter/execution_hooks.html">Execution Hooks (Experimental)</a></li>
<li role="separator" class="divider"></li>
<li class="title"><span>Other Features</span></li>
<li><a href="{{BASE_PATH}}/usage/other_features/publishing_paragraphs.html">Publishing Paragraphs</a></li>
<li><a href="{{BASE_PATH}}/usage/other_features/personalized_mode.html">Personalized Mode</a></li>
<li><a href="{{BASE_PATH}}/usage/other_features/customizing_homepage.html">Customizing Zeppelin Homepage</a></li>
<li role="separator" class="divider"></li>
<li class="title"><span>REST API</span></li>
<li><a href="{{BASE_PATH}}/usage/rest_api/interpreter.html">Interpreter API</a></li>
<li><a href="{{BASE_PATH}}/usage/rest_api/zeppelin_server.html">Zeppelin Server API</a></li>
<li><a href="{{BASE_PATH}}/usage/rest_api/notebook.html">Notebook API</a></li>
<li><a href="{{BASE_PATH}}/usage/rest_api/notebook_repository.html">Notebook Repository API</a></li>
<li><a href="{{BASE_PATH}}/usage/rest_api/configuration.html">Configuration API</a></li>
<li><a href="{{BASE_PATH}}/usage/rest_api/credential.html">Credential API</a></li>
<li><a href="{{BASE_PATH}}/usage/rest_api/helium.html">Helium API</a></li>
</ul>
</li>

<li>
<a href="#" data-toggle="dropdown" class="dropdown-toggle">Setup<b class="caret"></b></a>
<ul class="dropdown-menu scrollable-menu">
<li class="title"><span>Basics</span></li>
<li><a href="{{BASE_PATH}}/setup/basics/how_to_build.html">How to Build Zeppelin</a></li>
<li><a href="{{BASE_PATH}}/setup/basics/multi_user_support.html">Multi-user Support</a></li>
<li role="separator" class="divider"></li>
<li class="title"><span>Deployment</span></li>
<!--<li><a href="{{BASE_PATH}}/setup/deployment/docker.html">Docker Image for Zeppelin</a></li>-->
<li><a href="{{BASE_PATH}}/setup/deployment/spark_cluster_mode.html#spark-standalone-mode">Spark Cluster Mode: Standalone</a></li>
<li><a href="{{BASE_PATH}}/setup/deployment/spark_cluster_mode.html#spark-on-yarn-mode">Spark Cluster Mode: YARN</a></li>
<li><a href="{{BASE_PATH}}/setup/deployment/spark_cluster_mode.html#spark-on-mesos-mode">Spark Cluster Mode: Mesos</a></li>
<li><a href="{{BASE_PATH}}/setup/deployment/flink_and_spark_cluster.html">Zeppelin with Flink, Spark Cluster</a></li>
<li><a href="{{BASE_PATH}}/setup/deployment/cdh.html">Zeppelin on CDH</a></li>
<li><a href="{{BASE_PATH}}/setup/deployment/virtual_machine.html">Zeppelin on VM: Vagrant</a></li>
<li role="separator" class="divider"></li>
<li class="title"><span>Security</span></li>
<li><a href="{{BASE_PATH}}/setup/security/authentication_nginx.html">HTTP Basic Auth using NGINX</a></li>
<li><a href="{{BASE_PATH}}/setup/security/shiro_authentication.html">Shiro Authentication</a></li>
<li><a href="{{BASE_PATH}}/setup/security/notebook_authorization.html">Notebook Authorization</a></li>
<li><a href="{{BASE_PATH}}/setup/security/datasource_authorization.html">Data Source Authorization</a></li>
<li><a href="{{BASE_PATH}}/setup/security/http_security_headers.html">HTTP Security Headers</a></li>
<li role="separator" class="divider"></li>
<li class="title"><span><b>Basic Feature Guide</b><span></li>
<li><a href="{{BASE_PATH}}/manual/dynamicform.html">Dynamic Form</a></li>
Expand Down
48 changes: 30 additions & 18 deletions docs/index.md
Expand Up @@ -168,24 +168,36 @@ Join to our [Mailing list](https://zeppelin.apache.org/community.html) and repor
* [Credential API](./rest-api/rest-credential.html)
* [Helium API](./rest-api/rest-helium.html)
* Security: available security support in Apache Zeppelin
* [Authentication for NGINX](./security/authentication.html)
* [Shiro Authentication](./security/shiroauthentication.html)
* [Notebook Authorization](./security/notebook_authorization.html)
* [Data Source Authorization](./security/datasource_authorization.html)
* [Helium Authorization](./security/helium_authorization.html)
* Advanced
* [Apache Zeppelin on Vagrant VM](./install/virtual_machine.html)
* [Zeppelin on Spark Cluster Mode (Standalone via Docker)](./install/spark_cluster_mode.html#spark-standalone-mode)
* [Zeppelin on Spark Cluster Mode (YARN via Docker)](./install/spark_cluster_mode.html#spark-on-yarn-mode)
* [Zeppelin on Spark Cluster Mode (Mesos via Docker)](./install/spark_cluster_mode.html#spark-on-mesos-mode)
* [Zeppelin on CDH (via Docker)](./install/cdh.html)
* Contribute
* [Writing Zeppelin Interpreter](./development/writingzeppelininterpreter.html)
* [Writing Zeppelin Application (Experimental)](./development/writingzeppelinapplication.html)
* [Writing Zeppelin Spell (Experimental)](./development/writingzeppelinspell.html)
* [Writing Zeppelin Visualization (Experimental)](./development/writingzeppelinvisualization.html)
* [How to contribute (code)](./development/howtocontribute.html)
* [How to contribute (documentation website)](./development/howtocontributewebsite.html)
* [HTTP Basic Auth using NGINX](./setup/security/authentication_nginx.html)
* [Shiro Authentication](./setup/security/shiro_authentication.html)
* [Notebook Authorization](./setup/security/notebook_authorization.html)
* [Data Source Authorization](./setup/security/datasource_authorization.html)
* [HTTP Security Headers](./setup/security/http_security_headers.html)
* Notebook Storage: a guide about saving notebooks to external storage
* [Git Storage](./setup/storage/storage.html#notebook-storage-in-local-git-repository)
* [S3 Storage](./setup/storage/storage.html#notebook-storage-in-s3)
* [Azure Storage](./setup/storage/storage.html#notebook-storage-in-azure)
* [ZeppelinHub Storage](./setup/storage/storage.html#notebook-storage-in-zeppelinhub)
* [MongoDB Storage](./setup/storage/storage.html#notebook-storage-in-mongodb)
* Operation
* [Configuration](./setup/operation/configuration.html): lists for Apache Zeppelin
* [Proxy Setting](./setup/operation/proxy_setting.html)
* [Upgrading](./setup/operation/upgrading.html): a manual procedure of upgrading Apache Zeppelin version
* [Trouble Shooting](./setup/operation/trouble_shooting.html)

#### Developer Guide
* Extending Zeppelin
* [Writing Zeppelin Interpreter](./development/writing_zeppelin_interpreter.html)
* [Helium: Overview](./development/helium/overview.html)
* [Helium: Writing Application](./development/helium/writing_application.html)
* [Helium: Writing Spell](./development/helium/writing_spell.html)
* [Helium: Writing Visualization: Basic](./development/helium/writing_visualization_basic.html)
* [Helium: Writing Visualization: Transformation](./development/helium/writing_visualization_transformation.html)
* Contributing to Zeppelin
* [How to Build Zeppelin](./setup/basics/how_to_build.html)
* [Useful Developer Tools](./development/contribution/useful_developer_tools.html)
* [How to Contribute (code)](./development/contribution/how_to_contribute_code.html)
* [How to Contribute (website)](./development/contribution/how_to_contribute_website.html)

#### External Resources
* [Mailing List](https://zeppelin.apache.org/community.html)
Expand Down
110 changes: 110 additions & 0 deletions docs/setup/security/http_security_headers.md
@@ -0,0 +1,110 @@
---
layout: page
title: "Setting up HTTP Response Headers"
description: "There are multiple HTTP Security Headers which can be configured in Apache Zeppelin. This page describes how to enable them by providing appropriate value in Zeppelin configuration file."
group: setup/security
---
<!--
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.
-->
{% include JB/setup %}

# Setting up HTTP Response Headers for Zeppelin

<div id="toc"></div>

Apache Zeppelin can be configured to include HTTP Headers which aids in preventing Cross Site Scripting (XSS), Cross-Frame Scripting (XFS) and also enforces HTTP Strict Transport Security. Apache Zeppelin also has configuration available to set the Application Server Version to desired value.

## Setting up HTTP Strict Transport Security (HSTS) Response Header

Enabling HSTS Response Header prevents Man-in-the-middle attacks by automatically redirecting HTTP requests to HTTPS when Zeppelin Server is running on SSL. Read on how to configure SSL for Zeppelin [here] (../operation/configuration.html). Even if web page contains any resource which gets served over HTTP or any HTTP links, it will automatically be redirected to HTTPS for the target domain.
It also prevents MITM attack by not allowing User to override the invalid certificate message, when Attacker presents invalid SSL certificate to the User.

The following property needs to be updated in the zeppelin-site.xml in order to enable HSTS. You can choose appropriate value for "max-age".

```
<property>
<name>zeppelin.server.strict.transport</name>
<value>max-age=631138519</value>
<description>The HTTP Strict-Transport-Security response header is a security feature that lets a web site tell browsers that it should only be communicated with using HTTPS, instead of using HTTP. Enable this when Zeppelin is running on HTTPS. Value is in Seconds, the default value is equivalent to 20 years.</description>
</property>
```


Possible values are:

* max-age=\<expire-time>
* max-age=\<expire-time>; includeSubDomains
* max-age=\<expire-time>; preload

Read more about HSTS [here](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security).

## Setting up X-XSS-PROTECTION Header

The HTTP X-XSS-Protection response header is a feature of Internet Explorer, Chrome and Safari Web browsers that initiates configured action when they detect reflected cross-site scripting (XSS) attacks.

The following property needs to be updated in the zeppelin-site.xml in order to set X-XSS-PROTECTION header.

```
<property>
<name>zeppelin.server.xxss.protection</name>
<value>1; mode=block</value>
<description>The HTTP X-XSS-Protection response header is a feature of Internet Explorer, Chrome and Safari that stops pages from loading when they detect reflected cross-site scripting (XSS) attacks. When value is set to 1 and a cross-site scripting attack is detected, the browser will sanitize the page (remove the unsafe parts).</description>
</property>
```


You can choose appropriate value from below.

* 0 (Disables XSS filtering)
* 1 (Enables XSS filtering. If a cross-site scripting attack is detected, the browser will sanitize the page.)
* 1; mode=block (Enables XSS filtering. The browser will prevent rendering of the page if an attack is detected.)

Read more about HTTP X-XSS-Protection response header [here](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection).

## Setting up X-Frame-Options Header

The X-Frame-Options HTTP response header can indicate browser to avoid clickjacking attacks, by ensuring that their content is not embedded into other sites in a `<frame>`,`<iframe>` or `<object>`.

The following property needs to be updated in the zeppelin-site.xml in order to set X-Frame-Options header.

```
<property>
<name>zeppelin.server.xframe.options</name>
<value>SAMEORIGIN</value>
<description>The X-Frame-Options HTTP response header can be used to indicate whether or not a browser should be allowed to render a page in a frame/iframe/object.</description>
</property>
```


You can choose appropriate value from below.

* DENY
* SAMEORIGIN
* ALLOW-FROM _uri_

## Setting up Server Header

Security conscious organisations does not want to reveal the Application Server name and version to prevent finding this information easily by Attacker while fingerprinting the Application. The exact version number can tell an Attacker if the current Application Server is patched for or vulnerable to certain publicly known CVE associated to it.

The following property needs to be updated in the zeppelin-site.xml in order to set Server header.

```
<property>
<name>zeppelin.server.jetty.name</name>
<value>Jetty(7.6.0.v20120127)</value>
<description>Hardcoding Application Server name to Prevent Fingerprinting</description>
</property>
```

The value can be any "String".
Expand Up @@ -80,7 +80,12 @@ private void addCorsHeaders(HttpServletResponse response, String origin) {
DateFormat fullDateFormatEN =
DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, new Locale("EN", "en"));
response.addHeader("Date", fullDateFormatEN.format(new Date()));
response.addHeader("X-FRAME-OPTIONS", ZeppelinConfiguration.create().getXFrameOptions());
ZeppelinConfiguration zeppelinConfiguration = ZeppelinConfiguration.create();
response.addHeader("X-FRAME-OPTIONS", zeppelinConfiguration.getXFrameOptions());
if (zeppelinConfiguration.useSsl()) {
response.addHeader("Strict-Transport-Security", zeppelinConfiguration.getStrictTransport());
}
response.addHeader("X-XSS-Protection", zeppelinConfiguration.getXxssProtection());
}

@Override
Expand Down
Expand Up @@ -484,6 +484,14 @@ public String getXFrameOptions() {
return getString(ConfVars.ZEPPELIN_SERVER_XFRAME_OPTIONS);
}

public String getXxssProtection() {
return getString(ConfVars.ZEPPELIN_SERVER_X_XSS_PROTECTION);
}

public String getStrictTransport() {
return getString(ConfVars.ZEPPELIN_SERVER_STRICT_TRANSPORT);
}


public Map<String, String> dumpConfigurations(ZeppelinConfiguration conf,
ConfigurationKeyPredicate predicate) {
Expand Down Expand Up @@ -628,7 +636,9 @@ public static enum ConfVars {
ZEPPELIN_WEBSOCKET_MAX_TEXT_MESSAGE_SIZE("zeppelin.websocket.max.text.message.size", "1024000"),
ZEPPELIN_SERVER_DEFAULT_DIR_ALLOWED("zeppelin.server.default.dir.allowed", false),
ZEPPELIN_SERVER_XFRAME_OPTIONS("zeppelin.server.xframe.options", "SAMEORIGIN"),
ZEPPELIN_SERVER_JETTY_NAME("zeppelin.server.jetty.name", null);
ZEPPELIN_SERVER_JETTY_NAME("zeppelin.server.jetty.name", null),
ZEPPELIN_SERVER_STRICT_TRANSPORT("zeppelin.server.strict.transport", "max-age=631138519"),
ZEPPELIN_SERVER_X_XSS_PROTECTION("zeppelin.server.xxss.protection", "1");

private String varName;
@SuppressWarnings("rawtypes")
Expand Down

0 comments on commit 09c381b

Please sign in to comment.