Skip to content

Add an owner-only gate for private notes - #19

Open
ShuminFu wants to merge 1 commit into
mainfrom
cursor/private-notes-access-fe0c
Open

ShuminFu wants to merge 1 commit into
mainfrom
cursor/private-notes-access-fe0c

Conversation

@ShuminFu

Copy link
Copy Markdown
Owner

What does this PR do?

Adds a fail-closed gate for a future private-notes section. The public garden, the 16 public notes, their URLs, RSS, and styling stay as they are. This pull request does not merge, deploy, or change live Cloudflare or Google settings, and live sign-in does not work yet.

Anonymous visitors see a modest Sign in link and no private entry. After a verified owner session, the same header gains Private Notes. Another Google account can be signed in and still does not see that entry. There is no client-side flash: the static HTML never contains the entry, and a Pages Function inserts it only after it checks the Access token.

Hiding the link is not the security boundary. /private/ and the separate notes deployment both require a signed Cloudflare Access JWT. A missing, expired, forged, or non-owner token fails closed. Cf-Access-Authenticated-User-Email is ignored. Preview and *.pages.dev hostnames do not serve the entry or the notes unless PRIVATE_NOTES_ALLOW_PREVIEW=true.

Why this is not Access alone

Access can demand Google login for a path. It does not rewrite the public HTML, and the shared cache key ignores cookies. The CF_Authorization cookie is HttpOnly, so the browser cannot decide what to draw. The public site therefore needs a Pages Function. It verifies the token (signature, issuer, audience, expiry) and compares the email claim with OWNER_EMAIL.

Two deployments

This public repository holds the website and an empty notes catalog. A private repository, which does not exist yet and is not named here, will hold the notes. There is no submodule and no build-time clone. A pointer at that repo would not be authorization, and a checkout during the public build could publish the notes. scripts/check-public-boundary.mjs fails if that happens.

The owner entry on funfun.zone proxies to PRIVATE_NOTES_ORIGIN only after the token matches. The browser does not receive that origin or a token of its own. The private worker checks the same token again. The full checklist is in docs/private-notes.md.

How to test

  1. npm test
  2. npm run build
  3. npm run dev and open the home page. The header shows Sign in. It does not show Private Notes. /auth/login/ explains that this preview does not start a session.
  4. The identity states below were rendered locally through the real gate with a throwaway test key. They are not a live Google login.

Anonymous, light:

Anonymous home, Sign in only

Anonymous, dark:

Anonymous home in dark mode

Anonymous phone menu:

Anonymous phone menu

Owner, after a verified test token. Not a real session:

Owner header with Private Notes

Owner, dark:

Owner header in dark mode

Owner phone menu:

Owner phone menu

Owner, empty private library. No notes are stored in this repo:

Empty private notes

A different verified Google account. Sign out is visible. Private Notes is not:

Non-owner header

That account opening /private/:

Non-owner denied

Public notes are still the public 16:

Public Notes unchanged

Before Access is configured, Sign in fails closed:

Sign-in not configured

Checklist

  • npm run build passes
  • Tested in light and dark mode
  • Tested with at least two themes (e.g. sage, classic). Verified in classic, light and dark. The new links use the same nav classes as Garden and About, so the other palettes recolor them through the existing tokens. Sage was not opened separately.
  • No new warnings in the console. The build still prints the existing empty docs and projects warnings and the existing markdown-plugin deprecation.

What you still have to set

This repository does not know the owner. Nothing was inferred from commits or from the about page. Put these only in the Cloudflare dashboard, not in git:

  1. ACCESS_TEAM_DOMAIN — https://<team-name>.cloudflareaccess.com
  2. ACCESS_AUD — the Access application’s AUD tag
  3. OWNER_EMAIL — the Google account you will sign in with
  4. PRIVATE_NOTES_ORIGIN — https://<private-deployment-host>, after that host exists

Google’s OAuth client id and client secret go only into Zero Trust → Google. Access’s Google login needs that client. This site never sees the secret and does not run its own OAuth exchange.

Set the Access global session, the application session, and the allow policy session to one month. That is the longest Access will issue. This code honors exp, allows 60 seconds of clock skew, and refuses a token with more than 32 days left. It does not mint a longer cookie.

Do not copy the variables onto preview deployments. Do not add a Bypass policy for /private or /auth, and do not add a Cache Everything rule. Create the private repository and its Cloudflare project only when you want notes to exist. Steps are in docs/private-notes.md.

To show artifacts inline, enable in settings.

Open in Web Open in Cursor 

Public pages stay cached and unchanged. A Pages Function verifies a Cloudflare Access token before it shows the private entry or reads a separate deployment. This repository keeps an empty catalog and does not contain the owner identity.

Co-authored-by: Shumin <shuminfu99@gmail.com>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying fun-fun-zone with  Cloudflare Pages  Cloudflare Pages

Latest commit: 31a2940
Status: ✅  Deploy successful!
Preview URL: https://b3cc45dc.fun-fun-zone.pages.dev
Branch Preview URL: https://cursor-private-notes-access.fun-fun-zone.pages.dev

View logs

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.

2 participants