Skip to content

Fix dataset visibility privacy filtering - #80

Merged
neuromechanist merged 2 commits into
devfrom
feature/dataset-visibility-privacy-fix
Jan 27, 2026
Merged

neuromechanist merged 2 commits into
devfrom
feature/dataset-visibility-privacy-fix

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

Fixes #79

Implements dataset visibility filtering to prevent users from seeing private datasets they don't own.

Changes

1. Database Migration (0006_dataset_visibility.sql)

  • Adds visibility column to datasets table ('private' or 'public')
  • Defaults to 'private' for all existing and new datasets (safe default)
  • Adds index for efficient filtering

2. Backend Filtering (datasets.ts)

Updated GET /datasets endpoint with proper visibility rules:

With --mine flag:

  • Shows only the authenticated user's own datasets (private + public)

Without --mine flag (public catalog):

  • Unauthenticated users: Only public datasets
  • Authenticated non-admin: Only public datasets
  • Admin users: All datasets (for oversight)

3. Publication Workflow (admin.ts)

  • Automated publication workflow now sets visibility='public' when making repo public
  • Manual visibility change endpoint updates both GitHub repo AND database

4. TypeScript Types (api.ts)

  • Updated Dataset interface to include visibility: "public" | "private"

5. Documentation (dataset.ts)

Updated nemar dataset list help text to clearly explain:

  • Default behavior shows only PUBLIC datasets
  • Use --mine flag to see your own datasets (including private)

Testing

Database Migration

  • Apply migration to D1 database
  • Verify all existing datasets have visibility = 'private'
  • Verify index was created

Backend

  • Test unauthenticated nemar dataset list - should only show public datasets
  • Test authenticated non-admin nemar dataset list - should only show public datasets
  • Test authenticated non-admin nemar dataset list --mine - should show only their datasets
  • Test admin nemar dataset list - should show all datasets

Publication Workflow

  • Create a private dataset
  • Verify non-owner cannot see it in nemar dataset list
  • Run publication workflow
  • Verify database visibility updated to 'public'
  • Verify non-owner can now see it in nemar dataset list

Impact

Before:

  • All users could see all private datasets (critical security issue)

After:

  • Users can only see:
    • Their own datasets (with --mine)
    • Public datasets (without --mine)
  • Admins can see all datasets
  • Default to private for new datasets

Deployment

  1. Deploy migration:

    wrangler d1 migrations apply nemar-db --remote
  2. Deploy backend:

    cd backend
    npm run deploy
  3. Verify all existing datasets are private:

    wrangler d1 execute nemar-db --remote --command "SELECT dataset_id, visibility FROM datasets LIMIT 10"

Built with Claude Code

- Add migration to create visibility column (private/public)
- Fix list endpoint to filter datasets by visibility
- Update publication workflow to set visibility=public
- Update TypeScript types to include visibility field
- Default all datasets to private for security

Fixes critical security issue where all users could see
all private datasets regardless of ownership.
Critical fixes:
- Add visibility check to GET /datasets/:id endpoint
- Add comprehensive error handling for database visibility updates
- Add rollback mechanism for failed database updates in admin endpoints
- Surface audit log failures to users with warnings

Type design improvements:
- Make status field type-safe: 'active' | 'archived' | 'deleted'
- Add JSDoc documentation for status and visibility fields
- Add runtime validation for Dataset type with validateDataset()
- Apply validation in listDatasets() to catch backend errors

Documentation improvements:
- Clarify sandbox exclusion behavior in backend comments
- Add admin privilege exception in CLI help text
- Document defense-in-depth client-side filtering rationale
- Expand JSDoc comments in datasets.ts

Error handling improvements:
- Wrap database queries in try-catch with proper error responses
- Validate query results before use
- Add detailed error messages for debugging
- Include action_required field for manual intervention

All changes verified to compile without new TypeScript errors.
@github-actions

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR80

Version: 0.3.7-PR80.74abe52
Commit: 74abe52


🤖 Updated on each push.

@neuromechanist
neuromechanist merged commit 791079c into dev Jan 27, 2026
@neuromechanist
neuromechanist deleted the feature/dataset-visibility-privacy-fix branch January 27, 2026 22:01

This branch was previously deployed

1 inactive deployment
npm — 74abe527 Deployed Jan 27, 2026 by neuromechanist
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.

1 participant