Skip to content

Commit

Permalink
Add security related headers for static resources
Browse files Browse the repository at this point in the history
Add the following security headers to static resources, including
`html`, `js`, and `css` files.
- Add `X-Content-Type-Options` header and assign the value
  to 'nosniff'
- Add `Content-Security-Policy` header and proper values
  - default-src: 'self'
  - style-src: 'self' 'unsafe-inline' https://fonts.googleapis.com
  - font-src: self fonts.gstatic.com
  - frame-ancestors: self

Signed-off-by: Yihong Wang <yh.wang@ibm.com>
  • Loading branch information
yhwang authored and tdcmeehan committed Jan 7, 2025
1 parent 9abf6c0 commit b230be1
Show file tree
Hide file tree
Showing 16 changed files with 583 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<air.maven.version>3.3.9</air.maven.version>

<dep.antlr.version>4.7.1</dep.antlr.version>
<dep.airlift.version>0.215</dep.airlift.version>
<dep.airlift.version>0.216</dep.airlift.version>
<dep.packaging.version>${dep.airlift.version}</dep.packaging.version>
<dep.slice.version>0.38</dep.slice.version>
<dep.testing-mysql-server-5.version>0.6</dep.testing-mysql-server-5.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
import com.facebook.presto.transaction.TransactionManagerConfig;
import com.facebook.presto.util.PrestoDataDefBindingHelper;
import com.google.common.collect.ImmutableList;
import com.google.common.net.HttpHeaders;
import com.google.inject.Binder;
import com.google.inject.Provides;
import com.google.inject.Scopes;
Expand Down Expand Up @@ -141,8 +142,12 @@ public class CoordinatorModule
@Override
protected void setup(Binder binder)
{
httpServerBinder(binder).bindResource("/ui", "webapp").withWelcomeFile("index.html");
httpServerBinder(binder).bindResource("/tableau", "webapp/tableau");
httpServerBinder(binder).bindResource("/ui", "webapp").withWelcomeFile("index.html")
.withExtraHeader(HttpHeaders.X_CONTENT_TYPE_OPTIONS, "nosniff")
.withExtraHeader(HttpHeaders.CONTENT_SECURITY_POLICY, "default-src 'self'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; frame-ancestors 'self'");
httpServerBinder(binder).bindResource("/tableau", "webapp/tableau")
.withExtraHeader(HttpHeaders.X_CONTENT_TYPE_OPTIONS, "nosniff")
.withExtraHeader(HttpHeaders.CONTENT_SECURITY_POLICY, "default-src 'self'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; frame-ancestors 'self'");

// discovery server
install(installModuleIf(EmbeddedDiscoveryConfig.class, EmbeddedDiscoveryConfig::isEnabled, new EmbeddedDiscoveryModule()));
Expand Down
4 changes: 2 additions & 2 deletions presto-ui/src/static/dev/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<script src="../vendor/html5shiv/html5shiv.min.js"></script>
<script src="../vendor/respond/respond.min.js"></script>
<![endif]-->

<!-- jQuery -->
Expand Down
4 changes: 2 additions & 2 deletions presto-ui/src/static/embedded_plan.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<script src="vendor/html5shiv/html5shiv.min.js"></script>
<script src="vendor/respond/respond.min.js"></script>
<![endif]-->

<!-- jQuery -->
Expand Down
4 changes: 2 additions & 2 deletions presto-ui/src/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<script src="vendor/html5shiv/html5shiv.min.js"></script>
<script src="vendor/respond/respond.min.js"></script>
<![endif]-->

<!-- jQuery -->
Expand Down
4 changes: 2 additions & 2 deletions presto-ui/src/static/plan.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<script src="vendor/html5shiv/html5shiv.min.js"></script>
<script src="vendor/respond/respond.min.js"></script>
<![endif]-->

<!-- jQuery -->
Expand Down
4 changes: 2 additions & 2 deletions presto-ui/src/static/query.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<script src="vendor/html5shiv/html5shiv.min.js"></script>
<script src="vendor/respond/respond.min.js"></script>
<![endif]-->

<!-- jQuery -->
Expand Down
4 changes: 2 additions & 2 deletions presto-ui/src/static/res_groups.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<script src="vendor/html5shiv/html5shiv.min.js"></script>
<script src="vendor/respond/respond.min.js"></script>
<![endif]-->

<!-- jQuery -->
Expand Down
4 changes: 2 additions & 2 deletions presto-ui/src/static/sql_client.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<script src="vendor/html5shiv/html5shiv.min.js"></script>
<script src="vendor/respond/respond.min.js"></script>
<![endif]-->

<!-- jQuery -->
Expand Down
4 changes: 2 additions & 2 deletions presto-ui/src/static/stage.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<script src="vendor/html5shiv/html5shiv.min.js"></script>
<script src="vendor/respond/respond.min.js"></script>
<![endif]-->

<!-- jQuery -->
Expand Down
4 changes: 2 additions & 2 deletions presto-ui/src/static/timeline.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<script src="vendor/html5shiv/html5shiv.min.js"></script>
<script src="vendor/respond/respond.min.js"></script>
<![endif]-->

<!-- jQuery -->
Expand Down
Loading

0 comments on commit b230be1

Please sign in to comment.