323: MSSQL: audit log writer (.pi/mssql-audit.log, mode 0600) #347
No reviewers
Labels
No labels
bug
chore
documentation
enhancement
feature
ready
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
david/pi-extensions-and-skills!347
Loading…
Reference in a new issue
No description provided.
Delete branch "feature/issue-323/mssql-audit-log-writer-pi-mssql-audit-log-mode-060"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
323: MSSQL: audit log writer (.pi/mssql-audit.log, mode 0600)
Implements 323.
Generated in 54s.
Review findings
Review Findings — 323
Summary
I fixed five of the six findings and left the logger wiring unresolved. The
audit.test.tssuite passes (6 tests). The repo has no build or lint script, so those gates did not run..gitignore: added an explicit.pi/mssql-audit.logentry. The existing*.logpattern already covered the file.audit.tsnow truncates SQL at 4096 characters and appends a marker. Rotation and README documentation of the log's sensitivity are not done.O_NOFOLLOW..piis nowchmoded to 0700 after creation.log()fromindex.tsand the guard is a larger change and may belong in a follow-up issue, so I left it.Critical
High
.pi/mssql-audit.logis not ignored (only.pi-loopis). The log holds raw SQL, which may include sensitive literals, sogit add -Acould commit it. Suggested fix: add.pi/mssql-audit.logto.gitignore. Don't ignore all of.pi/, because.pi/settings.jsonmay be tracked.Medium
entry.sqlverbatim and without a length cap. Queries containing patron PII or secret literals are persisted in plain text (APP 11 / Privacy Act 2020 / PDPA / UK GDPR considerations), and very large statements can grow the log without limit. Suggested fix: cap the SQL length (e.g. truncate to a few KB with a marker). Document in the README that the log is sensitive. Consider size-based rotation.openSync(file, "a")follows symlinks, so a planted.pi/mssql-audit.logsymlink would redirect writes and thefchmod. Suggested fix: open withfs.constants.O_APPEND | O_CREAT | O_WRONLY | O_NOFOLLOW. Alternatively,lstatthe path and refuse to write if it is a symlink.index.tsor the guard (grep finds noauditreferences there), so nothing is logged yet. Suggested fix: if this issue is meant to deliver working auditing, calllog()from the query path for rejected, executed, error and permission_warning outcomes. Otherwise confirm that a follow-up issue covers it.Low
.pialready exists with looser permissions,mkdirSyncleaves them unchanged, and the test only covers a freshly created directory. Suggested fix: optionallychmodSync(dir, DIR_MODE)aftermkdirSync, or note this as accepted.chmod 0500blocking writes. This doesn't hold when the tests run as root (common in CI containers), so the test would fail there. Suggested fix: skip the test whenprocess.getuid?.() === 0, or inject a failingfs.