Skip to content

feat: keep the User-Agent header in the access log - #152

Open
mactsk wants to merge 4 commits into
NethServer:mainfrom
mactsk:feat/access-log-user-agent
Open

mactsk wants to merge 4 commits into
NethServer:mainfrom
mactsk:feat/access-log-user-agent

Conversation

@mactsk

@mactsk mactsk commented Oct 15, 2026

Copy link
Copy Markdown

With the default accessLog: {} Traefik drops every request header, so the User-Agent field of each access log line is always "-". CrowdSec scenarios such as http-bad-user-agent never match, and security monitoring tools (SIEM) cannot spot scanners or skip legitimate crawlers. NethServer/dev#8233

The access log now keeps the User-Agent request header and still drops all the others (Referer, Cookie, Authorization...). The log format and file do not change: only the User-Agent field is filled in.

  • create-module: new modules get the setting.
  • update-module.d/15upgrade_v3: existing modules get it on update, only if accessLog is still the default {}. A disabled or customized access log is left untouched.
  • README: the log example shows a User-Agent.

How to test

  • Install or update the module and check that traefik.yaml has accessLog.fields.headers with defaultMode: drop and User-Agent: keep
  • Open a route with a browser: the access log line shows the browser User-Agent, and the Referer is still "-"
  • Update a module with a customized accessLog: the setting is unchanged

See also


🤖 Generated with Claude Code

With the default "accessLog: {}" Traefik drops all request headers, so
the User-Agent field of every access log line is "-". Keep only the
User-Agent header: CrowdSec scenarios such as http-bad-user-agent and
external SIEMs can use it, while Referer, Cookie and Authorization stay
dropped.

New modules get the setting from create-module. Existing modules get it
from update-module.d/15upgrade_v3, only when accessLog is still the
default "{}": a disabled or customized access log is left untouched.

NethServer/dev#8233

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@stephdl stephdl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. I tested it on a node with CrowdSec and Wazuh, and it works.

I'm not sure the gain is worth it. Scanners caught by http-bad-user-agent usually probe paths too, and the path based scenarios already ban them a few requests later. Wazuh gets the field, but no rule uses it yet. On the other side, it's more user data stored in four places and more log volume.

There is also a side effect. Traefik writes a quote in the User-Agent as \", and the hub parser crowdsecurity/traefik-logs drops those lines. A client with a " in its User-Agent would skip every HTTP scenario. NethServer/ns8-crowdsec#226 fixes it, but we would have to maintain a copy of a hub parser on our side until the hub fixes it upstream.

If it goes in, I'd prefer it opt-in, kept across restore, with a README note on privacy. A bare accessLog: (None) also needs handling in 15upgrade_v3.

@DavidePrincipi your call. I keep NethServer/ns8-crowdsec#226 in draft until then.

@mactsk

mactsk commented Oct 15, 2026

Copy link
Copy Markdown
Author

Thanks @stephdl for testing it, and for catching the escaped-quote problem in the hub parser. I agree that NethServer/ns8-crowdsec#226 must be released before or together with this PR.

About Wazuh: the stock ruleset already reads the User-Agent in the access log. Rules 31166/31168 (Shellshock) look for () { in it, and rule 31140 skips the 4xx errors of known crawlers. I checked them with wazuh-logtest on Traefik lines, one with an escaped quote: the decoder reads IP, path and status before the User-Agent, so the \" does not break it.

I'm fine with opt-in. If @DavidePrincipi agrees, I'll rework the PR: an action to turn the User-Agent on and off, kept across restore, a README note on privacy, and handling of a bare accessLog:.

Comment thread imageroot/update-module.d/15upgrade_v3 Outdated
# (access log disabled) or a custom one is left untouched.
if static_cfg.get('accessLog') != {}:
return # nothing to do
print("Keep the User-Agent request header in the Traefik access log")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the PR, just a little cleanup: remove this line since it only pollutes the logs

Suggested change
print("Keep the User-Agent request header in the Traefik access log")

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 60ad079, thanks. I also handled a bare accessLog:, as @stephdl pointed out.

A bare "accessLog:" loads as None and enables the default access log
like "accessLog: {}", so change it too. Also drop the print: it only
adds noise to the logs.

NethServer/dev#8233

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@stephdl
stephdl requested a review from gsanchietti October 20, 2026 09:14
@stephdl stephdl self-assigned this Oct 20, 2026

@DavidePrincipi DavidePrincipi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @stephdl and @mactsk, a few ideas:

  1. Escaped quote: before we maintain our own copy of the hub parser (NethServer/ns8-crowdsec#226), we could ask the CrowdSec team whether they'd fix crowdsecurity/traefik-logs upstream. Either way, it might be safer to merge this only after a fix is out.

  2. On by default: I'd lean towards keeping the User-Agent enabled, with a README note on privacy and how to turn it off. Like the version check in #154, that means editing traefik.yaml, since flags and env vars are ignored. The update step already leaves a changed accessLog alone.

  3. Loki: an Alloy rule in core could blank the User-Agent before logs reach Loki, which keeps them much longer than the journal. CrowdSec and other local agents would still see it in the journal.

What do you think?

@stephdl

stephdl commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Escaped quote: before we maintain our own copy of the hub parser (NethServer/ns8-crowdsec#226), we could ask the CrowdSec team whether they'd fix crowdsecurity/traefik-logs upstream. Either way, it might be safer to merge this only after a fix is out.

it worth to try but no clue when and what they will fix

@stephdl

stephdl commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

done sorry for the delay, let's see

@stephdl

stephdl commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

the pr crowdsecurity/hub#1978 has been accepted by crowdsec

Platypuschan added a commit to Platypuschan/ns8-traefik-reworked that referenced this pull request Nov 24, 2026
* Keep the User-Agent in the access log (default access log only)

Traefik drops every request header from the access log by default, so security
monitoring (CrowdSec http-bad-user-agent, SIEM) cannot recognise scanners by their
User-Agent. Only the User-Agent is kept; Cookie, Authorization, Referer and all other
headers stay dropped. New modules get the setting, existing modules on update, but only
if accessLog is still the default; a disabled or customised access log is untouched.
Same change as upstream NethServer/ns8-traefik#152.

* Release notes and version 4.2.8-reworked.1

---------

Co-authored-by: Platypuschan <[email protected]>
@stephdl

stephdl commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

@DavidePrincipi could you take another look?

Point 1 is solved. The CrowdSec team merged the parser fix upstream in crowdsecurity/hub#1978. Our nodes get it with the hub upgrade timer, so I closed NethServer/ns8-crowdsec#226.

Point 2 is solved too. The User-Agent stays on by default. I added an "Access log" section to the README. It covers privacy and how to turn the field off in traefik.yaml. I tested backup and restore on a cluster. A restore keeps the accessLog of the existing instance, so the admin's choice survives.

About point 3, I'm not sure we should blank the User-Agent in Loki. Loki already stores the client IP, which says more about a person than the User-Agent. The User-Agent is useful when we analyze a past attack, after the journal has rotated. What do you think?

@stephdl
stephdl self-requested a review November 26, 2026 15:23

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants