Keep the storefront CMS usable when the platform GitHub token expires - #819
Open
vitorrgg wants to merge 6 commits into
Open
Keep the storefront CMS usable when the platform GitHub token expires#819vitorrgg wants to merge 6 commits into
vitorrgg wants to merge 6 commits into
Conversation
Decap CMS could never actually work through this proxy, it only lacked
consumers to surface the defects:
- Answer `/user` with the authenticated store user, so the CMS editor is
identified as the commit author instead of the token owner
- Report `permissions.push` on the bare repository endpoint: write access is
granted by `edit_storefront` on store auth, not by the `GITHUB_TOKEN` owner
- Accept the `token` auth scheme Decap sends (a fixed 7 char offset for
"Bearer " was dropping one character of the store access token)
- Keep the query string when proxying (`?ref={branch}` was lost, so reads
always resolved against the default branch)
- Send the actual byte count on Content-Length (default commit messages
contain curly quotes, so requests with them were rejected by fetch)
- Forward `/search/**`, used by Decap for entry notes
- Serve the proxy before and regardless of catalog fetching, so the CMS does
not go down nor wait when the products API is slow or failing
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The GitHub proxy rewrite required a `{git,contents,issues,branches,pulls,
commits}` segment, so `/_api/user`, `/_api/repos/{owner}/{repo}`, bare
`/pulls` (Decap lists and creates PRs there) and `/_api/search/**` fell
through to SSR. Replaced by `/_api/repos/**` plus the auth endpoints.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…xpires The /admin page trusted the `gh_token` returned by the platform without ever checking it, and had no fallback. An expired credential surfaced as Decap's misleading "Repo not found" error, with no way to edit content until someone reissued the token on the platform side. - Probe the credential on `GET /user` before trusting it - Fall back to the store own GitHub proxy (`/_api`, `feeds` function) with the SSO token, probing the repo endpoint since it checks store auth, `GITHUB_TOKEN` and repository access at once - Show an explicit message when no backend can authenticate, instead of letting Decap blame the repository Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…ints Review follow-ups on the proxy: - Pin proxied requests to `GITHUB_REPO` and allowlist CMS subresources (`git`, `contents`, `issues`, `branches`, `pulls`, `commits`), in the function itself since hosting rewrites are bypassable via the direct function URL. Without this, any store user with `edit_storefront` could reach `/hooks`, `/keys` or arbitrary repositories through the PAT - Restore CORS and preflight handling on proxy responses (regression on 85bdcae), now answered by the proxy itself - `Cache-Control: private, no-store` on authenticated responses - Guard the module level catalog promise against unhandled rejection now that proxy requests skip awaiting it Covered by unit tests exercising the requests Decap CMS actually sends. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
A transient network error on the backend probe was discarding a working token, downgrading a healthy CMS session to the error screen. Now only 401 and 403 invalidate; probes also get a shorter 5s timeout so the failure path stays responsive. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Member
Author
|
Revisão adversarial feita sobre a versão inicial; achados corrigidos nos 2 últimos commits:
Validação: 20 testes de unidade em |
Proxy requests now skip the serve-feeds path that set CSP, nosniff and X-Frame-Options, so the proxy sets them itself. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contexto
O CMS (
/admin) do store 1024 (tiasonia) quebrou em 19/08 com "Repo "tiasonia/tiasonia" not found". A mensagem engana: é ohasWriteAccess()do Decap traduzindo um 401 Bad credentials do GitHub. Ogh_token(ghu_, user-to-server) devolvido porecomplus.app/api/github-installationsexpirou e não é renovado — nem refazendo o OAuth completo do GitHub App (reproduzido:POST /api/github-callbackcom 2xx não regrava o token). O proxy da plataforma (/api/{store}/git/github) injeta a mesma credencial morta, então não havia caminho de recuperação nenhum.O que muda
O storefront deixa de confiar cegamente no token da plataforma e ganha uma cadeia com fallback:
gh_token(GET /user) antes de usá-lo;/_api, funçãofeeds, comGITHUB_TOKENdo env) usando o token do SSO — a sonda bate em/_api/repos/{repo}, validando auth da loja + PAT + acesso ao repo de uma vez;O proxy da loja existia mas nunca poderia ter funcionado — faltavam consumidores para expor os defeitos:
Authorizationlido comslice(7)("Bearer "), mas o Decap mandatoken ***(não configurável) → 1 caractere do access token era cortado;req.path) →?ref={branch}perdido, leituras sempre na branch padrão (erro silencioso);Content-Lengthem unidades UTF-16 → commits com as mensagens padrão (aspas curvas “”) rejeitados pelo fetch;/user,/repos/:o/:rbare (ohasWriteAccess()lêpermissions.pushdali) e/search/**(notas de entrada);/repos/:o/:r/pullsbare (Decap lista/cria PRs do editorial workflow ali) não casava com o rewrite{git,contents,...}/**;/userresponde com o usuário autenticado da loja (autoria correta nos commits) e o endpoint do repo reportapermissions.push— o acesso de escrita é concedido peloedit_storefrontda Store API, não pela permissão do dono doGITHUB_TOKEN.Como validar
Loja com
GITHUB_TOKEN(PAT fine-grained: Contents RW, Pull requests RW, Metadata R) no env do grupomany, CLI atualizado (regenera ofirebase.jsoncom os rewrites) e deploy demany+ssr. O/admindeve autenticar mesmo com ogh_tokenda plataforma expirado. SemGITHUB_TOKEN, deve exibir a mensagem de credencial expirada em vez de "Repo not found".Atenção na revisão
**//*/*nos rewrites do Firebase Hosting (mantive ambos por segurança);api_rootpróprio;mainpara pendurar.Não corrige a causa raiz (backend do
ecomplus.appnão renova nem regrava oghu_) — tratada em issue separada.🤖 Generated with Claude Code