Skip to content

fix: sanitize the client-supplied QNAME in the session-table-full log line - #217

Open
xmgzxmgz wants to merge 2 commits into
masterking32:mainfrom
xmgzxmgz:fix/log-field-sanitize
Open

xmgzxmgz wants to merge 2 commits into
masterking32:mainfrom
xmgzxmgz:fix/log-field-sanitize

Conversation

@xmgzxmgz

Copy link
Copy Markdown

What

When the session table is full, internal/udpserver/server_session.go logs the request domain on every rejected request:

if err == ErrSessionTableFull {
    if s.log != nil {
        s.log.Errorf(
            "... Session Table Full Request: SESSION_INIT, Domain: <cyan>%s</cyan></red>",
            decision.RequestName,
        )
    }
    return s.buildSessionBusyResponse(...)
}

decision.RequestName is the QNAME from the wire.

Why it matters

  • Log forging. A QNAME is arbitrary bytes up to the DNS label limits. A name containing CR/LF injects fabricated lines into the log; ANSI escapes rewrite whatever terminal tails it. Neither is filtered anywhere between the wire and the sink.
  • Markup corruption. The logger uses <red> / <cyan> tags for colour. A domain containing </cyan> or <script> breaks that parsing for the rest of the line.
  • Unbounded growth. There is no throttle, so while the table is full a client can add one ERROR line per request. The sibling logInvalidSessionDrop path already throttles and gates on debug logging; this one does neither.

Change

Add logField() in server_utils.go: drops control characters (including ANSI escapes), replaces < > with [ ] so the colour tags survive, and caps the field at 120 chars so one request cannot dump a quarter kilobyte into the log. Apply it at the single call site.

Testing

go build ./internal/udpserver/ — not run here, no Go toolchain in my environment. The change is a pure string transform plus one call site; no signature or behaviour change beyond the logged text.

I did not add throttling because that is a policy decision (what interval, whether to keep counting dropped requests while suppressed). Happy to add it following the invalidSessionDropLog pattern if you want it in this PR.

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.

1 participant