AddHeader plug-in
The AddHeader plug-in helps secure your web application by adding HTTP response headers. By default, the plugin provides a baseline configuration of HTTP response headers. You can add custom response headers or override the default ones by configuring the plugin parameters.
This plugin must be applied to an ASM gateway.
Prerequisites
An ingress gateway is deployed. For more information, see Create an ingress gateway.
-
The sleep and httpbin services must be deployed in the data plane cluster. For more information, see Deploy the httpbin application.
Parameters
|
Parameter |
Type |
Required |
Default |
Description |
|
headers |
string map |
Optional |
{} |
A map of custom response headers to add or override. |
Configuration examples
Use the baseline configuration
The Open Web Application Security Project (OWASP) provides best practice guides and programming frameworks on using security response headers to protect your application. For more information about the baseline configuration of HTTP response headers, see Add HTTP response headers through EnvoyFilter in ASM. By default, the AddHeader plug-in secures your application by inserting a baseline configuration of HTTP response headers into the gateway response. You do not need to configure any parameters. Set the plugin scope to Gateway Scope and apply it to the ingressgateway gateway.
Run the following command to test the configuration.
curl -I {gateway IP address}/get
Expected output:
HTTP/1.1 200 OK
server: istio-envoy
date: Thu, 16 Jun 2022 07:10:08 GMT
content-type: application/json
content-length: 504
access-control-allow-origin: *
access-control-allow-credentials: true
x-envoy-upstream-service-time: 3
content-security-policy: frame-ancestors none;
x-frame-options: deny
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
referrer-policy: no-referrer
x-download-options: noopen
x-dns-prefetch-control: off
feature-policy: camera 'none';microphone 'none';geolocation 'none';encrypted-media 'none';payment 'none';speaker 'none';usb 'none';
The output includes baseline security headers, such as content-security-policy, x-frame-options, and x-xss-protection.
Add custom response headers
To override the default baseline headers or add custom ones, provide them in the headers parameter of the AddHeader plug-in. For example, enter the following configuration in the plugin parameters:
headers:
x-xss-protection: "0"
app: httpbin
This configuration changes the x-xss-protection header in the gateway response to 0 and adds a custom response header app: httpbin.
Set the plugin scope to Gateway Scope and apply it to the ingressgateway gateway.
Run the following command to test the configuration.
curl -I {gateway IP address}/get
Expected output:
HTTP/1.1 200 OK
server: istio-envoy
date: Thu, 16 Jun 2022 07:19:51 GMT
content-type: application/json
content-length: 504
access-control-allow-origin: *
access-control-allow-credentials: true
x-envoy-upstream-service-time: 2
app: httpbin
x-xss-protection: 0
content-security-policy: frame-ancestors none;
x-frame-options: deny
x-content-type-options: nosniff
referrer-policy: no-referrer
x-download-options: noopen
x-dns-prefetch-control: off
feature-policy: camera 'none';microphone 'none';geolocation 'none';encrypted-media 'none';payment 'none';speaker 'none';usb 'none';
The output confirms that the x-xss-protection header is changed to 0, and the custom response header app: httpbin is added.