Skip to content

Security: langming58-hash/studyhub-local

Security

SECURITY.md

Security Policy

Reporting

Please report security issues privately to the repository maintainer. Do not include API keys, course files, cookies, OAuth tokens, session values, or personal study data in public issues.

Local-First Model

StudyHub Local is designed to run on 127.0.0.1, localhost, or ::1 only. The server refuses non-loopback bind hosts and rejects non-loopback HTTP Host headers on all supported methods. Do not expose a live StudyHub Local instance through ngrok, Cloudflare Tunnel, port forwarding, reverse proxies, or public hosting without a separate security review.

API Keys

OpenAI keys must remain server-side in .env.local or an equivalent private environment. They must not be stored in frontend code, GitHub, SQLite databases, screenshots, logs, or issue attachments.

OpenAI/vector indexing is opt-in. When enabled, selected indexed file content and safe academic metadata are sent to OpenAI for retrieval. Local absolute paths, local database paths, cache paths, and provider IDs should not be returned through public-facing API or MCP responses.

File Access

The scanner, upload flow, and normal local-material reads are constrained to the configured STUDY_LIBRARY_PATH; exact external references remain explicit exceptions. Canvas-retained reads add one narrow exception: an explicit canvas_remote row must exactly match its persisted path inside the profile-owned Canvas remote-content root. No arbitrary data/cache path is trusted. Path traversal and arbitrary filesystem reads are not allowed. Upload targets are built from validated server-side components and copied by temporary file plus atomic rename.

Study-library files are treated as untrusted content. Active browser formats such as HTML, XHTML, XML, and SVG are not rendered as same-origin active documents in preview; they are shown as escaped plaintext with MIME sniffing disabled.

Browser/API Boundary

Mutating HTTP routes require a per-process CSRF token and exact same-origin headers: HTTP scheme, Host hostname literal, and effective port must match. The frontend obtains that token from a local-only session bootstrap endpoint, not from the general health payload. API responses include security headers, deny framing, disable referrer leakage, and use Cache-Control: no-store for API/MCP responses.

MCP Boundary

MCP is read-only. It may list/search/fetch indexed study-library content by safe file IDs, but must not expose local absolute paths, local cache paths, database paths, OpenAI provider file IDs, vector-store IDs, write tools, delete tools, shell execution, app-opening actions, or indexing/upload actions.

Credential Boundary

Native credentials are not exposed through frontend JavaScript, localhost HTTP, MCP, diagnostics, browser storage, SQLite, logs, or Tauri raw-secret commands. The internal credential handoff boundary is typed, child-authorized, restart-invalidated, and covered with synthetic participants. StudyHub supports a development-only manual Canvas connection enrollment boundary for local developer testing; Production manual-token enrollment fails closed before any credential-store access. Production Canvas connection is OAuth-only, gated on an institutionally provisioned OAuth client, with the client secret, refresh token, and access token held only inside the native credential store.

The macOS/Unix desktop shell additionally creates a private inherited stream between the Tauri parent and the exact spawned Python backend child. Only non-secret bootstrap metadata is placed in the child environment. Credentials are not passed through argv, environment variables, localhost TCP, socket paths, temporary files, logs, diagnostics, SQLite, WebView JavaScript, or MCP. The implemented protocol supports only a narrow internal canvas_default connection-record operation. If a valid origin-bound connection record exists, the Python backend can use it for read-only Canvas identity validation and course discovery and explicit selected-file acquisition. The browser may submit only selected CourseOffering intent, expected plan revisions, and StudyHub-generated remote-file stable IDs. StudyHub re-reads authoritative metadata before persistence. Canvas API bearer credentials are never attached to ephemeral file URLs or redirects. Downloads are HTTPS-only, reject unsafe literal network targets, enforce redirect and 256 MiB streaming limits, and remain inside profile-owned storage. Hostname DNS address pinning is not yet implemented and is documented as a residual SSRF limitation. Production Canvas OAuth uses the institution's authorization flow: the native parent generates a one-shot, expiring, cryptographically random state, opens the institution authorization URL in the system browser, validates the returned authorization code, exchanges it over HTTPS bound to the exact configured Canvas origin, and validates the connection with /api/v1/users/self before persisting an OAuth credential record. The native parent owns token refresh with a bounded safety margin and serialized refresh, and the Python backend continues to receive only an origin-bound access credential through canvas_default. Canvas passwords, generic self-service Developer Key provisioning, background sync, remote deletion, and Canvas writes remain not implemented.

Academic Materials

Do not upload private or copyrighted course content to issues, pull requests, tests, or demo fixtures.

There aren't any published security advisories