Skip to content

fix(api): serve public profile sections to the audience those pages have (#732) - #748

Merged
thinkclay merged 1 commit into
mainfrom
claude/fix-public-profile-anon
Sep 11, 2026
Merged

thinkclay merged 1 commit into
mainfrom
claude/fix-public-profile-anon

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Closes #732.

Found smoke-testing production as an anonymous visitor — the audience a public profile exists for. Every section endpoint the page calls answered 401, so scaffald.com/users/clay rendered "No profile data available", "No work experience added yet" and "No verified work logs are currently visible on this profile" for a profile that has all three.

A visitor cannot tell an empty profile from a gated one, and neither can a crawler — these pages are in sitemap-users.xml.

The product decision was already made

I filed this asking which sections should be public. They are already decided, in code. GET /v1/profiles/slug/{slug} serves anonymously and returns a visibility object from core.preferences.profile_visibility — work experience, education, skills, certifications and reviews public by default, contact info not, each overridable by the owner.

The page reads that object to decide what to render, then asks for the data and is refused. The endpoints never honoured the rule the page was already being handed.

lib/profile-visibility.ts is that rule in one place rather than copied into six handlers, with a test asserting its defaults match the ones in profiles.ts — if those drift, the page renders a section the data endpoint then refuses, or hides one it would have served.

Why the auth check was there at all

Each handler did if (!user) return 401 then userId || user.id. The check existed to make that fallback possible — without a caller there is no "me". An explicit userId needs no fallback, which is what makes an anonymous read of a named public profile possible. No userId still requires auth.

Authorization vs mechanism

core.user_experience, user_education and user_certifications carry owner-only SELECT policies, so a viewer's own client reads nothing of someone else's profile however the owner published it. The visibility check is the authorization; the service client is only how it's carried out — the same split profiles.ts already documents. Reading your own profile stays on your own client, so RLS still applies there.

A hidden section answers 404, not 403 — 403 would confirm the section exists and was hidden, which is the one thing the owner asked not to reveal.

work-logs/public-feed was my own mistake

I built it in #616 for WorkLogPortfolioWidget, which renders only on app/(public)/users/[slug].tsx — then gated it on if (!user) and verified it with an authenticated caller. It was reachable in exactly the case it wasn't built for. Its filters (verified status, show_on_profile, per-photo opt-in) are the publication rule, and none depend on who is asking.

reviews/by-subject contradicted its own table: core.reviews carries reviews_read as SELECT to {anon, authenticated} USING (true). The 401 was the only thing stopping the page showing them. The owner's reviews flag still hides them.

Verified against a live stack

case result
anonymous, visible section ✅ 200
anonymous, owner hid it ✅ 404
a different signed-in user, hidden section ✅ 404
owner, implicit "me" ✅ 200
owner, explicit own id ✅ 200
no userId, anonymous ✅ 401
/widgets/preferences, anonymous ✅ 401

18 new tests. The route guards assert the rules rather than the wiring, because the wiring is easy to reintroduce — an if (!user) return 401 added to a section handler looks locally sensible and silently empties every public profile again.

One pre-existing failure in sdk-envelopes.test.ts (GET /v1/profiles/:p, /v1/profiles/organizations/:p) is unrelated — confirmed identical with my changes stashed.

🤖 Generated with Claude Code

…ave (#732)

Found smoke-testing production as an anonymous visitor — the audience a public
profile exists for. Every section endpoint the page calls answered 401:

  /v1/profiles/widgets/general-info     401
  /v1/profiles/widgets/experience       401
  /v1/profiles/widgets/education        401
  /v1/profiles/widgets/skills           401
  /v1/profiles/widgets/certifications   401
  /v1/work-logs/public-feed             401
  /reviews/by-subject                   401

So scaffald.com/users/clay rendered "No profile data available", "No work
experience added yet" and "No verified work logs are currently visible on this
profile" for a profile that has all three. A visitor cannot tell an empty
profile from a gated one, and neither can a crawler — these pages are in
sitemap-users.xml.

## The product decision was already made

I filed this asking which sections are public. They are already decided, in
code: GET /v1/profiles/slug/{slug} serves anonymously and returns a `visibility`
object from core.preferences.profile_visibility — work experience, education,
skills, certifications and reviews public by default, contact info not, each
overridable by the owner. The page reads that object to decide what to render,
then asked for the data and was refused. The endpoints simply never honoured the
rule the page was already being told.

lib/profile-visibility.ts is that rule in one place rather than copied into six
handlers, with a test asserting its defaults match the ones in profiles.ts —
if those drift, the page renders a section the data endpoint then refuses.

## Why the auth check was there at all

Each handler did `if (!user) return 401` and then `userId || user.id`. The check
existed to make that fallback possible: without a caller there is no "me". An
explicit userId needs no fallback, which is what makes an anonymous read of a
named public profile possible at all. No userId still requires auth.

## Authorization versus mechanism

core.user_experience, user_education and user_certifications carry owner-only
SELECT policies, so a viewer's own client reads nothing of someone else's
profile however the owner published it. The visibility check is the
authorization; the service client is only how it is carried out — the same split
profiles.ts already documents for /slug/{slug}. Reading your own profile stays on
your own client, so RLS still applies there.

A hidden section answers 404, not 403: 403 would confirm the section exists and
was hidden, which is the one thing the owner asked not to reveal.

## work-logs/public-feed was my own mistake

I built it in #616 for WorkLogPortfolioWidget, which renders only on
app/(public)/users/[slug].tsx, gated it on `if (!user)`, and verified it with an
authenticated caller. It was reachable in exactly the case it was not built for.
Its filters — verified status, the worker's show_on_profile opt-in, a per-photo
opt-in — are the publication rule, and none of them depend on who is asking.

reviews/by-subject contradicted its own table: core.reviews carries reviews_read
as SELECT to {anon, authenticated} USING (true). The 401 was the only thing
stopping the page showing them; the owner's `reviews` flag still hides them.

Verified against a live stack, anonymously and signed in:

  anonymous, visible section            200
  anonymous, owner hid it               404
  a different signed-in user, hidden    404
  owner, implicit "me"                  200
  owner, explicit own id                200
  no userId, anonymous                  401
  /widgets/preferences, anonymous       401

Co-Authored-By: Claude Opus 5 <[email protected]>
@thinkclay
thinkclay merged commit 3bf189f into main Sep 11, 2026
7 of 8 checks passed
@thinkclay
thinkclay deleted the claude/fix-public-profile-anon branch September 11, 2026 21:09
@github-actions

Copy link
Copy Markdown
Contributor

📊 Performance Benchmark Results


thinkclay added a commit that referenced this pull request Sep 11, 2026
…g them

Clears BASELINE_MISMATCHES to empty. Nine were real and are fixed in
Scaffald/sdk#30; two were this test's own false positives.

**Seven declared the payload against a route that wraps** — apiKeys.update,
apiKeys.getUsage, connections.accept, connections.send, engagement.track,
follows.followJob, follows.followUser. They now unwrap, as 39 other methods in
the SDK already do, rather than widening the signature. That is the fix that
makes callers work rather than merely type-check: useUpdateApiKeyMutation
already declares `UseMutationOptions<ApiKey, …>`, so the hook, the screens and
the type were all right and only the runtime value was wrong.

**Two declared an envelope their route does not send,** and this one was live.
personalityAssessments.getStatus and getIPIPStatus declared `{ data: … }`;
probed against the running api, both routes answer bare. So every consumer
reading `status?.data` was reading undefined:

  PersonalityAssessmentWidget.tsx           const assessment = assessmentData?.data
  usePersonalityAssessment.ts               const assessment = assessmentData?.data
  useAssessmentStatus.ts                    cast through `{ data?: … }` to compile

All three corrected here. A fourth, LuscherTestWizard.tsx, already carried the
workaround *and the diagnosis* — "SDK type declares { data: AssessmentStatus }
but API returns AssessmentStatus directly", with a `??` fallback that made that
one screen work while the other three silently did not. Now that the type is
right, the fallback goes too.

Typecheck found that fourth site on its own once the declaration stopped lying,
which is the argument for fixing the type rather than the call sites.

**Two were the guard's false positives.** auth.getUserRoles and
jobs.officeDuplicateJob do unwrap, through spellings the detector did not
recognise:

    return { roles: response.data.roles }              // reshapes while unwrapping
    .then((res) => res.data)
    const response = (await this.get<…>(p)) as {…}     // parenthesised cast

Detection is now precise about the thing that matters: find the name the
response is bound to, then ask whether the body reads `.data` off it. Widening
it that way first hid four real unwraps in background-checks and feedback,
because the binding regex did not allow the parenthesised form — caught by the
baseline's own stale check, which is what that half of the guard is for.

Re-attacked after the change, since a too-permissive detector would mask the
class it exists to catch: reverting engagement.track to its pre-fix form is
still reported as "sdk says bare, route says wrapped", and legitimate unwrapping
is still not flagged.

Also runs deno fmt over three files this branch does not otherwise touch —
__tests__/lib/profile-visibility.test.ts,
__tests__/routes/public-profile-sections.test.ts and routes/profile-widgets.ts,
all from #748. They fail `Lint REST API Code` on main, and formatting them makes
that check pass rather than fail less.

scf-core typecheck and its 1151 tests pass; deno fmt and lint clean; the
contract directory is 9/9.

Closes #744

Co-Authored-By: Claude Opus 5 <[email protected]>
thinkclay added a commit that referenced this pull request Sep 11, 2026
…g them (#750)

Clears BASELINE_MISMATCHES to empty. Nine were real and are fixed in
Scaffald/sdk#30; two were this test's own false positives.

**Seven declared the payload against a route that wraps** — apiKeys.update,
apiKeys.getUsage, connections.accept, connections.send, engagement.track,
follows.followJob, follows.followUser. They now unwrap, as 39 other methods in
the SDK already do, rather than widening the signature. That is the fix that
makes callers work rather than merely type-check: useUpdateApiKeyMutation
already declares `UseMutationOptions<ApiKey, …>`, so the hook, the screens and
the type were all right and only the runtime value was wrong.

**Two declared an envelope their route does not send,** and this one was live.
personalityAssessments.getStatus and getIPIPStatus declared `{ data: … }`;
probed against the running api, both routes answer bare. So every consumer
reading `status?.data` was reading undefined:

  PersonalityAssessmentWidget.tsx           const assessment = assessmentData?.data
  usePersonalityAssessment.ts               const assessment = assessmentData?.data
  useAssessmentStatus.ts                    cast through `{ data?: … }` to compile

All three corrected here. A fourth, LuscherTestWizard.tsx, already carried the
workaround *and the diagnosis* — "SDK type declares { data: AssessmentStatus }
but API returns AssessmentStatus directly", with a `??` fallback that made that
one screen work while the other three silently did not. Now that the type is
right, the fallback goes too.

Typecheck found that fourth site on its own once the declaration stopped lying,
which is the argument for fixing the type rather than the call sites.

**Two were the guard's false positives.** auth.getUserRoles and
jobs.officeDuplicateJob do unwrap, through spellings the detector did not
recognise:

    return { roles: response.data.roles }              // reshapes while unwrapping
    .then((res) => res.data)
    const response = (await this.get<…>(p)) as {…}     // parenthesised cast

Detection is now precise about the thing that matters: find the name the
response is bound to, then ask whether the body reads `.data` off it. Widening
it that way first hid four real unwraps in background-checks and feedback,
because the binding regex did not allow the parenthesised form — caught by the
baseline's own stale check, which is what that half of the guard is for.

Re-attacked after the change, since a too-permissive detector would mask the
class it exists to catch: reverting engagement.track to its pre-fix form is
still reported as "sdk says bare, route says wrapped", and legitimate unwrapping
is still not flagged.

Also runs deno fmt over three files this branch does not otherwise touch —
__tests__/lib/profile-visibility.test.ts,
__tests__/routes/public-profile-sections.test.ts and routes/profile-widgets.ts,
all from #748. They fail `Lint REST API Code` on main, and formatting them makes
that check pass rather than fail less.

scf-core typecheck and its 1151 tests pass; deno fmt and lint clean; the
contract directory is 9/9.

Closes #744

Co-authored-by: Claude Opus 5 <[email protected]>
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.

Public profile pages are empty for anonymous visitors — most of their data needs auth

1 participant