> Source: https://docs.cyberelements.io/bastion/4.7/pl/Security/Apache/

# Apache

Apache HTTP Server hosts the **web portal** and the **application router** of CyberElements Bastion on the Mediation Controller server. This chapter therefore does **not** apply to Edge Gateway servers, which do not run Apache.

> **Information**
>
> Two ANSSI references complement each other on this subject. The technical note **DAT-NT-009/ANSSI/SDE/NP** (2013, website security) sets out the general principles: least privilege for the account running the HTTP server, positive security model, restriction of outbound connections. The guide **ANSSI-PA-009 v2.1** (2021) is markedly more recent and details the mechanisms that can be enabled through HTTP headers (HSTS, X-Frame-Options, Referrer-Policy…).
>
> Most of it, however, deals with **application development** subjects (XSS, CSP, cookies, JavaScript) that belong to the code of CyberElements Bastion itself rather than to the Apache configuration an integrator can adjust. Only the points directly configurable at web server level are covered here; the [Content Security Policy](https://docs.cyberelements.io/bastion/4.7/pl/Security/ContentSecurityPolicy/) has a chapter of its own.

## Summary

| # | Recommendation | Mediation Controller | Edge Gateway |
|---|---|---|---|
| [**R42**](#r42) | Reducing the attack surface and exposed information | ✅ | ❌ |
| [**R43**](#r43) | Management of persistent connections | ✅ | ❌ |
| [**R44**](#r44) | HTTP security headers | ✅ | ❌ |
| [**R45**](#r45) | Restriction of HTTP methods and directory browsing | ✅ | ❌ |
| [**R46**](#r46) | Compression of Reverse Proxy virtual hosts and the BREACH vulnerability | ✅ | ❌ |
| [**R47**](#r47) | Permissions of configuration files | ✅ | ❌ |

The **❌** in the Edge Gateway column marks a recommendation that is **not relevant** for that role, rather than a mere omission.

> **Warning!**
>
> These recommendations should only be applied **after** CyberElements Bastion has been installed and the portal confirmed to work correctly.

## R42. Reducing the attack surface and exposed information

**Applies to**: Mediation Controller ✅ · Edge Gateway ❌

In `/etc/apache2/apache2.conf` or `/etc/apache2/conf-available/security.conf`:

```
1
2
```

`ServerTokens Prod` limits the `Server` HTTP header to the sole mention "Apache", with no version or operating system. `ServerSignature Off` removes the server signature line shown at the bottom of the error pages Apache generates.

Both settings are consistent with the minimisation principle already applied to system banners ([R18](https://docs.cyberelements.io/bastion/4.7/pl/Security/SystemHardening/SystemIntegrity/#r18)): **do not hand an attacker, for free, information useful for a reconnaissance phase**.

When enabled, the `mod_status` and `mod_info` modules expose detailed information about the server's internal state or its complete configuration. If they are not used for monitoring, they must be disabled; if they are, access to them must be strictly restricted by IP address.

The loaded modules can be listed, then disabled where unnecessary:

```
1
2
3
```

> **Warning!**
>
> The list of modules actually required by CyberElements Bastion **depends on the deployed configuration** (reverse proxy, authentication, SSO…). Only disable a module after checking that no virtual host in the configuration loads it, and validate that the portal works completely after any change.

## R43. Management of persistent connections

**Applies to**: Mediation Controller ✅ · Edge Gateway ❌

In `/etc/apache2/apache2.conf`:

```
1
2
3
```

- `KeepAlive On` enables persistent connections, avoiding the renegotiation of a full TCP/TLS connection for each request;
- `KeepAliveTimeout 5` limits the waiting time between two requests from the same client before the connection is closed (a value below 15 seconds is recommended);
- `MaxKeepAliveRequests 100` limits the number of requests handled over a single persistent connection, so as to contain the impact of abusive usage.

## R44. HTTP security headers

**Applies to**: Mediation Controller ✅ · Edge Gateway ❌

Add the following block at the end of `/etc/apache2/apache2.conf`:

```
1
2
3
4
5
6
```

- **`Strict-Transport-Security`** (HSTS) requires the browser to use HTTPS for every subsequent access to the site, even if the user tries to force a cleartext connection;
- **`X-Content-Type-Options: nosniff`** prevents the browser from guessing a content type different from the one declared by the server;
- **`X-Frame-Options: SAMEORIGIN`** limits the inclusion of the portal in a frame (`iframe`) to pages of the same origin, as protection against **clickjacking**. The ANSSI (PA-009) considers this header complementary to the CSP `frame-ancestors` directive, covered in the [Content Security Policy](https://docs.cyberelements.io/bastion/4.7/pl/Security/ContentSecurityPolicy/#r55) chapter: both mechanisms are recommended together, as defence in depth;
- **`Referrer-Policy: strict-origin-when-cross-origin`** limits the navigation information sent to third-party sites when a link is followed from the portal. It is the default value of several recent browsers; the ANSSI explicitly forbids the `unsafe-url` value, which would send the full URL without restriction.

> **Warning!**
>
> Regarding the **HSTS** header: the `includeSubDomains` directive must be used with care if a subdomain of the portal has no HTTPS access. This header should only be put in place once the portal's certificate is **valid and properly signed** by a recognised authority. The ANSSI stresses this explicitly: durable HTTPS access is an essential prerequisite for HSTS, which **makes cleartext access impossible for the whole `max-age` duration**, even after the header is removed.

> **Information**
>
> The Content Security Policy, and the hardening of cookie attributes (`HttpOnly`, `Secure`, `SameSite`), are handled separately: the former in the [Content Security Policy](https://docs.cyberelements.io/bastion/4.7/pl/Security/ContentSecurityPolicy/) chapter, the latter belonging mainly to the **application code** of CyberElements Bastion rather than to the Apache configuration. Additional hardening at reverse proxy level, by rewriting `Set-Cookie` headers with `mod_headers`, remains possible but must be validated case by case so as not to conflict with the attributes already set by the application.

Once the changes are made, reload the service:

```
1
```

## R45. Restriction of HTTP methods and directory browsing

**Applies to**: Mediation Controller ✅ · Edge Gateway ❌

In `/etc/apache2/apache2.conf` or in the configuration of each virtual host concerned:

```
1
```

`TraceEnable off` disables the `TRACE` HTTP method, whose combination with an XSS vulnerability can allow a **Cross-Site Tracing** (XST) attack and the retrieval of sensitive information present in request headers (cookies in particular).

```
1
2
3
```

`Options -Indexes` prevents Apache from automatically generating a list of the files in a directory when no index page is present, avoiding the unintended disclosure of the structure or content of the tree.

## R46. Compression of Reverse Proxy virtual hosts and the BREACH vulnerability

**Applies to**: Mediation Controller ✅ · Edge Gateway ❌

**Reverse proxy** virtual hosts use `deflate` compression by default. Combined with TLS, that compression is vulnerable to certain attacks allowing **session cookies** to be retrieved under specific conditions: attacks of the **BREACH** family.

To disable compression on Debian and restart Apache:

```
1
2
```

> **Warning!**
>
> Disabling this compression **increases the volume of data exchanged** between the Mediation Controller and the browsers connecting to it. That trade-off remains preferable to exposure to BREACH on an authentication portal.

## R47. Permissions of configuration files

**Applies to**: Mediation Controller ✅ · Edge Gateway ❌

```
1
```

This configuration file, specific to CyberElements Bastion, must remain readable by the processes that need it **without being writable** by an unprivileged user. The general principles for controlling permissions and sensitive files are covered in [File system and permissions](https://docs.cyberelements.io/bastion/4.7/pl/Security/SystemHardening/SystemFilesystem/) and are not repeated here.
