fix(ui): delete prompts use data-confirm, so a quote in a name no longer runs script (#5099)

#5099 "A name containing a quote runs script when an admin clicks Delete".
Inline handlers like onclick="return confirm('Delete {{ rule.name }}?')" are
HTML-decoded before the JavaScript is parsed, so autoescaping did not stop a
name such as  x');fetch(…);//  from running.

- Every prompt (22 handlers, plus the docker prune and token revoke ones)
  is now data-confirm="…", read through dataset by one submit listener in
  base.html; nothing rendered is parsed as JavaScript.
- The remaining inline handlers take integers only (|int), and the time
  range buttons pass this.dataset.range.
- tests/test_inline_handlers.py fails on any {{ }} in an inline handler that
  is not |int, with a self-test; tests/_templates.py is the one template
  walker the template guards now share.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-06 14:30:13 -04:00
co-authored by Claude Opus 5.5
parent 737d699308
commit f47fc23265
28 changed files with 97 additions and 49 deletions
+1 -1
View File
@@ -10,6 +10,6 @@
<button type="button"
class="range-btn{% if current_range == key %} active{% endif %}"
data-range="{{ key }}"
onclick="setTimeRange('{{ key }}')">{{ key }}</button>
onclick="setTimeRange(this.dataset.range)">{{ key }}</button>
{% endfor %}
</div>
+1 -1
View File
@@ -59,7 +59,7 @@
<td class="td-actions">
{% if row.state == 'active' %}
<form method="post" action="/ai-access/tokens/{{ t.id }}/revoke" style="margin:0;"
onsubmit='return confirm({{ ("Revoke “" ~ t.name ~ "”? Any client using it stops working immediately.")|tojson }})'>{{ csrf_field() }}
data-confirm="Revoke “{{ t.name }}”? Any client using it stops working immediately.">{{ csrf_field() }}
<button type="submit" class="btn btn-danger btn-sm">Revoke</button>
</form>
{% endif %}
+1 -1
View File
@@ -99,7 +99,7 @@
</form>
<form method="post" action="/alerts/rules/{{ rule.id }}/delete" style="display:inline;">{{ csrf_field() }}
<button type="submit" class="btn btn-sm btn-danger"
onclick="return confirm('Delete rule {{ rule.name }}?')">Delete</button>
data-confirm="Delete rule {{ rule.name }}?">Delete</button>
</form>
</td>
</tr>
+1 -1
View File
@@ -62,7 +62,7 @@
<td class="td-actions">
<form method="post" action="/alerts/maintenance/{{ w.id }}/delete" style="display:inline;">{{ csrf_field() }}
<button type="submit" class="btn btn-sm btn-danger"
onclick="return confirm('Delete window &quot;{{ w.name }}&quot;?')">Delete</button>
data-confirm="Delete window &quot;{{ w.name }}&quot;?">Delete</button>
</form>
</td>
</tr>
+1 -1
View File
@@ -28,7 +28,7 @@
{% if view_editable and session.user_role == 'admin' %}
<a href="/ansible/playbooks/edit/{{ view_source }}/{{ view_path }}" class="btn btn-sm">Edit</a>
<form method="post" action="/ansible/playbooks/delete" style="display:inline;"
onsubmit="return confirm('Delete {{ view_path }}?');">{{ csrf_field() }}
data-confirm="Delete {{ view_path }}?">{{ csrf_field() }}
<input type="hidden" name="source_name" value="{{ view_source }}">
<input type="hidden" name="playbook_path" value="{{ view_path }}">
<button type="submit" class="btn btn-sm btn-danger">Delete</button>
@@ -40,7 +40,7 @@
<a href="/ansible/inventory/groups/{{ grp.id }}" class="btn btn-sm btn-ghost">Edit</a>
<form method="post" action="/ansible/inventory/groups/{{ grp.id }}/delete" style="display:inline;">{{ csrf_field() }}
<button type="submit" class="btn btn-sm btn-danger"
onclick="return confirm('Delete group {{ grp.name }}?')">×</button>
data-confirm="Delete group {{ grp.name }}?">×</button>
</form>
</td>
</tr>
@@ -49,7 +49,7 @@
<a href="/ansible/inventory/targets/{{ tgt.id }}" class="btn btn-sm btn-ghost">Edit</a>
<form method="post" action="/ansible/inventory/targets/{{ tgt.id }}/delete" style="display:inline;">{{ csrf_field() }}
<button type="submit" class="btn btn-sm btn-danger"
onclick="return confirm('Delete target {{ tgt.name }}?')">×</button>
data-confirm="Delete target {{ tgt.name }}?">×</button>
</form>
</td>
</tr>
@@ -54,7 +54,7 @@
{% if editing %}
<form method="post" action="/ansible/playbooks/delete" style="margin-top:1rem;"
onsubmit="return confirm('Delete {{ playbook_path }}?');">{{ csrf_field() }}
data-confirm="Delete {{ playbook_path }}?">{{ csrf_field() }}
<input type="hidden" name="source_name" value="{{ source_name }}">
<input type="hidden" name="playbook_path" value="{{ playbook_path }}">
<button type="submit" class="btn btn-danger btn-sm">Delete playbook</button>
+1 -1
View File
@@ -7,7 +7,7 @@
<h1 class="page-title" style="margin-bottom:0;">Run Detail</h1>
<div style="margin-left:auto;display:flex;gap:0.5rem;">
{% if run.status.value in ("running", "queued") and session.user_role in ("operator", "admin") %}
<form method="post" action="/ansible/runs/{{ run.id }}/cancel" onsubmit="return confirm('Cancel this run?');">{{ csrf_field() }}
<form method="post" action="/ansible/runs/{{ run.id }}/cancel" data-confirm="Cancel this run?">{{ csrf_field() }}
<button type="submit" class="btn btn-sm btn-danger">Cancel run</button>
</form>
{% endif %}
+1 -1
View File
@@ -62,7 +62,7 @@
</form>
<a href="?edit={{ s.id }}#form" class="btn btn-sm btn-ghost">Edit</a>
<form method="post" action="/ansible/schedules/{{ s.id }}/delete" style="display:inline;"
onsubmit="return confirm('Delete schedule {{ s.name }}?');">{{ csrf_field() }}
data-confirm="Delete schedule {{ s.name }}?">{{ csrf_field() }}
<button class="btn btn-sm btn-danger" type="submit">Delete</button>
</form>
</td>
+7
View File
@@ -10,6 +10,13 @@
document.addEventListener('htmx:configRequest', function (ev) {
ev.detail.headers['X-CSRF-Token'] = document.querySelector('meta[name="csrf-token"]').content;
});
// A form (or its submit button) with data-confirm="…" asks before it
// submits. The prompt is attribute text read through dataset, never
// parsed as JavaScript, so a name inside it cannot run as script (#5099).
document.addEventListener('submit', function (ev) {
var ask = (ev.submitter && ev.submitter.dataset.confirm) || ev.target.dataset.confirm;
if (ask && !window.confirm(ask)) { ev.preventDefault(); ev.stopPropagation(); }
}, true);
</script>
<title>{% block title %}Steward{% endblock %}</title>
{# Every asset is served by Steward itself: it runs with no outbound network (rule 164). #}
+1 -1
View File
@@ -57,7 +57,7 @@
{% if my_dashboards | length > 1 %}
<form method="post" action="/dashboards/{{ dash.id }}/delete" style="margin:0;"
onsubmit="return confirm('Delete \'{{ dash.name }}\'?')">{{ csrf_field() }}
data-confirm="Delete '{{ dash.name }}'?">{{ csrf_field() }}
<button type="submit" class="btn btn-danger btn-sm">Delete</button>
</form>
{% endif %}
+1 -1
View File
@@ -32,7 +32,7 @@
</div>
</div>
<form method="post" action="/d/{{ dashboard.id }}/share/revoke/{{ token.id }}"
style="margin:0;" onsubmit="return confirm('Revoke this share link?')">{{ csrf_field() }}
style="margin:0;" data-confirm="Revoke this share link?">{{ csrf_field() }}
<button type="submit" class="btn btn-danger btn-sm">Revoke</button>
</form>
</div>
+2 -2
View File
@@ -16,7 +16,7 @@
<a href="/hosts/{{ host.id }}/edit" class="btn btn-ghost btn-sm">Edit</a>
{% if session.user_role == 'admin' %}
<form method="post" action="/hosts/{{ host.id }}/delete" style="margin:0;"
onsubmit="return confirm('Delete host {{ host.name }}? Monitors and history are removed.');">{{ csrf_field() }}
data-confirm="Delete host {{ host.name }}? Monitors and history are removed.">{{ csrf_field() }}
<button type="submit" class="btn btn-danger btn-sm">Delete</button>
</form>
{% endif %}
@@ -78,7 +78,7 @@
<div style="display:flex;gap:0.35rem;flex-shrink:0;">
<a href="/monitors/{{ m.id }}/edit" class="btn btn-sm btn-ghost" style="padding:0.2rem 0.5rem;font-size:0.72rem;">Edit</a>
<form method="post" action="/monitors/{{ m.id }}/delete" style="display:inline;"
onsubmit="return confirm('Delete monitor {{ m.name }}?');">{{ csrf_field() }}
data-confirm="Delete monitor {{ m.name }}?">{{ csrf_field() }}
<button type="submit" class="btn btn-sm" style="padding:0.2rem 0.5rem;font-size:0.72rem;color:var(--red);">✕</button>
</form>
</div>
+1 -1
View File
@@ -80,7 +80,7 @@
<a href="/hosts/{{ host.id }}/edit" class="btn btn-sm btn-ghost" style="margin-right:0.5rem;">Edit</a>
<form method="post" action="/hosts/{{ host.id }}/delete" style="display:inline;">{{ csrf_field() }}
<button type="submit" class="btn btn-sm btn-danger"
onclick="return confirm('Delete {{ host.name }}?')">Delete</button>
data-confirm="Delete {{ host.name }}?">Delete</button>
</form>
</td>
</tr>
+1 -1
View File
@@ -59,7 +59,7 @@
{{ "Pause" if m.enabled else "Resume" }}</button>
</form>
<form method="post" action="/monitors/{{ m.id }}/delete" style="display:inline;"
onsubmit="return confirm('Delete monitor {{ m.name }}?');">{{ csrf_field() }}
data-confirm="Delete monitor {{ m.name }}?">{{ csrf_field() }}
<button type="submit" class="btn btn-sm" style="padding:0.2rem 0.5rem;font-size:0.72rem;color:var(--red);">✕</button>
</form>
</div>
@@ -46,7 +46,7 @@
{% endif %}
<button class="btn btn-ghost btn-sm" style="font-size:0.78rem;"
onclick="toggleAnsibleEdit({{ idx }})">Edit</button>
onclick="toggleAnsibleEdit({{ idx|int }})">Edit</button>
<button class="btn btn-danger btn-sm" style="font-size:0.78rem;"
hx-post="/settings/ansible/sources/{{ idx }}/remove"
@@ -72,7 +72,7 @@
<div class="form-group" style="margin:0;">
<label style="font-size:0.8rem;">Type</label>
<select name="type" id="ansible-edit-type-{{ idx }}"
onchange="updateAnsibleEditFields({{ idx }})">
onchange="updateAnsibleEditFields({{ idx|int }})">
<option value="local" {% if src.type == 'local' %}selected{% endif %}>local</option>
<option value="git" {% if src.type == 'git' %}selected{% endif %}>git</option>
</select>
@@ -118,7 +118,7 @@
<div style="display:flex;gap:0.5rem;margin-top:0.75rem;">
<button type="submit" class="btn btn-sm">Save</button>
<button type="button" class="btn btn-ghost btn-sm"
onclick="toggleAnsibleEdit({{ idx }})">Cancel</button>
onclick="toggleAnsibleEdit({{ idx|int }})">Cancel</button>
</div>
</form>
</div>
@@ -18,7 +18,7 @@
</div>
<div style="display:flex;gap:0.4rem;flex-shrink:0;">
<button class="btn btn-ghost btn-sm" style="font-size:0.78rem;"
onclick="toggleRepoEdit({{ idx }})">Edit</button>
onclick="toggleRepoEdit({{ idx|int }})">Edit</button>
<button class="btn btn-danger btn-sm" style="font-size:0.78rem;"
hx-post="/settings/plugins/repos/{{ idx }}/remove"
hx-target="#plugin-repos"
@@ -47,7 +47,7 @@
<div style="display:flex;gap:0.5rem;margin-top:0.75rem;">
<button type="submit" class="btn btn-sm">Save</button>
<button type="button" class="btn btn-ghost btn-sm"
onclick="toggleRepoEdit({{ idx }})">Cancel</button>
onclick="toggleRepoEdit({{ idx|int }})">Cancel</button>
</div>
</form>
</div>
+1 -1
View File
@@ -39,7 +39,7 @@
<span style="color:var(--text-muted);font-size:0.78rem;">Click to select — add to a host's <code>authorized_keys</code> to authorize Steward manually.</span>
</div>
<form method="post" action="/settings/ansible/generate-key"
onsubmit="return confirm('Regenerate the managed key? Already-provisioned hosts will reject Steward until you re-provision them.');">{{ csrf_field() }}
data-confirm="Regenerate the managed key? Already-provisioned hosts will reject Steward until you re-provision them.">{{ csrf_field() }}
<button type="submit" class="btn btn-ghost btn-sm">Regenerate key</button>
</form>
{% else %}
+2 -2
View File
@@ -54,7 +54,7 @@
<div class="section-title">Monitoring capabilities</div>
<form method="post" action="/settings/plugins/restart/"
hx-post="/settings/plugins/restart/" hx-target="#restart-banner" hx-swap="outerHTML"
onsubmit="return confirm('Restart the app now? This will briefly interrupt all monitoring.')"
data-confirm="Restart the app now? This will briefly interrupt all monitoring."
style="margin:0;">{{ csrf_field() }}
<button type="submit" class="btn btn-ghost btn-sm" style="font-size:0.78rem;">Restart App</button>
</form>
@@ -134,7 +134,7 @@
</div>
{% if orphan.removable %}
<form method="post" action="/settings/plugins/orphans/{{ orphan.name }}/remove/"
onsubmit="return confirm('Remove stored settings for &quot;{{ orphan.name }}&quot;? Its saved configuration, including any credentials, will be discarded. This cannot be undone.');"
data-confirm="Remove stored settings for &quot;{{ orphan.name }}&quot;? Its saved configuration, including any credentials, will be discarded. This cannot be undone."
style="margin:0;flex-shrink:0;">{{ csrf_field() }}
<button type="submit" class="btn btn-danger btn-sm" style="font-size:0.78rem;">Remove</button>
</form>