Claude commited on
Commit
3964d02
·
1 Parent(s): b12bb48

Fix bugs and security issues from post-a11y scan

Browse files

Bugs:
- _doc_styles.html: move @import to first line (was after :root, silently
ignored by browsers — Merriweather/Source Sans 3 never loaded)
- index.html: merge duplicate .vgm-scene-thumb rule; position:relative
now lives in the main block so the ::after overlay always has a
positioning context
- index.html: add sandbox attribute to review iframe
(allow-scripts allow-same-origin allow-downloads allow-forms)
- index.html: reduce non-review format resetForRetry delay 2500→1500ms;
focus is now returned sooner after download
- review.html: makeKeyTermRow aria-label updates live as user types the
term, matching the Jinja server-rendered row behaviour

Security:
- main.py: add HTTP security header middleware (X-Content-Type-Options,
X-Frame-Options, Referrer-Policy, Content-Security-Policy)
- llm_extract.py: scrub API key from exception messages before logging

https://claude.ai/code/session_01EGBMur51izertyiu7msWPQ

app/main.py CHANGED
@@ -42,6 +42,25 @@ templates = Jinja2Templates(directory=str(BASE_DIR / "templates"))
42
  app = FastAPI(title="VideoGuideMaker")
43
  app.mount("/static", StaticFiles(directory=str(BASE_DIR / "static")), name="static")
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  VIDEO_SUFFIXES = {".mp4", ".mov", ".mkv", ".webm", ".m4v", ".avi"}
46
  TRANSCRIPT_SUFFIXES = {".vtt", ".srt"}
47
  ALLOWED_FORMATS = {"review", "single", "zip"}
 
42
  app = FastAPI(title="VideoGuideMaker")
43
  app.mount("/static", StaticFiles(directory=str(BASE_DIR / "static")), name="static")
44
 
45
+
46
+ @app.middleware("http")
47
+ async def _security_headers(request: Request, call_next):
48
+ response = await call_next(request)
49
+ response.headers["X-Content-Type-Options"] = "nosniff"
50
+ response.headers["X-Frame-Options"] = "SAMEORIGIN"
51
+ response.headers["Referrer-Policy"] = "strict-origin-when-cross-origin"
52
+ # Allow inline scripts (needed for our templates) and CDN resources for MathJax/fonts.
53
+ response.headers["Content-Security-Policy"] = (
54
+ "default-src 'self'; "
55
+ "script-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net; "
56
+ "style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; "
57
+ "font-src https://fonts.gstatic.com; "
58
+ "img-src 'self' data: blob:; "
59
+ "media-src 'self' data: blob:; "
60
+ "connect-src 'self';"
61
+ )
62
+ return response
63
+
64
  VIDEO_SUFFIXES = {".mp4", ".mov", ".mkv", ".webm", ".m4v", ".avi"}
65
  TRANSCRIPT_SUFFIXES = {".vtt", ".srt"}
66
  ALLOWED_FORMATS = {"review", "single", "zip"}
app/pipeline/llm_extract.py CHANGED
@@ -287,7 +287,9 @@ def extract_one(
287
  ],
288
  )
289
  except Exception as exc: # pragma: no cover (network-dependent)
290
- log.warning("LLM extraction failed for %s: %s", image_path.name, exc)
 
 
291
  return _EMPTY
292
 
293
 
 
287
  ],
288
  )
289
  except Exception as exc: # pragma: no cover (network-dependent)
290
+ # Scrub the API key from the exception message before logging (S4).
291
+ safe_msg = str(exc).replace(resolved, "***") if resolved else str(exc)
292
+ log.warning("LLM extraction failed for %s: %s", image_path.name, safe_msg)
293
  return _EMPTY
294
 
295
 
app/templates/_doc_styles.html CHANGED
@@ -1,4 +1,5 @@
1
  <style>
 
2
  /* ========== CSS CUSTOM PROPERTIES ========== */
3
  :root {
4
  --color-bg: #FFFFFF;
@@ -31,8 +32,6 @@
31
  --radius: 6px;
32
  }
33
 
34
- @import url('https://fonts.googleapis.com/css2?family=Merriweather:wght@400;700&family=Source+Sans+3:wght@400;600;700&family=JetBrains+Mono:wght@400&display=swap');
35
-
36
  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
37
 
