Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nulab/nginx-length-hiding-filter-module

nginx filter module to append random generated string to the end of HTML response
https://github.com/nulab/nginx-length-hiding-filter-module

nginx

Last synced: about 2 months ago
JSON representation

nginx filter module to append random generated string to the end of HTML response

Awesome Lists containing this project

README

        

# Nginx Length Hiding Filter Module

[![Build Status](https://travis-ci.org/nulab/nginx-length-hiding-filter-module.svg?branch=master)](https://travis-ci.org/nulab/nginx-length-hiding-filter-module)

## Introduction

In [BREACH site](http://breachattack.com/), the mitigations against BREACH attack are given as follows:

1. Disabling HTTP compression
2. Separating secrets from user input
3. Randomizing secrets per request
4. Masking secrets (effectively randomizing by XORing with a random secret per request)
5. Protecting vulnerable pages with CSRF
6. Length hiding (by adding random number of bytes to the responses)
7. Rate-limiting the requests

BREACH relies on HTTP compression and it's reasonable to disable it to secure your website. However without compresseion, some websites may meet severe performance degression or the cost may increase if you're charged based on the volume of traffic like AWS. In such case it may be difficult to turn off HTML compression for whole responses from your website and need to adopt other proper ways.

Other mitigations listed from the 2nd to 5th above are basically applicable to your application but the 6th one, Length hiding, can be done on nginx. This filter module provides functionality to append randomly generated HTML comment to the end of response body to hide correct response length and make it difficult for attackers to guess secure token.

The sample of randomly appended HTML comment is here.
```

```
For every response, length of the random strings will vary within a given range.

This idea originally came from [breach-mitigation-rails](https://github.com/meldium/breach-mitigation-rails/). Thanks team!

## Warning

As said in breach-migration-rails, BREACH is complicated and wide-ranging attack and this module provides only PARTIAL protection. To secure your website or service wholly, you need to review BREACH paper and find proper way according to your own website or service.

## Installation

Module version | Nginx version
--- | ---
1.1.x | 1.10.1 or higher
1.0.0 | 1.10.0 or earlier

Download nginx sources from [http://nginx.org](http://nginx.org) and unpack it.

Run configure script with adding --add-module option with the directory where this module is extracted like this:
```
./configure --add-module=/path/to/nginx-length-hiding-filter-module
```
To compile this module as dynamic module available in 1.9.11 or later, use `--add-dynamic-module` instead
```
./configure --add-dynamic-module=/path/to/nginx-length-hiding-filter-module
```
You can add other options along with it. Then build and install.
```
make
sudo make install
```

## Configuration Directives

### length_hiding

* syntax: length_hiding on | off
* default: off
* context: http, server, location, if in location

Enables or disables adding random generated HTML comment.

### length_hiding_max

* syntax: length_hiding_max size
* default: 2048
* context: http, server, location

Sets maximum length of random generated string used in HTML comment. The size should be within a range from 256 and 2048.

### length_hiding_types

* syntax: length_hiding_types [..]
* default: text/html
* context: http, server, location, if in location

Enables adding random generated HTML comment to responses of the specified MIME types in addition to text/html. The special value * matches any MIME type.

## Example Configuration

Enable this module for specific location ('/hiding'). In this example, the length of random strings will be less than 1024.
```
server {
listen 443 default_server deferred ssl http2;
server_name example.com;
length_hiding_max 1024;

location /hiding {
length_hiding on;
}
}
```

If this module is built as dynamic module, do NOT forget including `load_module` line in nginx configuration.
```
load_module modules/ngx_http_length_hiding_filter_module.so;
```

## Services using this module

* [Cacoo](https://cacoo.com/)
* [Backlog](https://backlog.com/)
* [Typetalk](https://typetalk.com/)
* [Nulab Account](https://apps.nulab.com/)