Skip to content

Restrict local imports to registered uploads - #4308

Merged
bcotrim merged 2 commits into
trunkfrom
mognet/review-code-scanning-alert-221
Jul 23, 2026
Merged

Restrict local imports to registered uploads#4308
bcotrim merged 2 commits into
trunkfrom
mognet/review-code-scanning-alert-221

Conversation

@bcotrim

@bcotrim bcotrim commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Related issues

  • Related to code scanning alert #221

How AI was used in this PR

Codex helped inspect the CodeQL taint flow, implement the upload registry, and run automated verification. I reviewed the diff and manually confirmed that fabricated upload paths are rejected.

Proposed Changes

  • Restrict local-web imports and cleanup to backup files created by the current server, preventing request-supplied paths from reaching filesystem operations.
  • Make uploaded backup paths single-use so fabricated or replayed paths are rejected without affecting the normal import flow.

Testing Instructions

  1. Build the CLI and start the local API server from this branch:

    npm run cli:build
    npm run cli:build:ui
    node apps/cli/dist/cli/main.mjs ui --no-open
  2. In another terminal, get the ID of an existing Studio site:

    SITE_ID=$(curl -sS http://127.0.0.1:8081/api/sites | jq -r '.[0].id')
    echo "$SITE_ID"
  3. Submit an import request with a fabricated upload path:

    curl -i -X POST \
      -H 'Content-Type: application/json' \
      -d '{"path":"/tmp/studio-upload-fake/backup.sql"}' \
      "http://127.0.0.1:8081/api/sites/$SITE_ID/import"
  4. Confirm the response is HTTP/1.1 400 Bad Request with:

    {"error":"Unknown backup path"}
  5. Start the local web UI with npm run dev:local --workspace=apps/ui, open http://localhost:5400, import a backup through Add site → Import from a backup, and confirm the normal import flow still completes.

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
@bcotrim bcotrim self-assigned this Jul 23, 2026
@bcotrim
bcotrim requested review from a team and wojtekn July 23, 2026 10:56
@wpmobilebot

wpmobilebot commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing ce4a1c3 vs trunk

app-size

Metric trunk ce4a1c3 Diff Change
App Size (Mac) 1362.04 MB 1362.04 MB 0.00 MB ⚪ 0.0%

site-editor

Metric trunk ce4a1c3 Diff Change
load 1081 ms 1093 ms +12 ms ⚪ 0.0%

site-startup

Metric trunk ce4a1c3 Diff Change
siteCreation 7011 ms 7012 ms +1 ms ⚪ 0.0%
siteStartup 2354 ms 2351 ms 3 ms ⚪ 0.0%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff)

@nightnei nightnei left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left 1 NIT comment

LGTM and works as expected:

  1. Screenshot 2026-07-23 at 17 25 46
  2. And the import works well too
Comment thread apps/local/src/index.ts Outdated
@bcotrim
bcotrim enabled auto-merge (squash) July 23, 2026 16:38
@bcotrim
bcotrim merged commit 8f7f574 into trunk Jul 23, 2026
13 checks passed
@bcotrim
bcotrim deleted the mognet/review-code-scanning-alert-221 branch July 23, 2026 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants