Skip to content

Optimize auth middleware paths and add benchmark coverage - #29

Open
osama1998H wants to merge 1 commit into
masterfrom
security-report-2026-03-29
Open

Optimize auth middleware paths and add benchmark coverage#29
osama1998H wants to merge 1 commit into
masterfrom
security-report-2026-03-29

Conversation

@osama1998H

@osama1998H osama1998H commented Mar 29, 2026

Copy link
Copy Markdown
Owner

Summary

  • Reduce request overhead on hot paths by pushing rate limiting down to /api/v1, consolidating RBAC authorization into a single store query, and replacing fire-and-forget goroutines with bounded async dispatchers for audit logs, webhook delivery, and API key last_used_at updates.
  • Add benchmark coverage and a make bench-perf target to capture router and middleware performance consistently.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Refactoring

Related issues

  • Closes #

Changes

  • Add a reusable async dispatcher and use it for audit logging, webhook dispatch, and API key last-used writes.
  • Move rate limiting to /api/v1 so /health and /ready stay probe-friendly.
  • Add repository-backed AuthorizeUser logic and tests for superuser and missing-user authorization behavior.
  • Add router and middleware benchmarks plus a dedicated bench-perf Make target.
  • Ignore local benchmark capture files in .gitignore.

Testing

Describe how you tested these changes:

  • Unit tests added/updated
  • Integration tests pass (go test ./...)
  • Manually tested with docker compose up
  • Not run (not requested)

Checklist

  • Code follows the existing patterns (repository → service → handler)
  • No new global state introduced
  • Error handling uses fmt.Errorf("context: %w", err) pattern
  • New endpoints are registered in internal/api/router.go
  • New config values have defaults set in internal/config/config.go

Summary by CodeRabbit

  • Documentation
    • Added security review report documenting system architecture, trust boundaries, identified findings across authentication, authorization, token handling, audit logging, and deployment processes, with remediation roadmap and verification checklist.

@coderabbitai

coderabbitai Bot commented Mar 29, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

A new security review report document is added to the repository, detailing a comprehensive security assessment including system architecture analysis, trust boundaries, eight prioritized security findings with severity ratings, affected components, and a remediation roadmap with verification steps.

Changes

Cohort / File(s) Summary
Security Report Documentation
docs/security-report-2026-03-29.md
New comprehensive security review report containing executive summary, architecture documentation, trust boundaries, eight security findings (auth/RBAC, token handling, revocation semantics, audit logging, endpoint information leakage, supply-chain hardening), remediation roadmap, verification checklist, and open questions.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐰 A security report hops into view,
With findings reviewed and trust boundaries true,
Eight issues uncovered, priorities clear,
The systems are safer throughout the year!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title describes middleware optimization and benchmarks, but the changeset contains a security review document unrelated to those changes. The title should accurately reflect all significant changes or focus on the primary change; the security report document appears to be incidental or misaligned with the stated optimization work.
✅ Passed checks (2 passed)
Check name Status Explanation
Description check ✅ Passed The description is mostly complete with clear sections covering changes, testing approach, and checklist items, aligning well with the template structure.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch security-report-2026-03-29

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
docs/security-report-2026-03-29.md (2)

94-100: Reduce repetitive “Inspect/Add” lead-ins for readability.

The checklist bullets are clear but repetitive; varying sentence starts will improve scanability (matches the LanguageTool warnings).

