Skip to content

fix(web): make top-bar search work under strict CSP#105

Merged
DnaMes merged 2 commits into
mainfrom
fix/csp-search-inline-handler
Jul 5, 2026
Merged

fix(web): make top-bar search work under strict CSP#105
DnaMes merged 2 commits into
mainfrom
fix/csp-search-inline-handler

Conversation

@DnaMes

@DnaMes DnaMes commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Problem

Top-bar search does nothing — clicking/focusing the box never opens the search modal, so no query runs. Reported as "Suche geht nicht".

Root cause

The top-bar search box used an inline onfocus="openSearch()" handler. The app sends a strict nonce-based CSP (script-src 'self' 'nonce-...', no unsafe-inline, set in web.py:598), which blocks all inline event handlers. So focus never fired openSearch() → modal never opened → #searchInput never received input → /api/search was never called.

/api/search itself was healthy (verified curl ...?q=test → 200 with results). The bug was purely the CSP-blocked entry point.

Fix

lore/templates/base.html:

  • onfocus="openSearch()"id="searchTrigger"
  • wire searchTrigger.addEventListener('focus', openSearch) (CSP-compliant, matches the pattern already used for #searchInput and Cmd/Ctrl+K)

Verification

Rebuilt the image, drove it live with Playwright:

  • Focusing the top-bar box opens the Search sessions dialog ✅
  • Typing test returns 10 results ✅
  • 0 CSP console errors (was 1 before) ✅

Follow-ups (not in this PR)

  • Other templates (session.html, sessions.html, projects.html, …) still use inline on*= handlers → same CSP bug, likely dead buttons. Separate sweep.
  • lore-sync.service failed + fastembed missing in container (semantic search degraded to FTS-only).

🤖 Generated with Claude Code

https://claude.ai/code/session_01X9biLMX3yYXrHFRWz7U5gi

The top-bar search box used an inline `onfocus="openSearch()"` handler.
The app sends a strict nonce-based CSP (`script-src 'self' 'nonce-...'`,
no `unsafe-inline`), which blocks all inline event handlers. Focusing the
box therefore did nothing — the search modal never opened and no query
ever ran. `/api/search` itself was fine.

Replace the inline handler with a CSP-compliant `addEventListener`:
- `onfocus="openSearch()"` → `id="searchTrigger"`
- wire `searchTrigger.addEventListener('focus', openSearch)`

Verified live in browser (rebuilt image): modal opens on focus, typing
returns results, 0 CSP console errors.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X9biLMX3yYXrHFRWz7U5gi

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Web UI’s top-bar search trigger to be compatible with the app’s strict nonce-based Content Security Policy (CSP) by removing an inline event handler and wiring the behavior via JavaScript.

Changes:

  • Replace inline onfocus="openSearch()" on the top-bar search input with an id hook (searchTrigger).
  • Add a DOM event listener that opens the search modal when the trigger is interacted with.

Comment thread lore/templates/base.html
Comment on lines +1042 to +1045
const searchTriggerEl = document.getElementById('searchTrigger');
if (searchTriggerEl) {
searchTriggerEl.addEventListener('focus', openSearch);
}
The base.html change (onfocus → addEventListener) propagates to every
page that extends it. Regenerated all golden render snapshots with
UPDATE_TEMPLATE_SNAPSHOTS=1. Diff is limited to the searchTrigger swap.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X9biLMX3yYXrHFRWz7U5gi
@DnaMes DnaMes merged commit 91bba0c into main Jul 5, 2026
9 checks passed
@DnaMes DnaMes deleted the fix/csp-search-inline-handler branch July 5, 2026 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants