[Improvement]: Normalize audit record fields to the audit table column widths in API Portal

Aperta Adatta ai principianti
#4,231 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
Mezza giornata
Idoneità per principianti
72/100
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript, sql
Ambito
backend, database

Direzione di ricerca

Inizia in portals/api-portal/src/middlewares/auditLogger.js da logUserAction, poi segui i valori fino a auditDao.record e verifica dove util.resolveActor(req) fornisce performed_by. Leggi le larghezze delle colonne in database/schema.sqlite.sql, schema.postgres.sql e schema.sqlserver.sql, ma non modificarle. Il lavoro è completato quando esiste un unico passaggio di normalizzazione prima dell'inserimento, viene emesso un avviso che indica il nome del campo ogni volta che avviene un troncamento e ci sono test unitari per una stringa normale, un valore non stringa, un valore troppo lungo e un resourceType mancante.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Aspect/Other
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.

Lingua principale
Go
Stelle
85
Fork
137
Merge medio
1g 12h
PR unite (30g)
247

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di wso2/api-platform

Tutte le issue di wso2/api-platform

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.