38
  html {
 
1
  <style>
2
+ @import url('https://fonts.googleapis.com/css2?family=Merriweather:wght@400;700&family=Source+Sans+3:wght@400;600;700&family=JetBrains+Mono:wght@400&display=swap');
3
  /* ========== CSS CUSTOM PROPERTIES ========== */
4
  :root {
5
  --color-bg: #FFFFFF;
 
32
  --radius: 6px;
33
  }
34
 
 
 
35
  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
36
 
37
  html {
app/templates/index.html CHANGED
@@ -395,6 +395,7 @@
395
  .vgm-scene-strip::-webkit-scrollbar-track { background: transparent; }
396
  .vgm-scene-strip::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 3px; }
397
  .vgm-scene-thumb {
 
398
  flex: 0 0 auto;
399
  width: 220px;
400
  display: flex;
@@ -430,7 +431,6 @@
430
  border-radius: inherit;
431
  pointer-events: none;
432
  }
433
- .vgm-scene-thumb { position: relative; }
434
  .vgm-preview-bar {
435
  height: 3px;
436
  border-radius: 2px;
@@ -922,7 +922,8 @@
922
  <button type="button" class="vgm-review__open" title="Open in a new tab">Open in new tab</button>
923
  <button type="button" class="vgm-review__back"><span aria-hidden="true">←</span> Back to upload</button>
924
  </div>
925
- <iframe class="vgm-review__frame" title="Study guide editor"></iframe>
 
926
  </div>
927
 
928
  <script>
@@ -1344,7 +1345,7 @@
1344
  a.click();
1345
  a.remove();
1346
  setProgress('running', 100, 'render', 'Downloaded. Generate another?');
1347
- setTimeout(resetForRetry, 2500);
1348
  }
1349
  } else if (data.type === 'error') {
1350
  es.close();
 
395
  .vgm-scene-strip::-webkit-scrollbar-track { background: transparent; }
396
  .vgm-scene-strip::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 3px; }
397
  .vgm-scene-thumb {
398
+ position: relative; /* needed for ::after deselected overlay */
399
  flex: 0 0 auto;
400
  width: 220px;
401
  display: flex;
 
431
  border-radius: inherit;
432
  pointer-events: none;
433
  }
 
434
  .vgm-preview-bar {
435
  height: 3px;
436
  border-radius: 2px;
 
922
  <button type="button" class="vgm-review__open" title="Open in a new tab">Open in new tab</button>
923
  <button type="button" class="vgm-review__back"><span aria-hidden="true">←</span> Back to upload</button>
924
  </div>
925
+ <iframe class="vgm-review__frame" title="Study guide editor"
926
+ sandbox="allow-scripts allow-same-origin allow-downloads allow-forms"></iframe>
927
  </div>
928
 
929
  <script>
 
1345
  a.click();
1346
  a.remove();
1347
  setProgress('running', 100, 'render', 'Downloaded. Generate another?');
1348
+ setTimeout(resetForRetry, 1500);
1349
  }
1350
  } else if (data.type === 'error') {
1351
  es.close();
app/templates/review.html CHANGED
@@ -515,6 +515,12 @@
515
  row.innerHTML = '<input type="text" data-list-field="term" placeholder="Term" aria-label="Term">'
516
  + '<input type="text" data-list-field="definition" placeholder="Definition" aria-label="Definition">'
517
  + '<button type="button" class="vgm-row-remove" data-action="remove-row" aria-label="Remove key term">×</button>';
 
 
 
 
 
 
518
  if (value) {
519
  row.querySelector('[data-list-field="term"]').value = value.term || '';
520
  row.querySelector('[data-list-field="definition"]').value = value.definition || '';
 
515
  row.innerHTML = '<input type="text" data-list-field="term" placeholder="Term" aria-label="Term">'
516
  + '<input type="text" data-list-field="definition" placeholder="Definition" aria-label="Definition">'
517
  + '<button type="button" class="vgm-row-remove" data-action="remove-row" aria-label="Remove key term">×</button>';
518
+ // Update aria-label with term name once user types it
519
+ const termInput = row.querySelector('[data-list-field="term"]');
520
+ const removeBtn = row.querySelector('[data-action="remove-row"]');
521
+ termInput.addEventListener('input', () => {
522
+ removeBtn.setAttribute('aria-label', `Remove key term${termInput.value ? ' ' + termInput.value : ''}`);
523
+ });
524
  if (value) {
525
  row.querySelector('[data-list-field="term"]').value = value.term || '';
526
  row.querySelector('[data-list-field="definition"]').value = value.definition || '';