os-nginx: add X-Frame-Options, Permissions-Policy and Server header removal

Open
#5,942 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
nginx, php
Domain
backend, security

Research direction

Start by locating the os-nginx Security Header model and its template, then inspect the HTTP settings model and template where server_tokens off; is rendered. Check the existing field validation and header rendering patterns, and run the relevant plugin tests or configuration checks. Done means the requested validated header options and Server header removal are persisted in configuration and render into the intended nginx contexts.

Written by the indexing model from the issue text.

Description

incomplete

Important notices

  • I have read the contributing guide
  • I have searched for existing issues

Is your feature request related to a problem? Please describe.
The Security Header object in os-nginx currently supports Referrer, XSS Protection,
Don't Sniff Content Type, HSTS, HPKP and CSP. Three common hardening measures
recommended by the OWASP Secure Headers Project and flagged by scanners are missing:

  • X-Frame-Options
  • Permissions-Policy
  • removing the Server response header (server_tokens off only hides the version;
    nginx still sends Server: nginx)

The only way to achieve this today is custom files in /usr/local/etc/nginx/http_post/.
That has two drawbacks:

  1. add_header at http level is not inherited by server blocks that define their own
    add_header – which every server does as soon as a Security Header object is
    assigned. The workaround therefore needs more_set_headers / more_clear_headers
    (headers-more module), which is not obvious to most users.
  2. The files are not part of config.xml, so they are not included in configuration
    backups, are not synchronised to an HA peer, and are lost on reinstall.

Describe the solution you like
Constrained, validated fields only – no free-form config:

  1. X-Frame-Options – OptionField in the Security Header model
    Values: (not set), DENY, SAMEORIGIN
    Rendered as:
    proxy_hide_header X-Frame-Options;
    add_header X-Frame-Options "" always;

  2. Permissions-Policy – TextField with strict mask validation in the Security
    Header model
    Only directive=allowlist pairs separated by commas, e.g.
    camera=(self), microphone=(self), geolocation=(), payment=()
    Suggested mask (rejects ;, {, }, quotes outside origins and newlines):
    /^[a-z-]+=(*|((\s*(self|"https?://[^"\s;{}]+")\s*)))(\s,\s*[a-z-]+=(*|((\s*(self|"https?://[^"\s;{}]+")\s*))))$/
    Rendered as:
    proxy_hide_header Permissions-Policy;
    add_header Permissions-Policy "" always;

  3. Remove Server response header – global checkbox in the HTTP settings
    (next to the existing option that renders server_tokens off;)
    Since the plugin already loads ngx_http_headers_more_filter_module, this could be
    rendered in the http block as:
    more_clear_headers Server;

Items 1 and 2 follow the existing behaviour of the Security Header object ("if you set
a setting here, it will override what the webserver sets").

Optional, if in scope: Cross-Origin-Opener-Policy and Cross-Origin-Resource-Policy
as OptionFields with their standard values.

Describe alternatives you considered

  • Custom files in http_post/ (more_set_headers / more_clear_headers) – works, but
    not persisted in config.xml (see above).
  • Patching the model/template locally – overwritten on every plugin update.
  • A generic free-text field – I understand this has been declined before because broken
    input can take down nginx; the proposal above deliberately avoids that by using
    validated fields only.

Additional context

  • OPNsense 26.10.0p1-amd64, os-nginx 1.36_5, nginx 1.36_5
  • Side note, possibly a separate issue: browsers have dropped HPKP, and current guidance
    for X-XSS-Protection is 0 or omitting it. The help texts could mention this.
Dominant language
PHP
Stars
1.2k
Forks
926
Avg merge
1d 10h
Merged PRs (30d)
25

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from opnsense/plugins

All issues in opnsense/plugins

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.