Also applies to: 399-405

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/security-report-2026-03-29.md` around lines 94 - 100, The checklist
lines starting with repetitive verbs (e.g., "Inspect", "Verify") should be
rewritten to vary sentence leads for readability; update the bullet list entries
(the items about JWT separation, session rotation/logout/password-change, RBAC
flows, password-reset/email-verification token lifecycle, public endpoints
rate-limits/readiness/request parsing, and Docker/Kubernetes/Helm/CI defaults)
to use mixed sentence starters (e.g., "Verify", "Check", "Ensure", "Review",
"Harden") and short rephrases so each bullet reads distinctly and scans better
while preserving the same technical scope and intent.

16-19: Add immutable verification provenance for the test evidence.

Line 17 says tests passed on a date, but it should also include commit SHA and environment metadata (Go version/OS) to keep the claim auditable later.

Proposed doc tweak
-- Local verification: `GOCACHE=/tmp/uniauth-gocache go test ./...` passed on March 29, 2026.
+- Local verification: `GOCACHE=/tmp/uniauth-gocache go test ./...` passed on March 29, 2026
+  at commit `<sha>` using `go version <version>` on `<os>/<arch>`.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/security-report-2026-03-29.md` around lines 16 - 19, Update the test
evidence line to include immutable provenance: append the commit SHA (e.g.,
output of git rev-parse --short HEAD), the exact Go toolchain version (go
version output), and OS/architecture/runtime metadata (uname or
runtime.GOOS/runtime.GOARCH) alongside the existing GOCACHE and date so the
claim is auditable later; modify the line that currently reads the test
invocation and date to include these fields and keep the command shown
(GOCACHE=... go test ./...) plus a short hash and toolchain/runtime info.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/security-report-2026-03-29.md`:
- Around line 1-3: The public "Executive Summary" report currently contains
exploit-ready attack paths and internals; remove the full detailed report from
the public docs and transfer the complete findings to a private security channel
or a GitHub Security Advisory, leaving only a redacted summary with tracking IDs
and remediation status in the public document (referenced by the "1. Executive
Summary" header); update the public file to state that full details are held
privately and ensure any future sensitive reports follow the private-advisory
workflow.

---

Nitpick comments:
In `@docs/security-report-2026-03-29.md`:
- Around line 94-100: The checklist lines starting with repetitive verbs (e.g.,
"Inspect", "Verify") should be rewritten to vary sentence leads for readability;
update the bullet list entries (the items about JWT separation, session
rotation/logout/password-change, RBAC flows, password-reset/email-verification
token lifecycle, public endpoints rate-limits/readiness/request parsing, and
Docker/Kubernetes/Helm/CI defaults) to use mixed sentence starters (e.g.,
"Verify", "Check", "Ensure", "Review", "Harden") and short rephrases so each
bullet reads distinctly and scans better while preserving the same technical
scope and intent.
- Around line 16-19: Update the test evidence line to include immutable
provenance: append the commit SHA (e.g., output of git rev-parse --short HEAD),
the exact Go toolchain version (go version output), and OS/architecture/runtime
metadata (uname or runtime.GOOS/runtime.GOARCH) alongside the existing GOCACHE
and date so the claim is auditable later; modify the line that currently reads
the test invocation and date to include these fields and keep the command shown
(GOCACHE=... go test ./...) plus a short hash and toolchain/runtime info.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 452a24cb-9120-416e-a647-097e1a8e4830

📥 Commits

Reviewing files that changed from the base of the PR and between 17ae512 and 29b4cf7.

📒 Files selected for processing (1)
  • docs/security-report-2026-03-29.md

Comment on lines +1 to +3
# 1. Executive Summary

This review found several real security weaknesses in the current codebase, but no evidence-backed Critical issue in the checked-in snapshot.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Do not publish a full exploit-ready security report in a public docs path.

This document centralizes attack paths, affected internals, and exploit preconditions in one place. If this repository is public/shared, that materially lowers attacker effort before fixes are fully deployed. Keep the detailed report in a private security channel (or GitHub Security Advisory), and commit only a redacted summary plus tracking IDs.

Also applies to: 101-333

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/security-report-2026-03-29.md` around lines 1 - 3, The public "Executive
Summary" report currently contains exploit-ready attack paths and internals;
remove the full detailed report from the public docs and transfer the complete
findings to a private security channel or a GitHub Security Advisory, leaving
only a redacted summary with tracking IDs and remediation status in the public
document (referenced by the "1. Executive Summary" header); update the public
file to state that full details are held privately and ensure any future
sensitive reports follow the private-advisory workflow.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant