Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A mobile-first GitHub workspace built with React, TypeScript, Vite and Tailwind.
## Two separate connections

1. **Sign in to GitPlus with Gothwad Accounts.** Existing first-party Accounts sessions are recognized automatically. A same-origin Cloudflare Pages Function verifies HttpOnly cookies with the Accounts API and returns only a public profile.
2. **Connect GitHub separately.** Gothwad login does not grant GitHub repository permissions. The current connection uses a user-provided GitHub PAT scoped to the verified Gothwad user ID and this tab. A server-side GitHub App integration is future work, not implemented authentication.
2. **Connect GitHub separately.** Gothwad login does not grant GitHub repository permissions. Use **Connect with GitHub** (OAuth App) or a manually supplied PAT. Either connection is bound to the verified Gothwad user ID and stored only in this tab session. No D1 or cross-device token sync is used.

No Gothwad password, Accounts access token or refresh token is stored by the browser app. GitHub PATs still need careful handling: session storage is not an encrypted vault.

Expand All @@ -17,10 +17,11 @@ This is now **Pages + a small Pages Function**, not a static-only deployment:

```text
Browser -> /api/session (Pages Function) -> Gothwad Accounts /api/auth/me
-> GitHub REST API (separate GitHub PAT)
-> /api/github/* (Pages Functions: OAuth state/callback/code exchange)
-> GitHub REST API (local OAuth token or PAT)
```

No new D1/R2 database, Accounts JWT secret, OAuth client secret or GitHub token is required in Pages environment settings. Accounts continues owning sessions.
No new D1/R2 database or Accounts JWT secret is required. Accounts continues owning sessions. GitHub OAuth requires runtime `GITHUB_CLIENT_ID` and encrypted `GITHUB_CLIENT_SECRET`; PAT works without these. See [OAuth setup and CLI fallback](docs/github-oauth.md) if Pages dashboard runtime editing is disabled.

**Silent SSO requires a first-party HTTPS custom domain.** The proposed/default origin is `https://gitplus.gothwadtech.com`; configure that domain in Pages before production use. `pages.dev`, localhost and Arena preview domains cannot receive `.gothwadtech.com` cookies. They deliberately show a setup message, not fake authentication. The custom domain is configured in source but has **not** been provisioned or deployed by this repair.

Expand Down Expand Up @@ -73,22 +74,23 @@ CI has a separate browser job that installs Chromium and runs these checks. `PLA
| Runtime `GITPLUS_ORIGIN` | `https://gitplus.gothwadtech.com` (change if using another first-party subdomain) |
| Runtime `ACCOUNTS_API_ORIGIN` | `https://api.gothwadtech.com` |
| Functions | Root `functions/` must be deployed with the app |
| Secrets / new database | None for this Accounts-cookie integration |
| OAuth runtime credentials | `GITHUB_CLIENT_ID`, encrypted `GITHUB_CLIENT_SECRET`; never `VITE_*` |
| New database | None |

Values above are non-secret runtime variables, already declared in `wrangler.jsonc`. Do not upload only the static `dist` directory through a method that omits Functions. See [deployment instructions](docs/cloudflare-pages.md).
The two origins are non-secret runtime variables already declared in `wrangler.jsonc`. OAuth credentials must be configured separately; no real secret is checked in. Do not upload only the static `dist` directory through a method that omits Functions. See [deployment instructions](docs/cloudflare-pages.md).

## Project layout

