[Improvement]: Normalize audit record fields to the audit table column widths in API Portal
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- Half a day
- Newbie friendliness
- 72/100
- Issue type
- Refactor
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript, sql
Research direction
Start in portals/api-portal/src/middlewares/auditLogger.js at logUserAction, then follow the values into auditDao.record and check where util.resolveActor(req) supplies performed_by. Read the column widths in database/schema.sqlite.sql, schema.postgres.sql and schema.sqlserver.sql but do not change them. Done means one normalisation step before the insert, a field-named warning when trimming occurs, and unit tests for a normal string, a non-string, an over-long value and a missing resourceType.
Written by the indexing model from the issue text.
Description
Area
Developer Portal (api-portal)
Aspect
Aspect/Other (audit trail robustness)
Suggested Improvement
Current behaviour
logUserAction (portals/api-portal/src/middlewares/auditLogger.js) saves an audit row through auditDao.record. The values come from the caller (action, resourceUuid, resourceType, orgUuid) and from util.resolveActor(req), and go straight into the INSERT as bind parameters.
The audit table has narrow columns (database/schema.sqlite.sql, schema.postgres.sql, schema.sqlserver.sql):
| Column | Width |
|---|---|
uuid, resource_uuid, org_uuid |
VARCHAR(40) |
action, resource_type |
VARCHAR(50) |
performed_by |
VARCHAR(255) |
SQLite does not enforce these widths. Postgres and SQL Server do. If a value ever exceeds its column, or is not a plain string, the insert fails. The failure is caught by the best-effort .catch in logUserAction and only logged as a warning ("Failed to persist audit record"), so that audit row is lost without anything else noticing.
Likelihood today: low. The callers I checked pass ids that were resolved to internal UUIDs (36 characters) and fixed action and resource-type constants, so I do not know of a failing case. This is a defensive gap, not a reported failure.
Suggested improvement
- Normalise the audit fields in one place before the insert: convert each to a string, trim it to its column width, and log a warning that names the field (not the value) when trimming happens.
- Keep the write best-effort, as it is today.
- Add unit tests for the normalisation: a normal string, a non-string value, an over-long value, and a missing
resourceType. - No schema change.
Out of scope: changing what is audited, or making audit writes blocking.
Related Issues
None.
- Dominant language
- Go
- Stars
- 85
- Forks
- 137
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 247
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from wso2/api-platform
-
Area/DeveloperPortal Aspect/UI Severity/Minor Type/Bug
Difficulty 1/5 Under an hour Newbie friendliness 88/100
wso2/api-platform#4369 ·
Maintainers usually reply within 1 day
-
[Bug]: host-rewrite policy documentation lists fewer allowed host characters than the policy acceptsOpenArea/Policies Aspect/Other Severity/Trivial Type/Bug
Difficulty 1/5 Under an hour Newbie friendliness 91/100
wso2/api-platform#4355 ·
Maintainers usually reply within 1 day
-
Area/Gateway Aspect/API Severity/Minor Type/Bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
wso2/api-platform#4348 ·
Maintainers usually reply within 1 day
-
Aspect/AI Aspect/API. Severity/Major
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
wso2/api-platform#4343 ·
Maintainers usually reply within 1 day
-
Area/Policies Aspect/Configuration Severity/Minor Type/Bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
wso2/api-platform#4330 ·
Maintainers usually reply within 1 day
All issues in wso2/api-platform
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Inconsistency between golang and cue in specPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
security
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
Tencent/LoopForge#1087 · 1 comment ·
Maintainers usually reply within 1 day