Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/palette.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,7 @@
## 2026-08-12 - Skip to Content Accessibility
**Learning:** Screen reader and keyboard-only users experience significant friction when forced to navigate through repetitive header controls on every page load.
**Action:** Keep a visible-on-focus skip link as the first interactive element, target a programmatically focusable main container, and give the focused link a high-contrast outline.

## 2026-08-12 - CSP-Compatible Dashboard Controls
**Learning:** Inline event attributes prevent deployment under strict Content Security Policy and can silently regress when newly rendered controls bypass the shared listener contract.
**Action:** Bind upload, severity, filter-clear, and dialog-close behavior with event listeners, keep the native file input behind an accessible proxy, and clear its value before parsing so the same file can be selected again.
32 changes: 28 additions & 4 deletions scanner/dashboard/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@
<span class="logo"></span><span class="brand">AppGuardrail</span>
<span class="spacer"></span>
<span class="meta" id="src">no findings loaded</span>
<input type="file" id="file" accept="application/json,.json" aria-label="Upload findings file" style="margin-left:12px">
<button type="button" id="header-browse-btn" class="primary-action" aria-label="Upload findings file" style="margin-left:12px;min-height:28px;padding:4px 12px;font-size:13px">Load Findings</button>
<input type="file" id="file" accept="application/json,.json" class="sr-only" tabindex="-1" aria-hidden="true">
</header>
<p id="findings-summary" class="sr-only" role="status" aria-live="polite" aria-atomic="true"></p>
<main id="app" tabindex="-1"></main>
Expand Down Expand Up @@ -183,7 +184,7 @@ <h1>Clean scan</h1>
const isSelected = filterSev === s;
const style = isSelected ? 'border-color:var(--primary); box-shadow:0 0 0 1px var(--primary); cursor:pointer;' : 'cursor:pointer;';
return `
<div class="card" role="button" tabindex="0" aria-label="Filter by ${s}: ${counts[s]}" aria-pressed="${isSelected}" onclick="document.getElementById('sev').value='${isSelected ? '' : s}'; document.getElementById('sev').dispatchEvent(new Event('change'));" onkeydown="if(event.key==='Enter'||event.key===' '){event.preventDefault(); this.click();}" style="${style}">
<div class="card severity-card" role="button" tabindex="0" data-severity="${s}" aria-label="Filter by ${s}: ${counts[s]}" aria-pressed="${isSelected}" style="${style}">
<div class="lbl"><span class="dot" style="background:${SEV[s].color}"></span>${s}</div>
<div class="n">${counts[s]}</div>
</div>`;
Expand Down Expand Up @@ -235,7 +236,7 @@ <h1>Dashboard</h1>
<thead><tr><th scope="col">Severity</th><th scope="col">Finding</th><th scope="col">File</th><th scope="col">Category</th><th scope="col">Status</th></tr></thead>
<tbody>${rows||`<tr><td colspan="5" style="padding:32px 24px;text-align:center">
<div style="color:var(--text);font-weight:600;font-size:14px;margin-bottom:8px">No findings match the filter</div>
<button type="button" aria-label="Clear filters" onclick="query=''; filterSev=''; render(); document.getElementById('q')?.focus();" style="padding:6px 12px;border-radius:6px;border:1px solid var(--border);background:var(--surface);cursor:pointer;font:inherit;color:var(--text);font-weight:500;transition:background 0.2s">Clear filters</button>
<button type="button" id="clear-filters-btn" aria-label="Clear filters" style="padding:6px 12px;border-radius:6px;border:1px solid var(--border);background:var(--surface);cursor:pointer;font:inherit;color:var(--text);font-weight:500;transition:background 0.2s">Clear filters</button>
</td></tr>`}</tbody>
</table></div>
</div>
Expand All @@ -245,6 +246,27 @@ <h1>Dashboard</h1>
liveSummary.textContent = summaryText;
}

app.querySelectorAll('.severity-card').forEach(card => {
const activate = () => {
const severitySelect = document.getElementById('sev');
severitySelect.value = card.dataset.severity === filterSev ? '' : card.dataset.severity;
severitySelect.dispatchEvent(new Event('change'));
};
card.addEventListener('click', activate);
card.addEventListener('keydown', e => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
activate();
}
});
});
document.getElementById('clear-filters-btn')?.addEventListener('click', () => {
query = '';
filterSev = '';
render();
document.getElementById('q')?.focus();
});