```text
functions/api/[[path]].ts Same-origin session route + JSON API 404s
functions/api/[[path]].ts Session, OAuth and explicit sign-out routes + JSON API 404s
server/accountsSession.ts Accounts verification and cookie/public-profile filtering
shared/ Product identity and shared Accounts contract
src/
context/AccountsContext.tsx Session lifecycle, retry, account switching
components/accounts/ Gothwad login gate and account menu
services/accounts/ Abortable single-flight session client
services/github.ts GitHub API and non-forced batch sync
utils/ Owner-bound PAT, ZIP, encoding and storage helpers
utils/ Owner-bound GitHub token, ZIP, encoding and storage helpers
public/ _headers, _routes.json, favicon, robots.txt
docs/ Product plan, integration research and operations
tests/ Regression tests with mocked upstream services
Expand All @@ -102,7 +104,7 @@ Generated `dist/`, `.wrangler/`, dependencies, `.env*` and `.dev.vars*` are not

- Signed-in Accounts identity is rechecked on startup, on visible-tab intervals and focus; no persistent profile acts as authentication.
- Switching Gothwad users clears the GitHub connection and invalidates in-flight operations. A late response cannot sign a new user in as the previous one.
- “Disconnect GitHub” and “Sign out of GitPlus (this tab)” are distinct. Global Gothwad sign-out is managed on Accounts; GitPlus does not silently sign Mail/Drive/Store out.
- “Disconnect GitHub” and “Sign out of GitPlus (this tab)” are distinct. The **actual hosted universal Accounts menu** supports explicitly confirmed ecosystem sign-out and local-only sign-out. Read-only checks never silently sign Mail/Drive/Store out.
- ZIP paths are preserved by default; optional wrapper removal strips one outer directory only. Review all paths/deletions before syncing.
- Batch sync requires an initialized branch, never force-pushes and aborts on partial upload failures. Start with a disposable repository.

Expand All @@ -111,6 +113,7 @@ Generated `dist/`, `.wrangler/`, dependencies, `.env*` and `.dev.vars*` are not
- [Product identity and phased roadmap](docs/product-roadmap.md)
- [Accounts research, contract and implementation](docs/gothwad-accounts.md)
- [Cloudflare deployment and rollout checklist](docs/cloudflare-pages.md)
- [GitHub OAuth App, scopes and runtime secrets](docs/github-oauth.md)
- [Architecture](docs/architecture.md)
- [Security and permissions](docs/security.md)
- [Audit and remaining limitations](docs/audit.md)
Expand Down
5 changes: 3 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
| [Product roadmap](product-roadmap.md) | Canonical naming, phases, completed implementation and remaining work |
| [Gothwad Accounts](gothwad-accounts.md) | Source-pinned Accounts/Mail/Store/Drive findings, SSO decisions and API contract |
| [Cloudflare Pages](cloudflare-pages.md) | Functions, runtime variables, first-party domain and deployment acceptance tests |
| [GitHub OAuth](github-oauth.md) | OAuth App registration, runtime-secret CLI fallback, local storage, scopes and callback security |
| [Architecture](architecture.md) | Runtime boundaries and code ownership |
| [Security](security.md) | Accounts cookies versus GitHub PATs, scopes, ZIP safety and hosting defenses |
| [Security](security.md) | Accounts cookies versus GitHub OAuth/PATs, scopes, ZIP safety and hosting defenses |
| [Audit](audit.md) | Initial repository repair, current verification and known limitations |

Deployment is **Pages + Functions**, not static-only. No new database or login secret is needed for first-party Accounts-cookie SSO. Runtime origins are public configuration; never expose credentials through `VITE_*` variables.
Deployment is **Pages + Functions**, not static-only. No new database or login secret is needed for first-party Accounts-cookie SSO. GitHub OAuth separately requires its runtime client credentials (PAT remains available without them). Runtime origins are public configuration; never expose credentials through `VITE_*` variables.
14 changes: 10 additions & 4 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ GitPlus is a Gothwad Tech product. Its identity provider is Gothwad Accounts; Gi
Cloudflare Pages: dist/ static React app
/api/* -> root Pages Function
/api/session -> verified Accounts cookie session -> public identity only
/api/github/* -> OAuth App state, callback and code exchange (no token vault)
/api/accounts/signout[-all] -> explicit, verified universal-menu mutations
other paths -> JSON 404

Browser after verified Accounts identity
-> GitHub REST API using the separately connected GitHub PAT
-> GitHub REST API using the separately connected OAuth token or PAT
-> JSZip + Web Crypto for local ZIP comparison
-> sessionStorage: owner-bound GitHub PAT, account selector, local sign-out marker
-> sessionStorage: owner-bound GitHub token, short-lived OAuth verifier, account selector, local sign-out marker
-> localStorage: non-secret appearance/editor preferences only
```

