Skip to content

fix(api): the CCPA disclosure under-reported, and delete-user destroyed data on a path that failed (#652, #653) - #663

Merged
thinkclay merged 1 commit into
mainfrom
claude/fix-ccpa-and-delete-user
Aug 27, 2026
Merged

thinkclay merged 1 commit into
mainfrom
claude/fix-ccpa-and-delete-user

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Closes #652. Closes #653.

The shared root cause, and why the obvious fix doesn't work

A head-count against a table the client cannot read comes back as:

{"status": 204, "error": null, "count": null}

No error is raised. So res.count ?? 0 reports a confident zero for data it never looked at — and checking error instead, which is exactly what this looks like it needs, changes nothing. Measured against a live stack, not assumed:

PROBE skills    {"count":null,"error":null,"status":204}
PROBE education {"count":2,"error":null,"status":200}

count: "exact" always yields a number when the query actually ran, so a null count is the only dependable signal that it didn't. I built the fix with the error check first, and the break-test caught it still returning 200 with a quietly smaller total.


#652 — the CCPA disclosure

A user with 2 education records, 6 skills, 3 work experiences and 3 certifications was told professional_information: hasData: false, itemCount: 0.

Eight of thirteen counts were failing, not the five originally filed:

queried reality
core.profiles does not exist; identity is core.users
core.education core.user_education
core.profile_skills core.user_skills
core.work_experience core.user_experience
core.feedback logs.user_feedback
core.certifications exists — but it's the catalogue, no user_id
id_verifications keyed worker_user_id, not user_id
reviews keyed author_user_id, not reviewer_user_id

The last three are what a table-name audit misses: the table is right and the filter is wrong, which fails exactly as silently.

A category that can't be counted now fails the request rather than shrinking the total — a partial disclosure understates what's held, which is the whole defect.

before after
user with 14 professional records hasData: false, itemCount: 0 hasData: true, itemCount: 14
one count broken 200, itemCount silently 8 500 naming the category

Platform feedback is left out of the Communications label rather than counted as zero: logs.user_feedback is unreachable — PostgREST doesn't expose the logs schema and it grants only postgres — so the feedback router is broken for the same reason. Stated in the code rather than papered over.

The admin queue read core.profiles too, so every row showed a blank name for whoever filed the request. Now reads core.users, with emails resolved through the auth admin API since they live in auth.users.


#653 — admin delete-user

The issue as I filed it was wrong, and the truth is worse.

I claimed data was left behind and success reported. In fact every relevant table cascades from core.users, and core.users cascades from auth.users — verified in a rolled-back transaction, all counts went to 0. So the hand-written cascade was redundant. Six of its eight statements were no-ops regardless, because .schema("core") applies only to the statement it's written on and the rest addressed public, with no result checked.

The two statements that did work ran first. Ten RESTRICT/NO ACTION references then block the delete for any user who verified a work log or created a task:

delete from core.user_skills ...   -- succeeds
delete from core.profile ...       -- succeeds
delete from core.users ...         -- ERROR: violates foreign key constraint
                                   --        work_logs_verified_by_user_id_fkey

The operator saw "Failed to delete user profile" while that user's skills and personal details were already gone, with no transaction to roll back. Retrying did nothing more.

Now

  1. Check the seven RESTRICT relations before writing anything → 409 naming what blocks it
  2. Release the three nullable verification pointers (work_logs.verified_by_user_id, user_skills.verified_by, skill_evidence.verified_by) — audit attributions, not content; holding a deletion hostage to one would make any reviewer undeletable
  3. Delete the auth user; the cascade does the rest

The NOT NULL ownership references (tasks, punchlists, organization_documents, …) can't be released and shouldn't be silently deleted — removing a person shouldn't remove work others depend on — so they're reported for a human decision.

case result
user with 18 tasks + 3 punchlists 409 blockedBy: [{tasks:18},{punchlists:3}], profile intact (was: 500, profile destroyed)
clean user with profile, education, experience, a verification pointer 200, all rows cascaded, pointer released

One honest caveat, in the code: if the auth delete fails for an unrelated reason after the release step, those pointers stay released — an audit attribution is lost, no record is destroyed, and retrying is safe.


Tests

Pinned as rules rather than table names, so a rename can't make either fail quietly again — including that count === null is the failure signal, since checking error looks like a fix and isn't.

Confirmed non-vacuous: all seven fail against the unfixed code (they show up as "newly passing" when the route changes are stashed).

Two flaws in my tests surfaced while writing them — "education" matched a count label, and reviewer_user_id matched my own explanatory comment — so assertions now read comment-stripped code.

  • Schema guard baseline: 45 → 33 references, 24 → 13 table names
  • API suite: 317 passed / 80 failed against 310 / 87 on main; failure sets diffed by name, zero newly failing

🤖 Generated with Claude Code

…ed data on a path that failed (#652, #653)

Two P0s from the schema-reference sweep (#660). They share a root cause that is
worth stating first, because the obvious fix for it does not work.

A head-count against a table the client cannot read comes back as:

    {status: 204, error: null, count: null}

No error is raised. So `res.count ?? 0` reports a confident zero for data it
never looked at — and checking `error` instead, which is what this looks like it
needs, changes nothing. Measured against a live stack, not assumed. The only
dependable signal is that `count: "exact"` always yields a number when the query
actually ran, so a null count means it did not.

## #652 — CCPA data summary

The disclosure told a user with 2 education records, 6 skills, 3 work
experiences and 3 certifications that professional_information was
`hasData: false, itemCount: 0`.

Eight of the thirteen counts were failing, not five as first filed:

  core.profiles          -> does not exist; identity is core.users
  core.education         -> core.user_education
  core.profile_skills    -> core.user_skills
  core.work_experience   -> core.user_experience
  core.feedback          -> logs.user_feedback
  core.certifications    -> exists, but is the catalogue and has no user_id
  id_verifications       -> keyed worker_user_id, not user_id
  reviews                -> keyed author_user_id, not reviewer_user_id

The last three are the ones a table-name audit misses: the table is right and
the filter is wrong, which fails exactly as silently.

A category that cannot be counted now fails the request rather than shrinking
the total, since a partial disclosure understates what is held. Verified both
ways against a live stack: 14 when healthy, and 500 naming the category when one
count is broken.

Platform feedback is left out of the Communications label rather than counted as
zero. logs.user_feedback is unreachable — PostgREST does not expose the `logs`
schema and it grants only postgres — so the feedback router is broken for the
same reason. Called out in the code rather than papered over.

The admin queue read core.profiles too, so every request row showed a blank name
for whoever filed it. It now reads core.users, and resolves emails through the
auth admin API since they live in auth.users.

## #653 — admin delete-user

The issue as filed said data was left behind and success reported. That was
wrong, and the truth is worse. Every relevant table cascades from core.users,
and core.users cascades from auth.users, so the hand-written cascade was
redundant — but six of its eight statements were no-ops anyway, because
`.schema("core")` applies only to the statement it is written on and the rest
addressed `public`. No result was checked, so the errors were discarded.

The two statements that did work ran first. Ten RESTRICT and NO ACTION
references then block the delete for any user who has verified a work log or
created a task or punchlist. Reproduced:

    delete from core.user_skills ...   -- succeeds
    delete from core.profile ...       -- succeeds
    delete from core.users ...         -- ERROR: violates foreign key constraint
                                       --        work_logs_verified_by_user_id_fkey

The operator saw "Failed to delete user profile" while that user's skills and
personal details were already gone, with no transaction to roll back.

Now: check the seven RESTRICT relations before writing anything and answer 409
naming what blocks it; release the three nullable verification pointers, which
are audit attributions rather than content; then delete the auth user and let
the cascade do the rest. Verified against a live stack — 409 with the profile
intact for a blocked user, 200 with a full cascade for a clean one.

## Tests

Pinned as rules rather than table names, so a rename cannot make either fail
quietly again. Confirmed non-vacuous: all seven fail against the unfixed code.

Schema guard baseline drops 45 -> 33 references, 24 -> 13 table names.
API suite 317 passed / 80 failed against 310 / 87; failure sets diffed by name,
zero newly failing.

Co-Authored-By: Claude Opus 5 <[email protected]>
@thinkclay
thinkclay merged commit 4e5e868 into main Aug 27, 2026
6 of 12 checks passed
@thinkclay
thinkclay deleted the claude/fix-ccpa-and-delete-user branch August 27, 2026 18:06
thinkclay added a commit that referenced this pull request Sep 2, 2026
…le at all

Every /v1/feedback endpoint failed for any client, for two independent reasons
(#665):

  1. PostgREST does not serve the `logs` schema. config.toml exposes auth,
     public, core, storage, data, onet, engagement and community.
  2. logs.user_feedback granted only `postgres` — no service_role, no
     authenticated. Same class as #481 and #654.

Migration 350 takes the smaller of the two routes offered in the issue: move
the table rather than expose a ninth schema. That keeps the exposed-schema list
stable across all three environments, and core is already the convention for
user-scoped data. `logs` held nothing else.

The table is empty, so nothing is migrated but the definition. SET SCHEMA
carries its indexes, constraints, RLS setting and all three policies, which
were already correct and role-scoped — select/insert to authenticated on
`user_id = auth.uid()`, ALL to service_role. What was missing was never the
policies but the grants beneath them: a policy cannot widen access past an
absent GRANT, which is why even service_role could not read it.

Verified against the running stack. Before, PostgREST answered "Could not find
the table in the schema cache". Now it resolves the table and answers 42501 for
`anon` — which is the correct outcome, since feedback requires auth and only
authenticated and service_role are granted. As `authenticated`, the count runs.

The CCPA data summary counts platform feedback again. #663 left it out of the
Communications category rather than reporting a silent zero in a statutory
disclosure; with the table reachable, the category is "Reviews, platform
feedback" and its count includes both.

Closes #665

Co-Authored-By: Claude Opus 5 <[email protected]>
thinkclay added a commit that referenced this pull request Sep 2, 2026
…le at all

Every /v1/feedback endpoint failed for any client, for two independent reasons
(#665):

  1. PostgREST does not serve the `logs` schema. config.toml exposes auth,
     public, core, storage, data, onet, engagement and community.
  2. logs.user_feedback granted only `postgres` — no service_role, no
     authenticated. Same class as #481 and #654.

Migration 350 takes the smaller of the two routes offered in the issue: move
the table rather than expose a ninth schema. That keeps the exposed-schema list
stable across all three environments, and core is already the convention for
user-scoped data. `logs` held nothing else.

The table is empty, so nothing is migrated but the definition. SET SCHEMA
carries its indexes, constraints, RLS setting and all three policies, which
were already correct and role-scoped — select/insert to authenticated on
`user_id = auth.uid()`, ALL to service_role. What was missing was never the
policies but the grants beneath them: a policy cannot widen access past an
absent GRANT, which is why even service_role could not read it.

Verified against the running stack. Before, PostgREST answered "Could not find
the table in the schema cache". Now it resolves the table and answers 42501 for
`anon` — which is the correct outcome, since feedback requires auth and only
authenticated and service_role are granted. As `authenticated`, the count runs.

The CCPA data summary counts platform feedback again. #663 left it out of the
Communications category rather than reporting a silent zero in a statutory
disclosure; with the table reachable, the category is "Reviews, platform
feedback" and its count includes both.

Closes #665

Co-Authored-By: Claude Opus 5 <[email protected]>
thinkclay added a commit that referenced this pull request Sep 2, 2026
…le at all

Every /v1/feedback endpoint failed for any client, for two independent reasons
(#665):

  1. PostgREST does not serve the `logs` schema. config.toml exposes auth,
     public, core, storage, data, onet, engagement and community.
  2. logs.user_feedback granted only `postgres` — no service_role, no
     authenticated. Same class as #481 and #654.

Migration 350 takes the smaller of the two routes offered in the issue: move
the table rather than expose a ninth schema. That keeps the exposed-schema list
stable across all three environments, and core is already the convention for
user-scoped data. `logs` held nothing else.

The table is empty, so nothing is migrated but the definition. SET SCHEMA
carries its indexes, constraints, RLS setting and all three policies, which
were already correct and role-scoped — select/insert to authenticated on
`user_id = auth.uid()`, ALL to service_role. What was missing was never the
policies but the grants beneath them: a policy cannot widen access past an
absent GRANT, which is why even service_role could not read it.

Verified against the running stack. Before, PostgREST answered "Could not find
the table in the schema cache". Now it resolves the table and answers 42501 for
`anon` — which is the correct outcome, since feedback requires auth and only
authenticated and service_role are granted. As `authenticated`, the count runs.

The CCPA data summary counts platform feedback again. #663 left it out of the
Communications category rather than reporting a silent zero in a statutory
disclosure; with the table reachable, the category is "Reviews, platform
feedback" and its count includes both.

Closes #665

Co-Authored-By: Claude Opus 5 <[email protected]>
thinkclay added a commit that referenced this pull request Sep 2, 2026
…le at all

Every /v1/feedback endpoint failed for any client, for two independent reasons
(#665):

  1. PostgREST does not serve the `logs` schema. config.toml exposes auth,
     public, core, storage, data, onet, engagement and community.
  2. logs.user_feedback granted only `postgres` — no service_role, no
     authenticated. Same class as #481 and #654.

Migration 350 takes the smaller of the two routes offered in the issue: move
the table rather than expose a ninth schema. That keeps the exposed-schema list
stable across all three environments, and core is already the convention for
user-scoped data. `logs` held nothing else.

The table is empty, so nothing is migrated but the definition. SET SCHEMA
carries its indexes, constraints, RLS setting and all three policies, which
were already correct and role-scoped — select/insert to authenticated on
`user_id = auth.uid()`, ALL to service_role. What was missing was never the
policies but the grants beneath them: a policy cannot widen access past an
absent GRANT, which is why even service_role could not read it.

Verified against the running stack. Before, PostgREST answered "Could not find
the table in the schema cache". Now it resolves the table and answers 42501 for
`anon` — which is the correct outcome, since feedback requires auth and only
authenticated and service_role are granted. As `authenticated`, the count runs.

The CCPA data summary counts platform feedback again. #663 left it out of the
Communications category rather than reporting a silent zero in a statutory
disclosure; with the table reachable, the category is "Reviews, platform
feedback" and its count includes both.

Closes #665

Co-Authored-By: Claude Opus 5 <[email protected]>
thinkclay added a commit that referenced this pull request Sep 2, 2026
…/feedback works (#712)

* feat(profiles)!: delete the employers route, which addressed a table in no schema

`GET /v1/profiles/employers/{slug}` has never returned a response. It queried
`core.employers`, and information_schema has no `employers` table in any schema
and no `employer_id` column anywhere in `core` — the route was written against
a schema that does not exist, not one that drifted. The handler also counted
jobs by `employer_id`, so there was nothing to repair toward.

`employer` in this product is an organization: `core.organizations` carries
`owner_user_id`, and `core.jobs.organization_id` is the real FK.
`GET /v1/profiles/organizations/{slug}` already does what this route appears to
want, and works (#617).

Deleted: the route, the SDK's `EmployerProfile` / `profiles.getEmployer` /
`useEmployerProfile` (Scaffald/sdk#21, pointer bumped here), the scf-core
wrapper hook and its re-export, and the five Deno tests plus the
`createTestEmployerProfile` helper that inserted into `core.employers`.

`core.employers` is dropped from BASELINE_BROKEN — with the route gone the
entry is stale, and the reference test fails on a stale entry rather than
letting it rot.

BREAKING CHANGE: `GET /v1/profiles/employers/{slug}` is gone, along with
`profiles.getEmployer`, `useEmployerProfile` and `EmployerProfile`. It never
returned a response, so no working behaviour is removed. Use
`GET /v1/profiles/organizations/{slug}` and `useOrganizationProfile`.

Closes #618

Co-Authored-By: Claude Opus 5 <[email protected]>

* fix(feedback): move user_feedback into core, so the router is reachable at all

Every /v1/feedback endpoint failed for any client, for two independent reasons
(#665):

  1. PostgREST does not serve the `logs` schema. config.toml exposes auth,
     public, core, storage, data, onet, engagement and community.
  2. logs.user_feedback granted only `postgres` — no service_role, no
     authenticated. Same class as #481 and #654.

Migration 350 takes the smaller of the two routes offered in the issue: move
the table rather than expose a ninth schema. That keeps the exposed-schema list
stable across all three environments, and core is already the convention for
user-scoped data. `logs` held nothing else.

The table is empty, so nothing is migrated but the definition. SET SCHEMA
carries its indexes, constraints, RLS setting and all three policies, which
were already correct and role-scoped — select/insert to authenticated on
`user_id = auth.uid()`, ALL to service_role. What was missing was never the
policies but the grants beneath them: a policy cannot widen access past an
absent GRANT, which is why even service_role could not read it.

Verified against the running stack. Before, PostgREST answered "Could not find
the table in the schema cache". Now it resolves the table and answers 42501 for
`anon` — which is the correct outcome, since feedback requires auth and only
authenticated and service_role are granted. As `authenticated`, the count runs.

The CCPA data summary counts platform feedback again. #663 left it out of the
Communications category rather than reporting a silent zero in a statutory
disclosure; with the table reachable, the category is "Reviews, platform
feedback" and its count includes both.

Closes #665

Co-Authored-By: Claude Opus 5 <[email protected]>

---------

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.

Admin delete-user destroys profile data on a path that then fails CCPA disclosure tells users the platform holds none of their professional data

1 participant