document.getElementById('q').addEventListener('input', e=>{
query = e.target.value.toLowerCase();
render();
Expand Down Expand Up @@ -290,7 +312,7 @@ <h1>Dashboard</h1>
<div class="dlg-head">
<span class="chip" style="background:${SEV[s]?SEV[s].color:'var(--info)'}">${esc(s)}</span>
<span class="t" id="dlg-title">${esc(f.rule_id)}</span>
<button aria-label="Close" title="Close (Esc)" onclick="document.getElementById('detail').close()">โœ•</button>
<button id="detail-close-btn" aria-label="Close" title="Close (Esc)">โœ•</button>
</div>
<div class="dlg-body">
<p class="file">${esc(f.file)}:${esc(f.line)} ยท ${esc(f.category)} ยท context: ${esc(f.context||'app-code')}${isDeployBlocking(f)?' ยท <span class="tag block">deploy-blocking</span>':''}</p>
Expand All @@ -303,6 +325,7 @@ <h1>Dashboard</h1>
${cwe?`<div class="kv">CWE: ${esc(cwe)}</div>`:''}
${refs?`<div style="margin-top:6px">${refs}</div>`:''}</div>`:''}
</div>`;
d.querySelector('#detail-close-btn').addEventListener('click', () => d.close());
d.showModal();
}

Expand All @@ -325,6 +348,7 @@ <h1>Dashboard</h1>
}

const fileInput = document.getElementById('file');
document.getElementById('header-browse-btn')?.addEventListener('click', () => fileInput.click());
fileInput.addEventListener('change', () => {
const selectedFile = fileInput.files?.[0];
fileInput.value = '';
Expand Down
31 changes: 24 additions & 7 deletions tests/test_dashboard_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ def test_dashboard_severity_cards_are_accessible_filter_toggles():

assert 'aria-label="Filter by ${s}: ${counts[s]}"' in html
assert 'aria-pressed="${isSelected}"' in html
assert "document.getElementById('sev').value='${isSelected ? '' : s}'" in html
assert "dispatchEvent(new Event('change'))" in html
assert (
'onkeydown="if(event.key===\'Enter\'||event.key===\' \')'
'{event.preventDefault(); this.click();}"' in html
)
assert 'data-severity="${s}"' in html
assert "app.querySelectorAll('.severity-card').forEach" in html
assert "card.addEventListener('click', activate)" in html
assert "card.addEventListener('keydown'" in html
assert "e.key === 'Enter' || e.key === ' '" in html
assert "severitySelect.dispatchEvent(new Event('change'))" in html


def test_dashboard_escapes_severity_in_innerhtml():
Expand Down Expand Up @@ -271,10 +271,27 @@ def test_dashboard_empty_state_clear_filters():

assert "No findings match the filter" in html
assert "aria-label=\"Clear filters\"" in html
assert "onclick=\"query=''; filterSev=''; render(); document.getElementById('q')?.focus();\"" in html
assert 'id="clear-filters-btn"' in html
assert "document.getElementById('clear-filters-btn')?.addEventListener" in html
assert "Clear filters</button>" in html


def test_dashboard_uses_csp_compatible_controls_and_reselectable_upload():
"""Dashboard controls avoid inline handlers and allow same-file reselection."""
html = dashboard_index_path().read_text(encoding="utf-8")

assert "onclick=" not in html
assert "onkeydown=" not in html
assert 'id="header-browse-btn"' in html
assert 'class="sr-only" tabindex="-1" aria-hidden="true"' in html
assert (
"document.getElementById('header-browse-btn')?.addEventListener('click'"
in html
)
assert "fileInput.value = '';" in html
assert "d.querySelector('#detail-close-btn').addEventListener('click'" in html


def test_dashboard_dialog_close_button_has_tooltip():
"""The dynamically rendered close button exposes its label and Esc tooltip."""
html = dashboard_index_path().read_text(encoding="utf-8")
Expand Down
Loading