- Backend: - Fix ListTickets parameter order mismatch for assignee filtering - Replicate all 13 PostgreSQL tables and columns during disaster recovery sync and rollback - Implement server-side session store with HttpOnly cookies and Bearer tokens - Add profile update verification requiring current password - Whitelist allowed file uploads and apply strict security headers (nosniff, CSP) - Enforce role check on error deletion (admin/lead/tester only) and authenticate SSE stream - Align foreign key user_id for saved filters and api tokens - Add ReopenTicket endpoint and workflow - Integrate Cloudflare Turnstile verification with testing/production key support - Frontend: - Remove liquid glass displacement filter and lens capsule for high-performance UI - Eliminate recursive backdrop-filters and heavy inset shadows - Add debounced search and optimize SSE re-rendering - Wire Saved Views filter bar with creation, active indicators, and deletion - Add Linked & Related Tickets management UI to sheet - Seed 6 demo personas in PostgreSQL with instant sign-in - Add Cloudflare Turnstile widgets to authentication modals - Add keyboard arrow navigation to Command Palette - Image Manipulator, Docs & Tooling: - Sync image manipulator updates, docs, and test coordinates
17 KiB
Khira Comprehensive Defect Remediation & Cloudflare Turnstile Plan
For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (
- [ ]) syntax for tracking.
Goal: Eliminate all performance bottlenecks (nested backdrop-filters, un-debounced search, heavy SVG filters), remediate all security flaws (unauthenticated header spoofing, arbitrary file uploads, weak password hashing), resolve all backend logic defects (argument mismatch in ListTickets, disaster recovery data loss, inability to move to Open), fix all frontend anomalies (demo logins, upload key mismatches, missing links/attachments in sheets, dead features), and integrate Cloudflare Turnstile bot protection into Khira.
Architecture:
- Frontend Optimization: Replace recursive multi-stage
--glass-bluron dynamic elements with composited obsidian surfaces, throttle search input with a 200ms debounce, optimize the SVG liquid glass lens, and prevent duplicate canvas rendering. - Security & Turnstile: Implement secure session cookie/token verification (stopping
X-Khira-Userheader spoofing), upgrade password hashing, enforce file extension whitelists with safe headers, require current password on profile updates, and add Turnstile CAPTCHA verification on auth endpoints with fallback dev keys. - Backend & DB Integrity: Fix the parameter order mismatch in
ListTickets, updateSyncDatabasesandRollbackDatabasesto replicate all 13 tables and missing columns, add areopenendpoint for Open status transitions, and seed all demo users. - UI & Feature Completeness: Fix demo accounts, dual-key upload responses (
attachment.urlandurl), re-fetch ticket details on sheet open to show attachments/links, implement Saved Filters and Ticket Relations in UI, fix light theme CSS, and add keyboard navigation to the Command Palette.
Tech Stack: Go 1.22+, Chi Router, PostgreSQL 16 (khira_primary & khira_backup), Vanilla JS (ES6+), CSS Custom Properties, Cloudflare Turnstile API.
Global Constraints
- Do not break existing API contracts or response structures expected by other dashboard tools.
- PostgreSQL database credentials must default to
KHIRA_PRIMARY_DB_URLandKHIRA_BACKUP_DB_URLwith local defaults. - Always use the local python venv when running scripts:
source /home/creserver/extras/local_venv/bin/activate.fish. - Cloudflare Turnstile must support standard Cloudflare dummy testing keys (
1x00000000000000000000AA/1x0000000000000000000000000000000AA) as well as environment variablesKHIRA_TURNSTILE_SITE_KEYandKHIRA_TURNSTILE_SECRET_KEY.
Review Focus
ListTicketsquery parameter alignment:status,priority,app,assignee,reporter,query,ticket_type.- Disaster recovery database sync/rollback across all 13 tables and newly added columns (
due_date,sla_hours,sla_breached,active,last_active_at,deactivated_at). - Secure session cookie vs spoofed
X-Khira-Userheaders. - File upload extension whitelisting and direct SVG/HTML execution mitigation.
- Turnstile validation failure handling without blocking headless testing or demo logins.
Task 1: Fix Critical Backend Bug: ListTickets Parameter Order Mismatch
Files:
- Modify:
internal/khira/handlers.go:394-412 - Modify:
internal/khira/store.go:731-795
Interfaces:
-
Consumes: HTTP Query params (
status,priority,app,assignee,creator/reporter,role,type/ticket_type,q) -
Produces: Correctly filtered
[]*Ticketmatching all specified criteria -
Step 1: Check existing broken behavior with curl Run:
curl -s -H "X-Khira-User: admin" "http://127.0.0.1:10000/khira/api/tickets?assignee=admin"Expected: Currently returns{"count":0,"tickets":null}due to argument mismatch. -
Step 2: Fix argument order in
handleListTicketsininternal/khira/handlers.goExtractapp := r.URL.Query().Get("app"),assignee,creator := r.URL.Query().Get("creator")(fallback toreporter),q,ticketType. Calls.Store.ListTickets(status, priority, app, assignee, creator, q, ticketType)in the exact order matchingstore.go. -
Step 3: Update
ListTicketsininternal/khira/store.goto support role-based filtering Ifroleis provided, addLOWER(created_by_role) = LOWER(...) OR LOWER(assigned_to_role) = LOWER(...). Ensure SQL query correctly parameterizes all conditions. -
Step 4: Recompile and verify ticket filtering Run:
go build -o bin/nexus-gateway cmd/nexus-gateway/main.goand restart/test gateway. Run:curl -s -H "X-Khira-User: admin" "http://127.0.0.1:10000/khira/api/tickets?assignee=admin"Expected: Returns KHR-101 (count: 1).
Task 2: Fix Disaster Recovery: Complete All Tables & Columns in DB Sync/Rollback
Files:
- Modify:
internal/khira/db.go:290-670 - Modify:
internal/khira/handlers.go:1399-1460 - Modify:
web/khira/app.js:1950-1965
Interfaces:
-
Consumes:
primaryDB,backupDBconnections -
Produces: Fully consistent mirrored database state with zero dropped tables or columns
-
Step 1: Update
SyncDatabasesininternal/khira/db.goInclude all 13 tables: -
users: add columnsactive,last_active_at,deactivated_at. -
tickets: add columnsdue_date,sla_hours,sla_breached. -
Add replication for:
ticket_tags,error_tags,ticket_relations,saved_filters,api_tokens. Truncate cascade query must cleanly handle all tables. -
Step 2: Update
RollbackDatabasesininternal/khira/db.goMirror the exact same 13 tables and complete column set when restoring frombackupDBtoprimaryDB. -
Step 3: Fix
adminSyncDB()inweb/khira/app.jsandhandleDBSyncinhandlers.goMakehandleDBSyncaccept authenticated admin session without requiring re-prompt, or prompt cleanly inapp.jslikeadminRollbackDB(). EnsureadminSyncDBsends the admin password if requested. -
Step 4: Verify DB Sync and Rollback Test
/khira/api/admin/db/syncand/khira/api/admin/db/statusvia curl and UI. Confirm all tables (including tags, relations, tokens) retain counts.
Task 3: Backend Security Hardening: Authentication, Session Tokens & Safe File Uploads
Files:
- Modify:
internal/khira/handlers.go:31-55, 325-366, 934-1004 - Modify:
internal/khira/handlers_enterprise.go:300-370 - Modify:
internal/khira/store.go:116-240, 1458-1468 - Modify:
internal/khira/events.go:74-119
Interfaces:
-
Consumes: Login credentials, session cookies, auth tokens, upload multipart form
-
Produces: Cryptographically verified user actor, sanitized file uploads, protected admin routes
-
Step 1: Implement Session Tokens in Auth Store In
internal/khira/store.go: Generate a secure session token (32 random hex bytes) on successfulAuthenticateUser. Store in an active sessions map or table with user ID and expiry (7 days). Set HTTP-only session cookiekhira_sessionon/auth/loginand/auth/register. Clear on/auth/logout. -
Step 2: Secure
getActorIninternal/khira/handlers.go: Validate the session token fromkhira_sessioncookie orAuthorization: Bearer <token>against the session store orapi_tokens. Deprecate unauthenticated rawX-Khira-Userheader unless accompanied by a valid session cookie or valid API token, preventing arbitrary identity spoofing. -
Step 3: Require Current Password for Profile Updates In
handleUpdateProfile: Ifreq.NewPasswordorreq.Passwordis provided, requirereq.CurrentPassword. Verify withAuthenticateUser(actor.Username, req.CurrentPassword). Reject with 401 Unauthorized if invalid. -
Step 4: Protect File Uploads against Stored XSS In
handleUpload: Enforce extension whitelist:.png,.jpg,.jpeg,.webp,.gif,.txt,.log,.pdf,.json. Reject.html,.htm,.svg,.js,.sh,.py,.exewith400 Invalid file type. Add response headers on/khira/uploads/*:X-Content-Type-Options: nosniff,Content-Security-Policy: default-src 'none'; img-src 'self' data:; style-src 'unsafe-inline', andContent-Disposition: inline(for safe images) orattachment(for other files). Return both"attachment": attand"url": att.URLin the JSON response. -
Step 5: Restrict Error Telemetry Deletion and Authenticate SSE In
DeleteError: Requires.isAdmin(actor)oractor.Role == RoleTester || actor.Role == RoleLead. InhandleEventsSSE: Requires.getActor(r) != nilbefore subscribing.
Task 4: Frontend Performance Optimization (Eliminate UI Lag & High Resource Usage)
Files:
- Modify:
web/khira/styles.css:50-85, 720-805, 1620-1660 - Modify:
web/khira/app.js:225-285, 355-440, 2215-2225, 2310-2335 - Modify:
web/khira/index.html:18-36
Interfaces:
-
Consumes: UI rendering events, scroll, search input, drag and drop
-
Produces: 60+ FPS responsive UI with lightweight compositing and zero typing lag
-
Step 1: Eliminate recursive nested
backdrop-filterinstyles.cssRemovebackdrop-filter: var(--glass-blur)from.col,.card,.stat,.fld, etc. Replace with clean, hardware-composited semi-transparent dark surfaces:
background: rgba(14, 18, 28, 0.88);
border: 1px solid rgba(255, 255, 255, 0.08);
Retain backdrop-filter: blur(12px) ONLY on non-nested overlays (.app-header, .modal-overlay, .sheet).
Remove multi-layer inset box-shadows that force heavy paint cycles.
-
Step 2: Optimize Kube.io Liquid Glass Precision Lens When lens is closed, ensure SVG filter and container are completely unrendered (
display: none). Optimize the lens capsule to use lightweight CSS magnification/border refraction rather than a 7-stage SVG displacement map that forces CPU rasterization on mouse move. -
Step 3: Debounce Global Search (
#q) Inweb/khira/app.js: Add a 200ms debounce timer to#qinput listener:
let searchTimer = null;
document.addEventListener('input', e => {
if (e.target.id === 'q') {
clearTimeout(searchTimer);
searchTimer = setTimeout(() => {
S.q = e.target.value.trim().toLowerCase();
render(false);
}, 200);
}
});
Do not rewrite #fa options on search keystrokes unless users changed.
- Step 4: Fix Duplicate Canvas Redraw in SSE
In
handleRealtimeEvent(): Remove the duplicaterenderA(false)call on line 2326, sincerefresh(false)already re-renders the active section when data changes.
Task 5: Seed Demo Accounts & Fix Landing Page Authentication
Files:
- Modify:
internal/khira/db.go:245-285 - Modify:
web/khira/app.js:2250-2255
Interfaces:
-
Consumes: Demo buttons click events (
charlie,alice,bob,diana,eva,admin) -
Produces: Successful one-click sign in for all demo personas
-
Step 1: Seed all 6 demo accounts in
seedDefaultUsers(db.go) Seed: -
admin(System Administrator,team_lead, pass:adminandadmin123) -
charlie(Charlie Patel,tester, pass:charlie123) -
alice(Alice Sharma,ios_dev, pass:alice123) -
bob(Bob Anderson,backend_dev, pass:bob123) -
diana(Diana Prince,android_dev, pass:diana123) -
eva(Eva Chen,designer, pass:eva123) -
Step 2: Update demo button handlers in
app.jsEnsureadmindemo button usesadmin123oradmin, matching seeded passwords. -
Step 3: Verify all 6 demo logins Test login via curl or browser for all 6 personas.
Task 6: Cloudflare Turnstile Integration
Files:
- Create:
internal/khira/turnstile.go - Modify:
internal/khira/handlers.go:103-112, 205-255 - Modify:
web/khira/index.html:10-15, 45-62 - Modify:
web/khira/app.js:2230-2265
Interfaces:
-
Consumes:
cf-turnstile-responsetoken from client -
Produces: Verified server-side challenge via Cloudflare Turnstile API (
https://challenges.cloudflare.com/turnstile/v0/siteverify) -
Step 1: Implement Cloudflare Turnstile verification in
internal/khira/turnstile.goReadKHIRA_TURNSTILE_SECRET_KEY(fallback to official Cloudflare dummy key1x0000000000000000000000000000000AAwhich always passes). Implement:
func VerifyTurnstile(token, remoteIP string) (bool, error)
POST to https://challenges.cloudflare.com/turnstile/v0/siteverify with secret, response, and remoteip.
-
Step 2: Add Turnstile endpoint & verification in
handlers.goExposeGET /khira/api/auth/turnstile-configreturning{"site_key": "..."}. Verify token inhandleLogin,handleRegister, andhandleForgotPassword. Allow bypass for demo accounts if triggered via demo button. -
Step 3: Add Turnstile Widget to Frontend In
web/khira/index.html: Add<script src="https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit" async defer></script>. Add container<div id="turnstileWidget" class="turnstile-container"></div>to#fInand#fUp. -
Step 4: Wire Turnstile in
app.jsFetch site key from/khira/api/auth/turnstile-config. Render widget explicitly viaturnstile.render('#turnstileWidget', { sitekey: ... }). Include token in submit payloads.
Task 7: Fix Ticket Lifecycle (Moving to Open, Sheet Attachments/Links & Upload Keys)
Files:
- Modify:
internal/khira/handlers.go:120-135, 934-1004 - Modify:
internal/khira/store.go:935-965 - Modify:
web/khira/app.js:485-498, 995-1030, 1315-1335, 2070-2090
Interfaces:
-
Consumes: Card drag/drop, ticket detail sheet open, image uploads
-
Produces: Reliable ticket lifecycle transitions, persisted attachments/links in detail drawer, reliable image uploads
-
Step 1: Add Reopen / Move to Open in Store & Handler In
internal/khira/store.go: ImplementReopenTicket(ticketID string, actor *User, remarks string) (*Ticket, error)which updatesstatus = 'open', resetshold_reasonandcompletion_remarks. RegisterPOST /khira/api/tickets/{id}/reopeninhandlers.go. Support"open"inBulkActionstatus updates. -
Step 2: Update
initBoardDragDropinapp.jsWhen dropped inopen: Call/khira/api/tickets/${id}/reopen. -
Step 3: Fix Upload JSON Response & Client Handlers In
handlers.gohandleUpload: return both{"status": "ok", "url": att.URL, "attachment": att}. Inapp.js: InnewTicket():uploadedImageUrl = upJson.url || upJson.attachment?.url;Inprofile():curImgUrl = upJson.url || upJson.attachment?.url; -
Step 4: Fetch Fresh Ticket Details in
sheet(id)Insheet(id): Callconst fullT = await api('/khira/api/tickets/' + encodeURIComponent(id));so full attachments, links, and tags are always displayed.
Task 8: Implement Missing Features & Polish Frontend Defects
Files:
- Modify:
web/khira/index.html:110-115, 205-225 - Modify:
web/khira/app.js:9-45, 1120-1165, 1830-1925, 2195-2205 - Modify:
web/khira/styles.css:75-90
Interfaces:
-
Consumes: UI events for filters, palette, themes, notifications
-
Produces: Fully functional Saved Filters, General Category dropdown, arrow-key navigable Command Palette, clean Light Theme, and missing icons
-
Step 1: Add General Category & Department in
newTicket()Add Category dropdown (CATS) and Scope/Department text field/chips in#modalCreateTicket/newTicket(). Pass to payload. -
Step 2: Implement Saved Filters UI In
app.js: Add handlers to fetch/khira/api/filters, render chips into#savedFilterChips, and allow saving current filter state. -
Step 3: Command Palette Keyboard Navigation (
ArrowUp,ArrowDown,Enter) InopenCmdPalette()and keydown listener: TrackactiveCmdIndex. OnArrowDown, highlight next item. OnArrowUp, highlight previous item. OnEnter, execute highlighted action. -
Step 4: Fix Light Theme in
styles.cssIn[data-theme="light"]: Set--surf: #f8fafc,--obsidian-surface: #ffffff,--on-s: #0f172a,--on-sv: #475569,--sc: rgba(241, 245, 249, 0.9),--out: rgba(0, 0, 0, 0.1). Ensure light theme is readable and contrast-compliant. -
Step 5: Add
historyIcon & Fix Notification Read AddhistorySVG toICONS. When clicking a notification inpop(), callPOST /khira/api/notifications/${id}/readto persist read state. InescD(id), safely handlee.messagewith(e.message || e.description || '').slice(0, 60).
Task 9: Full System Verification & Regression Testing
Files:
-
Test all endpoints with curl and verify in browser
-
Step 1: Verify Go backend compiles with zero errors Run:
go build -o bin/nexus-gateway cmd/nexus-gateway/main.go -
Step 2: Restart Gateway and test all fixed endpoints
- Test demo logins (
admin,charlie,alice,bob,diana,eva). - Test ticket filtering (
?assignee=admin,?type=general,?status=open). - Test backup sync and rollback without data loss.
- Test moving a ticket from in_progress to open.
- Test ticket creation with image attachment.
- Test profile photo upload.
- Test Turnstile verification with dummy test key.
- Verify UI responsiveness, 60 FPS scrolling, and debounced search.