Skip to content

branch-4.1: [fix](audit) escape 0x1F/0x1E in audit_log stream load to prevent row forgery #66580 - #66592

Open
github-actions[bot] wants to merge 1 commit into
branch-4.1from
auto-pick-66580-branch-4.1
Open

branch-4.1: [fix](audit) escape 0x1F/0x1E in audit_log stream load to prevent row forgery #66580#66592
github-actions[bot] wants to merge 1 commit into
branch-4.1from
auto-pick-66580-branch-4.1

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Cherry-picked from #66580

… forgery (#66580)

## Proposed changes

The builtin audit plugin frames its stream-load payload for
`__internal_schema.audit_log` with `0x1F` as the column separator and
`0x1E` as the row delimiter (see `AuditLoader.AUDIT_TABLE_COL_SEPARATOR`
/ `AUDIT_TABLE_LINE_DELIMITER`). In `AuditLoader.fillLogBuffer`,
however,
the string columns — statement text, catalog/db, user, changed
variables, error message, workload group, etc. — were appended without
escaping.

Because these fields can carry user-controlled content (and a SQL
statement may legitimately contain arbitrary bytes inside a block
comment or string literal, which the lexer accepts), a crafted statement
containing raw `0x1F`/`0x1E` could end its own audit row early and have
the trailing bytes parsed as an additional, fully attacker-controlled
row. This allows forging or misattributing rows in the audit table
(CWE-117 log injection).

### Changes

- Add `sanitizeField()` in `AuditLoader`, which replaces the two framing
  bytes (`0x1F`, `0x1E`) with a space. Only these two bytes are
  structural, so all other content — including newlines and tabs already
  present in SQL text — is preserved unchanged.
- Route every string column in `fillLogBuffer` through the new
  `appendField()` helper so that new string columns added in the future
  are covered automatically. Numeric and boolean columns are appended
  directly since they can never contain these bytes.
- Add unit tests asserting that injected delimiters cannot add rows or
  columns, and that ordinary statements pass through unchanged.

The text-file audit sink (`AuditLogBuilder`, `fe.audit.log`) uses a
`|key=value` format and is unaffected.

## Types of changes

- [x] Bugfix (non-breaking change which fixes an issue)

## Further comments

Behavior-preserving: only the two structural bytes, which are not
meaningful data, are affected. Existing clusters and audit consumers are
unchanged.
@github-actions
github-actions Bot requested a review from yiguolei as a code owner August 10, 2026 01:40
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