Expand All @@ -26,14 +28,18 @@ No new database, AI backend, Express server or self-issued Gothwad login token e
| `shared/brand.ts` | GitPlus / Gothwad Tech public identity and default first-party domains |
| `shared/accounts.ts` | Public identity types, schema normalization, safe return URL and selectors |
| `functions/api/[[path]].ts` | Pages route dispatch; no accidental SPA fallback for API requests |
| `server/githubOAuth.ts`, `server/protectedRequest.ts` | Exact-origin JSON/Accounts verification, encrypted transaction cookie, S256 PKCE, fixed provider exchange |
| `server/accountActions.ts` | Narrow, explicit sign-out routes; approved rotations/deletions only |
| `src/services/githubOAuth.ts` | Same-tab verifier, single-flight completion and owner/generation guards |
| `src/services/accounts/accountWidget.ts`, `AccountsBar.tsx` | Real hosted universal menu, sanitized state and guarded callbacks |
| `server/accountsSession.ts` | Trusted upstream request, cookie filtering, timeout, public-profile projection, no-store responses |
| `src/services/accounts/sessionClient.ts` | Single-flight, selector-keyed, abortable session requests; explicit error states |
| `src/context/AccountsContext.tsx` | Automatic session boot/revalidation, account switching, local sign-out pause, generation isolation |
| `src/components/accounts/AccountsGate.tsx` | Product sign-in/setup/error screens and Gothwad account menu |
| `src/App.tsx` | Verified user's GitHub workspace; lazy-loaded tabs and overlays |
| `src/components/AuthScreen.tsx` | **Connect GitHub**, not the product identity login |
| `src/services/github.ts` | GitHub REST API, cancellable request generations, live trees, pagination, batch commits |
| `src/utils/tokenStorage.ts` | Session-only PAT with verified Gothwad user ID ownership; unbound legacy tokens removed |
| `src/utils/tokenStorage.ts` | Session-only OAuth token/PAT with verified Gothwad user ID ownership; unbound legacy tokens removed |
| `src/utils/zipParser.ts`, `paths.ts`, `encoding.ts` | ZIP byte budgets, path safety and byte-exact Git SHA/Base64 |
| `src/components/ErrorBoundary.tsx` | Reload recovery on render failure |

Expand All @@ -54,7 +60,7 @@ No local profile/cookie decoding is considered proof of authentication. The UI h

A temporary identity-service outage blocks the workspace and invalidates pending GitHub calls without deliberately deleting the same-owner PAT. Successful revalidation can restore that connection. An identity change or local sign-out deletes the old connection. Unsaved UI/draft state is not durable and can reset when the gate closes.

The implementation does not introduce a global account-menu script or widen CSP to external scripts: its local account menu uses Accounts-derived, sanitized metadata. Global account management stays on Accounts.
The app imports the actual `https://accounts.gothwadtech.com/widget/account-menu.js` ES module and relative template/style modules. CSP permits only that external script directory. Its state is sanitized; callbacks use GitPlus verification/switching and protected sign-out routes instead of raw `/auth/me`. This shared script is trusted app code with access to local GitHub tokens, not a sandbox. Load failure shows a management link, not a cloned menu. See [OAuth protocol](github-oauth.md) and [security](security.md).

## Tooling

Expand Down
14 changes: 12 additions & 2 deletions docs/audit.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ No real GitHub write/delete/merge operations or Cloudflare account deployment ar

## Current known limitations / next work

