backend
Technical notes on web development, DevOps, and AI integration.
157 articles
- 00:24security
Enum and Slug: The Two Identifiers That Keep a Gate Shut
The moderation gate never rejected anyone: an unmapped enum simply compared false forever, and read-only won by default.
TL;DR: A read-only badge appeared on all reviews because the frontend passed raw module enums like PARIWISATA into a gate expecting slugs like wisata, so the check silently failed and defaulted to read-only. The fix centralized enum-to-slug mapping in one TypeScript Record. Server-side, guardModule now enforces deny-by-default checks with tests locking in 403s and 404s.
#rbac#typescript#authorization - 23:29backend
Two Sets: What You May Read, What You May Manage
Opening read access across departments without loosening writes: readable and manageable module sets as two separate fail-closed sets.
TL;DR: KotaPortal treated the module query parameter as a write gate, hiding all content from other departments. The fix splits access into two sets: ModulesFor for writable modules and ReadableModules for readable ones, with fail-closed checks moved earlier in the chain. The frontend keeps full navigation while write affordances hide per permission, marked by a read-only banner.
#rbac#golang#http - 23:28security
Error Bodies That Repeat Your Input Back
API error messages that echo requester input are a cheap reconnaissance channel. The fix: specific code, static detail, regression tests.
TL;DR: KotaPortal's admin API was reflecting user input back in error messages across five spots in two services, confirming injection viability per OWASP guidance. The fix keeps specific error codes but makes human-readable details fully static, never echoing request data. Each endpoint gets a regression test that sends a random probe and fails if the probe appears in the response.
#api#security#http - 23:28backend
A Rental Package CRUD That Knows Its Scope
A scope-aware rental package CRUD: nil versus empty slice for fail-closed, five domain errors, one mapError translating them to HTTP.
TL;DR: Rental package CRUD centralizes authorization in a service layer instead of scattered handler checks, returning five domain errors mapped to precise HTTP codes. A sentinel pair makes it fail-closed: nil means global access, empty slice means deny-all. Tests verify status codes and deny-by-default behavior, so unrecognized departments never slip through.
#golang#rbac#http - 13:50backend
From Full Buffering to Streaming Uploads in Go
Five slots times 10 MiB per request is a DoS invitation. A per-user rate limit plus multipart streaming cuts memory to roughly 1 MiB per request.
TL;DR: Buffering five 10 MiB uploads per request risked gigabytes under concurrent load, since a per-request cap doesn't limit request frequency. A per-user rate limiter of 30 requests per minute returns 429 with Retry-After to cap waves. Streaming with a 1 MiB memory window keeps each request near 1 MiB regardless of file size.
#go#security#upload - 13:50backend
When a Generic Error Swallows the Validation Message
The service composed a precise validation message; the handler answered generically. A bridge pattern forwards audited static detail, locked by a regression test.
TL;DR: A shared respondErr helper collapsed a precise validation message into one generic string, leaving an admin guessing. The fix forwards static business-rule detail after auditing every wrap site for user input, while dynamic detail stays in logs. A regression test locks the message so it cannot silently vanish again.
#go#error-handling#api - 01:00backend
The filter that stayed silently empty
Three public failures in one night: a filter that never matched, search exploding to 500, and a 403 echoing input.
TL;DR: A broken anchored LIKE pattern made the amenity filter always return empty rows, fixed by switching to substring matching with wildcards escaped. An unsanitized search term crashed MySQL's full-text parser via a single asterisk, fixed by stripping operator characters at the boundary. A 403 response echoed user input back to attackers, fixed by replacing it with a static message while logging the raw value.
#mysql#sql#input-validation - 23:52database
Loyal CASCADE: When Deleting an Account Takes the Content With It
The 409 guard never fired because CASCADE removed the content first. Migration 000067 flips the order: RESTRICT refuses at the database, then the guard speaks.
TL;DR: A delete endpoint removed a citizen account plus all its content because the foreign keys used ON DELETE CASCADE, letting InnoDB wipe child rows before the app's ErrHasContent guard could check them. Migration 000067 switched those constraints to RESTRICT, MySQL's default, so the database refuses first. Five integration tests verify both up and down migrations.
#mysql#go#security - 22:45security
An Empty Scope Is Not Everything: Fail-Closed Choreography
An empty scope column used to mean ALL for legacy tokens. The four-step choreography that flipped the middleware to deny 403 BIDANG_UNSET.
TL;DR: An empty bidang scope was silently treated as ALL, a classic failing-open bug that let unscoped accounts pass authorization. Retiring it took choreography: backfill data, kill the shim's producers, prove a census of zero empty rows, then flip middleware to deny with 403 BIDANG_UNSET. Two denial layers and one documented exception (system actor userID 0) make the deny-by-default contract auditable.
#go#security#rbac