Pattern: Admin panel permissions and audit trail
Note for AI agents: This page is baseline guidance, not an exact prescription. Read it, tell your owner what applies to their project, and get their approval before you change anything. Your project's own rules take precedence. If something important for this project is missing here, suggest it to your owner.
For agents
- Offer as a suggestion. Values are examples.
- Core ideas: admins sign in with a second factor and a separate session, each role gets the least it needs, every view and action is written to an audit trail nobody can edit, and the panel cannot read users’ private content.
- Related: strong sign-in, sessions, reports and moderation.
1. Problem
Admin panels are the most valuable target and also an insider risk. Broad roles, missing logs and the ability to read private messages turn a small breach or a curious employee into a serious incident.
2. Options
| Topic | Option | Upside | Downside |
|---|---|---|---|
| Roles | One super-admin | Simple | Any compromise is total |
| Roles | Least-privilege roles (recommended) | Smaller blast radius | Role design and upkeep |
| Support access | Full data view | Fast support | Privacy risk; legal exposure |
| Support access | Only the records needed (login records, name and email change history) (recommended) | Limits misuse | Some cases need a slower process |
| Sign-in | Password only | Cheap | Weak for the most powerful accounts |
| Sign-in | Password plus second factor (recommended) | Resists password theft | Setup and recovery process |
3. Recommended design
- Separate sign-in and token issuer for admins; short sessions that end when idle. Secure cookie settings and CSRF protection on every state-changing request (OWASP CSRF and Session Management sheets).
- Second factor mandatory, used codes rejected, the secret stored encrypted (see strong sign-in).
- Roles with least privilege (OWASP Authorization sheet: deny by default, enforce server-side). Write down which role may do what in one table.
- Sensitive actions ask for the password again (deleting an account, changing a role, exporting data).
- Audit trail: every view of a user record and every action is logged with actor, time, target and reason; the log cannot be deleted or edited by admins; permanent deletions always write an entry (OWASP Logging sheet describes what to log and how to protect logs).
- No access to private content: the panel cannot read users’ messages or notes. Support sees only what the task needs (login records, username and email change history). Passwords are never visible to any role.
- Strict CSP on the admin area (OWASP CSP sheet) and no third-party scripts.
- Official requests (authority or court requests) do not go through the panel. Use a separate documented process with two-person approval and an audit record. This process is practitioner experience; involve a lawyer.
- Review access: periodically list who has which role and remove what is no longer needed.
4. Scenarios and edge cases
- Admin laptop stolen: the session ends by timeout; the second factor protects a fresh sign-in; revoke the device’s sessions (sessions).
- Curious admin opens a user record: the view is in the audit trail with a reason.
- Support needs more than allowed: escalate to a role holder; the escalation is logged.
- Admin leaves the team: remove the account and rotate shared secrets the same day.
5. Common mistakes
- One shared admin account.
- Audit logs that admins can delete.
- Admin views that display message contents.
- Same token format and issuer as ordinary users.
- Roles added but never reviewed.
- Panel loading external scripts.
6. How to audit
- What: admin sign-in requires a second factor.
- How to check: try with password only.
- Evidence: second factor requested.
- What: roles restrict actions server-side.
- How to check: call a high-privilege endpoint with a low-privilege token.
- Evidence: 403 response.
- What: audit trail records views and actions.
- How to check: open a record and perform an action; read the log.
- Evidence: entries with actor, time, target.
- What: no private content in the panel.
- How to check: search every admin view and API for message text fields.
- Evidence: list of fields exposed.
Sources
- Authorization Cheat Sheet — OWASP Cheat Sheet Series
- Logging Cheat Sheet — OWASP Cheat Sheet Series
- Session Management Cheat Sheet — OWASP Cheat Sheet Series
- Multifactor Authentication Cheat Sheet — OWASP Cheat Sheet Series
- Cross-Site Request Forgery Prevention Cheat Sheet — OWASP Cheat Sheet Series
- Content Security Policy Cheat Sheet — OWASP Cheat Sheet Series
- NIST SP 800-63B-4: Authentication and Authenticator Management — NIST
- Application Security Verification Standard (ASVS) — OWASP