- Gothwad Accounts SSO and its read-only backend adapter are now implemented. GitHub authorization remains PAT-based; a server-side GitHub App/OAuth credential flow and vault are not implemented.
- Accounts SSO, OAuth App + PAT and the actual shared account menu are implemented. No token vault/D1 is intended. Runtime OAuth credentials and live first-party/provider acceptance remain operator work; see [setup](github-oauth.md).
- GitHub Actions log redirects and private raw-file/image downloads may fail in a browser because of CORS or authorization. Opening the resource on GitHub is the safe fallback; do not paste tokens into raw URLs.
- Empty repositories need an initial commit before batch ZIP sync. Large/truncated recursive trees are blocked instead of partially compared. A full subtree traversal workflow is future work.
- Repository lists paginate; several other endpoint lists (branches, releases, issues, PR files, jobs, etc.) still return a limited page. Full pagination/UI for all endpoints remains to be implemented.
Expand All @@ -72,4 +72,14 @@ Run `npm ci && npm run check` for current results. The expanded suite checks the

The initial 20-test count above describes the earlier repair, not the expanded suite. Real Accounts cookie acceptance across products, DNS/custom-domain provisioning and live GitHub writes still require the operator's staging checklist. No deployment or modification to Accounts/Mail/Store/Drive was made here.

Latest local follow-up checks: **40 regression tests passed**, **3 Playwright browser tests passed**, TypeScript and production build passed, Pages Functions compiled, and `npm audit --audit-level=moderate` reported **0 known vulnerabilities**. Browser checks cover automatic existing-session recognition, GitHub owner isolation on account switch, local sign-out across reload, return/error behavior without redirect loops, and the real local Functions unsupported-domain/JSON-404 responses. Upstream identity/GitHub responses are mocked in the authenticated browser cases; this does not claim live Accounts SSO is deployed.
Previous SSO-only follow-up checks: **40 regression tests passed**, **3 Playwright browser tests passed**, TypeScript and production build passed, Pages Functions compiled, and `npm audit --audit-level=moderate` reported **0 known vulnerabilities**. Browser checks cover automatic existing-session recognition, GitHub owner isolation on account switch, local sign-out across reload, return/error behavior without redirect loops, and the real local Functions unsupported-domain/JSON-404 responses. Upstream identity/GitHub responses are mocked in the authenticated browser cases; this does not claim live Accounts SSO is deployed.

## OAuth App + universal menu verification (2026-10-24)

- Implemented the accepted OAuth App + PAT design: mandatory Accounts identity, base scopes plus explicit optional `delete_repo`, same-tab S256 PKCE, encrypted ten-minute transaction cookie, verified-owner callback/completion and local owner-bound session storage. No D1, refresh-token persistence, GitHub App installation flow or cross-device sync.
- Replaced the local menu with the actual Accounts-hosted universal module. Explicit slot/global sign-out uses narrowly routed, origin-checked, verified mutations; local GitPlus sign-out stays local. CSP and the trusted-script supply-chain boundary are documented.
- **52 unit/regression tests passed**, including state/PKCE/owner rejection, expiry/tampering, secret rotation, one-use exchange failure, sign-out and widget loader contracts.
- **8 Playwright browser tests passed** with real built Pages assets, pinned actual widget modules and mocked Accounts/GitHub: OAuth completion/reload/disconnect, PAT fallback, denial, widget mutation/failure and stale completion after a Gothwad account switch, plus existing SSO/isolation tests.
- TypeScript, production Vite build and Pages Functions compilation passed. `npm audit --audit-level=moderate` reported **0 known vulnerabilities**; `git diff --check` passed.
- The browser mock uses a consent document and fresh navigation because Playwright only intercepts the first request of a server redirect chain. Real callback 303 behavior is covered by server tests. This is not a live OAuth provider test.
- [Administrator documentation](github-oauth.md) includes exact OAuth App URLs, runtime-secret CLI prompts for dashboard-restricted Pages projects, redeploy/config verification, scope limits and revocation. No real credentials were supplied/configured. Live OAuth/SSO/custom-domain and hosted-module acceptance remain required.
Loading
Loading