Files
lucioandClaude Fable 5 a9da249760 Remove unsafe-inline from script-src CSP
Move every inline <script> block and on*= attribute out of the templates
into per-page files under static/js/, then tighten the CSP to
script-src 'self' so injected inline scripts are actually blocked.

- static/js/base.js: QR modal, form[data-confirm] submit confirmation,
  and a shared glimmerCopy clipboard helper (loaded by base.html)
- One script per template: index, bin_view, bin_token, admin,
  admin_edit, admin_bin, admin_bin_edit, admin_uploads
- Template data now flows through data-* attributes (data-slug,
  data-filename, data-max-mb, ...) instead of being interpolated
  into JS; confirm() prompts use data-confirm
- style-src keeps unsafe-inline for the style="" attributes
- Update CLAUDE.md / AGENTS.md with the no-inline-JS rule

Verified in a live browser session: shorten flow, login, QR modal,
paste editor (token radios, name preview), paste cards (preview
dialog, expand/close), public paste view, token prompt redirect, and
uploads page - no console errors or CSP violations.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-06-09 20:14:30 -07:00

57 lines
2.3 KiB
HTML

{{define "title"}}Glimmer{{end}}
{{define "content"}}
<div style="max-width: 640px; margin: 1.5rem auto 0;">
<div class="card" style="text-align: center; padding: 2.5rem 2rem;">
<div class="brand" style="justify-content: center; margin-bottom: 1rem;">
<div class="brand-logo">G</div>
<span class="brand-name">Glimmer</span>
</div>
<h1 style="font-size: 1.75rem; margin-bottom: 0.5rem;">Shorten a URL</h1>
<p class="text-muted" style="margin-bottom: 2rem;">Paste a long URL and get a short link.</p>
{{if .Error}}
<div class="alert alert-error">{{.Error}}</div>
{{end}}
{{if .ShortURL}}
<div class="alert alert-success" style="text-align:left;">
<div style="flex-grow: 1;">
<strong>Your short link is ready.</strong>
<p class="text-muted" style="font-size: 0.85rem; margin-top: 0.25rem; word-break: break-all;">{{.OriginalURL}}</p>
</div>
</div>
<div class="result-box">
<code id="short-url">{{.ShortURL}}</code>
<button id="copy-short-url" class="btn btn-secondary btn-sm">Copy</button>
</div>
{{if .QRSVG}}
<div class="qr-display">{{.QRSVG}}</div>
{{end}}
{{end}}
<form method="post" action="/shorten" id="shorten-form" style="text-align: left;">
<input type="hidden" name="csrf_token" value="{{.CSRFToken}}">
<div class="form-group">
<label for="url" class="form-label">URL to shorten</label>
<input type="text" inputmode="url" id="url" name="url" placeholder="https://example.com/very/long/url" required>
</div>
{{if .LoggedIn}}
<div class="form-group">
<label for="slug" class="form-label">Custom slug <small class="text-muted">(optional)</small></label>
<input type="text" id="slug" name="slug" placeholder="my-link" pattern="[a-zA-Z0-9_-]+" title="Letters, numbers, hyphens, underscores only">
<small class="form-help">Leave blank to auto-generate a 3-character slug.</small>
</div>
{{end}}
<button type="submit" class="btn btn-primary btn-lg btn-block">Shorten</button>
</form>
</div>
</div>
<script src="/static/js/index.js"></script>
{{end}}