diff --git a/.cursor/skills/marqdo-release/reference.md b/.cursor/skills/marqdo-release/reference.md index 1b7c3b7..4306d3b 100644 --- a/.cursor/skills/marqdo-release/reference.md +++ b/.cursor/skills/marqdo-release/reference.md @@ -236,7 +236,25 @@ git push https://proxy.cflmy.top/github.com/cflmy/marqdo.git vVER Short GETs via the proxy often work; **long `git push` may still time out**. If push hangs or drops, skip Clash retries and go to **HK SSH jump** below. -`gh` against `api.github.com` may still need a direct path or HK jump (the reverse proxy is for `github.com` git, not always the API). +`gh` / Release API can use the same path reverse-proxy: + +| Path prefix | Upstream | +|-------------|----------| +| `/github.com/` | `https://github.com/` | +| `/api.github.com/` | `https://api.github.com/` | +| `/uploads.github.com/` | `https://uploads.github.com/` (Release asset POST; OpenResty on HK) | + +```bash +# Upload a Release asset through proxy.cflmy.top (Content-Type: application/octet-stream) +curl -X POST \ + -H "Authorization: Bearer $GH_TOKEN" \ + -H "Accept: application/vnd.github+json" \ + -H "Content-Type: application/octet-stream" \ + --data-binary @dist/FILE.zip \ + "https://proxy.cflmy.top/uploads.github.com/repos/cflmy/marqdo/releases/RELEASE_ID/assets?name=FILE.zip" +``` + +Do **not** rewrite `Host: uploads.github.com` against `proxy.cflmy.top` without the `/uploads.github.com/` path prefix — that returns 404. ### Diagnose diff --git a/plugins/web/internal/httpx/listen.go b/plugins/web/internal/httpx/listen.go index 6b5522c..9f9638a 100644 --- a/plugins/web/internal/httpx/listen.go +++ b/plugins/web/internal/httpx/listen.go @@ -310,15 +310,37 @@ func (st *state) preparePage(page map[string]any, r *http.Request) map[string]an return p } +// attachCSRF stamps page._csrf and returns Set-Cookie when auth is enabled so +// custom login/register pages (that own GET /login) still expose a token for JS. +func (st *state) attachCSRF(page map[string]any, r *http.Request) *string { + if page == nil || r == nil { + return nil + } + if st.auth.users == nil && !st.auth.rbac { + return nil + } + _, csrf, setCookie := resolveSession(r) + if csrf != "" { + page["_csrf"] = csrf + } + return setCookie +} + func (st *state) writePage(w http.ResponseWriter, r *http.Request, page map[string]any) { - html := render.RenderPage(st.preparePage(page, r), st.dbURL, "") + p := st.preparePage(page, r) + setCookie := st.attachCSRF(p, r) + html := render.RenderPage(p, st.dbURL, "") w.Header().Set("Content-Type", "text/html; charset=utf-8") + appendSetCookie(w, setCookie) _, _ = io.WriteString(w, html) } func (st *state) writePart(w http.ResponseWriter, r *http.Request, page map[string]any, id string) { - html := render.RenderPage(st.preparePage(page, r), st.dbURL, id) + p := st.preparePage(page, r) + setCookie := st.attachCSRF(p, r) + html := render.RenderPage(p, st.dbURL, id) w.Header().Set("Content-Type", "text/html; charset=utf-8") + appendSetCookie(w, setCookie) _, _ = io.WriteString(w, html) } diff --git a/plugins/web/internal/render/render.go b/plugins/web/internal/render/render.go index 12006d6..84e3adc 100644 --- a/plugins/web/internal/render/render.go +++ b/plugins/web/internal/render/render.go @@ -731,6 +731,9 @@ func headHTML(page map[string]any, defaultTitle string) string { } var s strings.Builder s.WriteString(fmt.Sprintf("%s", esc(pageTitle))) + if csrf, ok := page["_csrf"].(string); ok && strings.TrimSpace(csrf) != "" { + s.WriteString(fmt.Sprintf(``, esc(strings.TrimSpace(csrf)))) + } if meta, ok := page["meta"].(map[string]any); ok { for k, v := range meta { if k == "title" {