Skip to content

feat: improve remote access UI and functionality - #35

Merged
linletian merged 25 commits into
developfrom
feature/improve-remote-access
May 24, 2026
Merged

feat: improve remote access UI and functionality#35
linletian merged 25 commits into
developfrom
feature/improve-remote-access

Conversation

@linletian

Copy link
Copy Markdown
Owner

No description provided.

linletian added 25 commits May 22, 2026 13:29
- Architecture: claimer pattern (TCP port as distributed lock), reverse proxy + loopback bypass
- Security: CSP with hash-based script/style whitelist, CSRF double-submit cookie, HttpOnly token cookie, rate limiting
- Features: global auth token config, dashboard HTML, tailscale serve auto-management
- Config: auth.json (atomic write, Load() distinguishes file-not-found vs JSON corruption)
- Auth: POST /api/auth returns 400 when token not configured; /api/logout requires CSRF token
- Cookie: mw_token 24h sliding expiration via Set-Cookie on each authenticated request
- Edge cases: Portal SPOF 10-15s failover window, Serve unexpected exit with Warn log
- 11 tasks with dependency graph and sub-task decomposition
- Each sub-task references plan document section and line numbers
- Includes acceptance criteria and cross-task concerns appendix
- Parallel execution: Task 1+3 first, then Task 5 splits into 6/7/8
- Task 0: Update README.md and README.zh-CN.md before any code changes
- Covers: Remote Access section rewrite, Features update, CLI examples, Portal output
- Docs-first principle: ensures team alignment on feature scope before implementation
Align with 文档优先 principle: project documentation updates before code
- 0.6: PRD.md — tagline, security section, implementation state, acceptance criteria
- 0.7: ARCHITECTURE.md — overview, new packages (config/portal), data persistence,
        security model (dual-layer auth), new CLI flags section
- 0.8: API.md — auth header (mw_token Cookie), new Portal endpoints chapter
        (7 endpoints with schemas, CSRF annotations, reverse proxy docs)
- README.md/zh-CN.md: expand Remote Access section (global token,
  Portal dashboard, Tailscale HTTPS, network security table),
  add CLI examples (mw config, --portal-port), add Portal output
- PRD.md: add Portal Dashboard as key feature, expand security
  section, update implementation status, add MVP acceptance criteria
- ARCHITECTURE.md: add Portal/dashboard overview, new internal/config
  and internal/portal packages, auth.json/portal registry/server.json,
  dual-layer auth architecture, CLI flags chapter
- API.md: add mw_token Cookie auth source, new Portal Dashboard
  endpoints section (7 endpoints with schemas, CSRF, reverse proxy)
- 添加 loopback 请求跳过校验(isLoopbackRequest)
- Token 提取优先级:Authorization Bearer → ?token= → mw_token Cookie
- 提取 extractAuthToken() 函数,使用 r.Cookie() 精确匹配
- 添加单元测试覆盖 loopback 放行、Cookie token、速率限制

[Task 4] §2 Auth中间件改造 (行118-145), §7 Cookie认证 (行446-470)
- Strip /s/<repo-hash>/ prefix before forwarding to target instance
- Validate repo-hash format (lowercase hex only) to prevent path traversal
- Set proxy.ErrorLog to logWriter for 502 errors with repo_hash context
- Add integration tests: auth required (401), invalid hash (400), not found (502), sliding cookie, WebSocket bidirectional message exchange
- WebSocket test: waitForPort retry loop instead of time.Sleep
- wsWriteFrame: fix mask key offset and extended payload length field
- Add gen.go (//go:build ignore) that reads dashboard.html and generates
  csp_gen.go with SHA256+base64 hashes for inline <script> and <style> blocks
- Add csp_gen.go with CSPHashes [][2]string exported variable
- Replace placeholder cspHashes with generated CSPHashes in portal.go
- Add //go:generate go run gen.go directive for re-generation
- Add CSP hash verification tests supporting multiple same-type blocks:
  TestCSPHashes_MatchesDashboardHTML (slice-based comparison)
  TestCSPHashes_NotEmpty
  TestCSPHashes_NoDuplicateTypes
- Fix duplicate style block in gen.go styles loop
- Fix test to strip quotes from CSPHashes entries for comparison
- Start Portal in Server.Start() after listener init, with graceful degradation on failure
- Add Shutdown() method for clean teardown: stop Portal, shutdown HTTP server, close listener
- Replace select{} with signal handling in CLI (SIGINT/SIGTERM → Shutdown)
- Add TailscaleDNSName() helper to display Tailscale URL at startup
…code host to 0.0.0.0 ; add tailscaleServeOK guard to suppress stale-check log spam
…dback

- Replace hardcoded port 12345 with s.cfg.PortalPort in app.go
- Add PortalPort > 0 guard before opening browser
- Show 'Portal is disabled' when portalPort is 0 instead of misleading 'Opening browser...' message
- Add color CSS property to button in index.html
@linletian
linletian merged commit ad6cd71 into develop May 24, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant