Commit Graph

21 Commits

Author SHA1 Message Date
Thomas Durieux e4ffd74068 Security hardening + gist UI fixes (#731)
* security: harden against XSS, ReDoS, path traversal, and injection

Defensive fixes across the server, storage, and viewer:

- XSS (CWE-79): sanitise rendered notebooks with DOMPurify, escape file
  names interpolated into AngularJS expressions (escapeNgString), set
  Mermaid securityLevel to 'strict', and stop urlRel2abs from returning
  javascript:/vbscript:/data:text/html URLs.
- Path traversal / zip-slip (CWE-22/23/24): validate URL-derived path
  components before they reach the storage layer (file/webview routes +
  StorageBase.assertSafePath) and sanitise zip entry names on extract for
  both the filesystem and S3 backends.
- ReDoS (CWE-1333): escape anonymization terms with catastrophic
  backtracking shapes to literals instead of compiling them as regexes.
- Secret hardening (CWE-798): require SESSION_SECRET / OAuth creds / DB
  password in production, random dev SESSION_SECRET fallback.
- Rate-limit spoofing (CWE-290): derive request.ip via trust-proxy hop
  count instead of the client-settable cf-connecting-ip header.
- NoSQL injection (CWE-943): allow only plain field paths as admin sort keys.
- Reject malformed streamer requests missing required string fields.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* fix(ui): make gists reachable/visible and clarify the ZIP button

- Gist & PR routes now accept a trailing slash (/gist/:id/:path*?), so the
  dashboard links (which end in "/") resolve to the gist/PR page instead of
  falling through to the 404 route (#725).
- Gist viewer picks the default tab after content loads, defaulting to
  "files" when files exist; previously the ng-init ran before the async
  load and a files-only gist rendered blank under the hidden comments tab.
- Explorer toolbar: relabel ZIP to "Full repo ZIP" with a tooltip, and add
  tooltips to Raw/Download clarifying they apply to the current file (#721).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* fix: report SAML-enforced orgs clearly instead of "token expired"

When a repo's organization enforces SAML SSO, GitHub returns a 403 whose
message differs from the OAuth-App-restriction case. That 403 fell through
to the generic handler and surfaced as "token_expired", pushing users to
re-login when the real fix is authorizing their token for the org. Detect
the "SAML enforcement" message and raise a dedicated, actionable error
instead (#379, #550).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* security: catch nested quantified groups in ReDoS guard and backslash path traversal

- hasCatastrophicBacktracking now scans across nested parens ([\s\S]*?)
  so shapes like ((a+))+ are detected; comment reframed as a heuristic
  backstop rather than a proof.
- file route path-traversal check now rejects backslash separators and a
  leading backslash, covering Windows-style "..\" payloads (CWE-22/25).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* chore(dev): track dev-proxy script, ignore .DS_Store and .claude/

scripts/dev-proxy.js is referenced by the "dev:ui" npm script but was
never committed, breaking the command on a fresh clone. Add it and
ignore local-only macOS/Claude Code files.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-18 13:50:55 +02:00
tdurieux 67cb2538b1 fix old github download repos 2026-05-06 19:37:16 +03:00
tdurieux f0bc53f093 feat: gist & co-authors 2026-05-04 13:10:44 +02:00
tdurieux db2ac5307d fix admin 2026-05-03 22:29:01 +02:00
tdurieux d138d487f2 fix: don't drop a path segment when resolving "./" relative URLs
urlRel2abs() prepended an extra "." when it saw "./X", turning the
relative path into "../X" and silently moving up a directory. As a
result, raw HTML <img src="./imgs/run.png"> inside a README rendered
under /r/<repo>/<file> resolved to /r/<repo>/imgs/... instead of
/r/<repo>/<dir>/imgs/..., so the image 404'd. Markdown image syntax
went through marked-base-url and was unaffected.

Strip the leading "./" instead so the relative path concatenates
cleanly with baseUrl.

Fixes #346.
2026-05-03 20:01:33 +02:00
tdurieux 9feeab1055 fix: render heading IDs so anchor links resolve
marked v12 dropped the headerIds option, so headings rendered with no
id attributes and links like [Releases](#releases-and-contributing)
silently failed to scroll. Add a heading renderer that emits a
GitHub-style slug id, with a numeric suffix for duplicates within a
document.

Fixes #390.
2026-05-03 19:44:18 +02:00
tdurieux a5f66d6844 multiple fixes 2026-05-03 15:30:54 +02:00
Thomas Durieux 2621dfd7fc (feat): added mermaid rendering support in markdown (#676) 2026-04-15 09:56:35 +02:00
Thomas Durieux 812f8b6314 Sanitize markdown HTML output with DOMPurify to prevent XSS (#658) 2026-04-15 04:22:38 +02:00
tdurieux b4ff27f560 fix: improve katex support 2024-04-11 21:38:42 +01:00
tdurieux f30110c567 fix: improve link rendering 2024-04-05 11:04:29 +01:00
tdurieux 7ed973ccfc fix: fix code rendering 2024-04-05 10:17:47 +01:00
tdurieux 22a28a913d perf: improve page loading time 2024-04-05 01:02:41 +01:00
tdurieux f5ec343a9c fix(#263): render math expression correctly 2024-04-04 18:08:03 +01:00
tdurieux dde7fa2d72 feat(#204): display videos in md 2023-05-02 18:21:47 +02:00
tdurieux 8ac3a66a30 feat(#169): add emoji support for markdown 2023-04-21 13:23:34 +02:00
tdurieux 3627096e63 feat(#148): add support for Math expression 2023-04-21 12:29:19 +02:00
Thomas Durieux 73e46f926f feat: add support for pull requests (#156) 2023-01-22 12:54:14 +01:00
tdurieux 8daee004b1 fix: fix relative to abs url 2021-09-09 00:32:03 +02:00
tdurieux 46c27036b8 feat: add support for .git url 2021-09-07 07:13:08 +02:00
tdurieux 80678c51a8 refactor app.js 2021-08-24 12:13:52 +02:00