opnsense / opnsense/plugins

os-nginx: Keepalive=0 is not rendered, but nginx >=1.29.7 enables upstream keepalive by default

Open Beginner friendly
#5,532 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
1.2k
Forks
863
Avg merge
2d 6h
Merged PRs (30d)
10

Description

Important notices

Before you add a new report, we ask you kindly to acknowledge the following:

Describe the bug

The os-nginx plugin GUI states for upstream Keepalive:

Leave blank or set to 0 to disable.

However, the current upstream template only renders the keepalive directive when the value is greater than 0:

https://raw.githubusercontent.com/opnsense/plugins/master/www/nginx/src/opnsense/service/templates/OPNsense/Nginx/upstream.conf

{% if upstream.keepalive is defined and upstream.keepalive|int > 0 %}
keepalive {{ upstream.keepalive }};

With nginx >= 1.29.7 this no longer disables upstream keepalive. According to nginx documentation, upstream keepalive is now enabled by default:

https://blog.nginx.org/blog/keep-alive-to-upstreams-is-now-default-in-nginx-1-29-7

keepalive 32 local;

But keepalive 0; is required to explicitly disable upstream keepalive.

To Reproduce

  1. Create an upstream in os-nginx.
  2. Set Keepalive to 0 or leave it blank.
  3. Apply the configuration.
  4. Check /usr/local/etc/nginx/nginx.conf.

Actual result:

upstream upstream<uuid> {
    server 10.0.0.2:443;
}

Expected behavior

Expected result when Keepalive is 0:

upstream upstream<uuid> {
    keepalive 0;
    server 10.0.0.2:443;
}

Impact

For IIS backends using Windows Authentication, nginx upstream keepalive can leak the authenticated backend connection context between different clients. This results in users seeing the previous user's authenticated session, even without sending credentials.

Manually adding:

keepalive 0;

to the generated upstream block fixes the issue.

Suggested fix

Render keepalive 0; when the GUI value is explicitly 0. Alternatively, change the plugin semantics to distinguish between:

  • blank = nginx default / auto
  • 0 = explicitly disabled

Environment

OPNsense 26.4.1 (amd64).
business edition
DEC3960

Contributor guide

Open the contributing guide

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.

Research direction

Start with www/nginx/src/opnsense/service/templates/OPNsense/Nginx/upstream.conf and review how the upstream.keepalive value is rendered. Reproduce the issue by setting Keepalive to 0, then inspect /usr/local/etc/nginx/nginx.conf. Done means the generated upstream block explicitly reflects the intended Keepalive=0 behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
nginx
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.