~/talk

30 Tips for Secure JavaScript

Talkat NDC Oslo 2025 · 2025-05-19..05-23· [javascript, security]
slides:none on file

Thirty concrete JavaScript rules: use a framework that outputs safe markup, avoid inline scripts and dangerous APIs like eval, innerHTML, document.write and with, prefer textContent/createElement and encodeURIComponent, and enforce CSP and subresource integrity (SRI) for third‑party scripts. Defend against XSS, DOM XSS and prototype injection by freezing prototypes or using Map, check for HTTP parameter pollution (use HPP middleware), run static analysis and dependency scans (npm audit, retire.js, NodeJS scan, DOMPurify), and enable encodeURIComponent and strict mode.

AI-written summary · about

  1. 0:00Introduction
  2. 1:28Secure JavaScript matters
  3. 6:27Frameworks for encoded code
  4. 7:31Secure development lifecycle
  5. 8:55Cross-site scripting risks
  6. 12:45Avoid inline scripting
  7. 13:48User input as data
  8. 14:50Use textContent over innerHTML
  9. 15:34encodeURIComponent vs escape
  10. 16:38Avoid document.write
  11. 17:39Replace unescapeHTML
  12. 18:22decodeURIComponent vs decodeURI
  13. 19:04URL encode for CSS
  14. 20:09Double-encode execution context
  15. 20:30Specify text content
  16. 21:55Safe setAttribute
  17. 23:59Explicit content type headers
  18. 24:22CSS for variables
  19. 25:04Strict mode for security
  20. 26:07HTTP parameter pollution
  21. 27:53Sanitize with DOMPurify
  22. 28:36Script integrity with SRI
  23. 29:18Minify sensitive code
  24. 30:00Prevent cross-site request forgery with tokens
  25. 31:45Linters and static analysis
  26. 33:31Avoid eval
  27. 34:15Never use the with statement in JavaScript
  28. 34:57Avoid function constructors
  29. 36:45Caution with setTimeout
  30. 37:53No untrusted HTML methods
  31. 38:35Prevent prototype injection
  32. 39:39Same-origin policy
  33. 40:45Backend input validation
  34. 42:12Prefer private variables
  35. 42:34Free tools for security
  36. 43:58Conclusion and key takeaways
  37. 44:20Free secure coding resources
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.