Files
conversation-history/SquareMCP/AI-Context/2026-06-17-claude-handoff-session-form-bug-fix.md
T

105 lines
5.8 KiB
Markdown

# Kimi Handoff — Session/Form Bug Fix + Pending Deploys
**Date:** 2026-06-17
**Session author:** Claude (Sonnet 4.6)
**Status:** Committed + pushed to `main` at `c6ab014`. Three deploys needed.
---
## What was fixed (commit `c6ab014`)
### Bug: "Save Connection" form leaking credentials to the URL and invalidating sessions
**Symptom:** After submitting the platform connect form (e.g. Facebook), the browser navigated to `https://app.squaremcp.com/?accessToken=<TOKEN>&pageId=<ID>`, then the user was redirected to the login page showing "Invalid session".
Three root causes, all fixed:
#### Fix 1 — `product/app/app.js:678` — form defaulted to GET
The `<form class="connect-form">` had no `method` attribute (default GET) and no `action` attribute (default = current URL). Any failure to call `e.preventDefault()` would append the form fields as query params in the address bar, exposing credentials to browser history and server logs.
**Change:** Added `method="post" action="javascript:void(0)"` to the form template. Native fallback submit is now a no-op instead of a GET navigation.
#### Fix 2 — `product/app/app.js:698` — stale `errorEl` reference
`errorEl` was obtained via `document.getElementById('connect-error')` — a document-wide lookup. If `openModal()` was called again while a fetch was in flight (replacing `modalBody.innerHTML`), this returned the wrong element or `null`, causing a TypeError that left the form without a working submit listener — meaning the *next* submit fell through to the native GET.
**Change:** Changed to `form.querySelector('#connect-error')` so the reference is always scoped to the live form.
#### Fix 3 — `src/index.ts:1561` — login cookie missing `domain` + wrong `sameSite`
`POST /api/auth/login` set the session cookie with `sameSite: 'strict'` and no `domain` attribute (scoped to `hermes.squaremcp.com` only). The signup endpoint and native login page both use `sameSite: 'lax'` + `domain: '.squaremcp.com'`. Inconsistency caused cross-subdomain session requests to behave differently depending on auth path.
**Change:** Aligned to `sameSite: 'lax'` + `domain: '.squaremcp.com'`.
---
## Three deploys needed
### Deploy A — `squaremcp-app` (urgent — fixes credential leak for live users)
Commit `c6ab014` changed `product/app/app.js`.
```bash
cd ~/hermes-mcp/product/app
git pull # gets c6ab014
docker build -t localhost:32000/squaremcp-app:c6ab014 .
docker save localhost:32000/squaremcp-app:c6ab014 -o /tmp/squaremcp-app-c6ab014.tar
microk8s ctr image import /tmp/squaremcp-app-c6ab014.tar
# update product/app/app-k8s.yaml: image → localhost:32000/squaremcp-app:c6ab014, imagePullPolicy: IfNotPresent
microk8s kubectl apply -f product/app/app-k8s.yaml
microk8s kubectl rollout status deployment/squaremcp-app -n fetcherpay
```
Verify: go to `https://app.squaremcp.com`, log in, click Connect on Facebook, fill in dummy credentials, submit — URL must NOT change to `?accessToken=...`. Error should appear inline in the modal.
### Deploy B — `hermes-mcp` (fixes login cookie for new sessions)
Commit `c6ab014` also changed `src/index.ts` (login cookie fix). Hermes needs a rebuild.
```bash
cd ~/hermes-mcp
git pull # gets c6ab014
docker build -t localhost:32000/hermes-mcp:c6ab014 .
docker save localhost:32000/hermes-mcp:c6ab014 -o /tmp/hermes-mcp-c6ab014.tar
microk8s ctr image import /tmp/hermes-mcp-c6ab014.tar
# update hermes-k8s.yaml: image → localhost:32000/hermes-mcp:c6ab014, imagePullPolicy: IfNotPresent
# DO NOT commit hermes-k8s.yaml — it contains the Communications OAuth secret
microk8s kubectl apply -f hermes-k8s.yaml
microk8s kubectl rollout status deployment/hermes-mcp -n fetcherpay
```
Verify: log out of `https://app.squaremcp.com`, log back in, DevTools → Application → Cookies for `hermes.squaremcp.com` — the `session` cookie should show `Domain: .squaremcp.com` and `SameSite: Lax`.
### Deploy C — `squaremcp-docs` (Communications docs page, still pending from 2026-06-16)
Commit `453831a` added `docs/communications.html` and updated nav across all docs pages. No new changes in this session — just the build that was deferred.
```bash
cd ~/hermes-mcp/docs
docker build -t localhost:32000/squaremcp-docs:453831a .
docker save localhost:32000/squaremcp-docs:453831a -o /tmp/squaremcp-docs.tar
microk8s ctr image import /tmp/squaremcp-docs.tar
# update docs/docs-k8s.yaml image similarly
microk8s kubectl apply -f docs/docs-k8s.yaml
microk8s kubectl rollout status deployment/squaremcp-docs -n fetcherpay
```
Verify: `https://docs.squaremcp.com/communications.html` loads; "Communications" shows in nav on every page.
---
## Side issue fixed this session — Redis pod sandbox churn
The hermes-mcp pod was stuck in `ContainerCreating` / readiness-probe failing because the Redis pod was stuck on a `SandboxChanged` event (classic single-node MicroK8s churn). Force-deleted the Redis pod; it came back healthy and hermes-mcp recovered automatically. No code change needed. Monitor: if Redis churns again, `microk8s kubectl delete pod -n fetcherpay -l app=redis --force --grace-period=0` is the fix. Adding memory limits to the ingress controller (from the previous open items list) would reduce overall sandbox pressure.
---
## Note on "Invalid session" for existing users
Users whose accounts were created before the MySQL container restart on 2026-06-16 will continue to get "Invalid session" errors from `meterMiddleware` — their customer rows were wiped and can't be recovered. Those users need to re-register. Fix 3 (login cookie alignment) prevents new users from hitting the cookie inconsistency going forward.
---
## Related vault docs
- Previous handoff (docs/picker deploy, Deploy C above): `SquareMCP/AI-Context/2026-06-16-claude-handoff-communications-docs-and-picker.md`
- Communications OAuth deploy result: `SquareMCP/deployments/2026-06-16-communications-chatgpt-oauth-deploy-result.md`