Skip to content

fix: harden Squad input handling - #2543

Merged
tamirdresher merged 6 commits into
devfrom
squad/2538-codeql-remediation
Nov 19, 2026
Merged

tamirdresher merged 6 commits into
devfrom
squad/2538-codeql-remediation

Conversation

@tamirdresher

Copy link
Copy Markdown
Collaborator

What

Harden CLI and SDK input handling to address the product-side CodeQL alerts blocking Squad 2.0.0 promotion.

Why

Relates to #2538. Inputs used in generated configuration, remote detection, text parsing, and self-upgrade commands need safe handling without changing normal upgrade behavior.

How

Escape generated strings and Markdown, validate remote hosts and upgrade selections, and replace pathological regular expressions with linear parsing. The release-workflow and script changes are in a separate PR. The changeset belongs on dev; the sanitized 2.0.0 promotion tree must omit unconsumed changesets.

Validation was run on the combined remediation worktree before the PRs were separated:

  • SKIP_BUILD_BUMP=1 npm run build: passed.
  • npm run lint: passed.
  • npm run lint:eslint: passed with existing warnings.
  • npx --no-install vitest run test/resolution.test.ts test/cli/doctor.test.ts test/migrate.test.ts test/migration.test.ts --maxWorkers=2 --testTimeout=30000 --hookTimeout=30000: passed, 156 tests.
  • The full npm test was not run locally; CI must run it. A longer targeted state-backend run was interrupted before the branch split and is not claimed as passing.

⚠️ Quick Check

  • If SDK/CLI source files changed: completed the applicable Changeset step below (npx changeset add / .changeset/*.md, direct CHANGELOG.md entry for maintainers, or skip-changelog label for no user-facing changes)

PR Readiness Checklist

The PR readiness bot will validate these automatically after push.
Check each item before requesting review. See CONTRIBUTING.md for full details.

Branch & Commit

  • Branch created from dev (not main)
  • Branch is up to date with dev (git fetch upstream && git rebase upstream/dev)
  • Verified diff contains only intended changes (git diff --cached --stat)
  • PR is not in draft mode (mark ready when checks pass)
  • Commit history is clean (squash fixups before review)

Build & Test

  • npm run build passes
  • npm test passes (all tests green)
  • npm run lint passes (type check clean)
  • npm run lint:eslint passes
  • For migration PRs (>20 files): include test output summary in PR description

The full-suite checkbox awaits CI. The user approved the >20-file release remediation.

Changeset

  • Changeset added via npx changeset add (if packages/squad-sdk/src/ or packages/squad-cli/src/ changed)
  • Or direct CHANGELOG.md entry (maintainers only — write-protected for external contributors)
  • Or skip-changelog label applied (if no user-facing changes)

The changeset was written directly in the repository format.

Docs

  • README section updated (if new feature/module)
  • Docs feature page (if new user-facing capability)

N/A: no new feature or capability.

Exports

  • package.json subpath exports updated (if new module)

N/A: no new module or export.


Breaking Changes

Malformed or spoofed Azure remote URLs no longer select the Azure adapter. Unsupported self-upgrade selections fail explicitly.

Waivers

None requested. Required CI must pass before merge.

Relates to #2538

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI adaptive review requested due to automatic review settings November 19, 2026 12:50
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🟠 Impact Analysis — PR #2543

Risk tier: 🟠 HIGH

📊 Summary

Metric Count
Files changed 28
Files added 1
Files modified 27
Files deleted 0
Modules touched 4
Critical files 1

🎯 Risk Factors

  • 28 files changed (21-50 → HIGH)
  • 4 modules touched (2-4 → MEDIUM)
  • Critical files touched: packages/squad-cli/src/cli/shell/index.ts

📦 Modules Affected

root (1 file)
  • .changeset/secure-release-paths.md
squad-cli (5 files)
  • packages/squad-cli/src/cli/commands/doctor.ts
  • packages/squad-cli/src/cli/commands/migrate.ts
  • packages/squad-cli/src/cli/core/team-md.ts
  • packages/squad-cli/src/cli/core/upgrade.ts
  • packages/squad-cli/src/cli/shell/index.ts
squad-sdk (13 files)
  • packages/squad-sdk/src/agents/onboarding.ts
  • packages/squad-sdk/src/backend/durable-http-backend.ts
  • packages/squad-sdk/src/casting/handwritten-registry.ts
  • packages/squad-sdk/src/client/adapters/apply.ts
  • packages/squad-sdk/src/client/adapters/coordinator.ts
  • packages/squad-sdk/src/config/init.ts
  • packages/squad-sdk/src/config/team-capabilities.ts
  • packages/squad-sdk/src/platform/comms-teams.ts
  • packages/squad-sdk/src/platform/detect.ts
  • packages/squad-sdk/src/ralph/triage.ts
  • packages/squad-sdk/src/resolution.ts
  • packages/squad-sdk/src/state-backend.ts
  • packages/squad-sdk/src/storage/in-memory-storage-provider.ts
tests (9 files)
  • test/clients.test.ts
  • test/comms-teams.test.ts
  • test/init-scaffolding.test.ts
  • test/init-sdk.test.ts
  • test/migrate.test.ts
  • test/platform-adapter.test.ts
  • test/profile-boundary.test.ts
  • test/ralph-triage.test.ts
  • test/team-capabilities.test.ts

⚠️ Critical Files

  • packages/squad-cli/src/cli/shell/index.ts

This report is generated automatically for every PR. See #733 for details.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🛫 PR Readiness Check

ℹ️ This comment updates on each push. Last checked: commit 19a1780

PR Scope: 📦🔧 Mixed (product + infrastructure)

⚠️ 2 item(s) to address before review

Status Check Details
❌ Single commit 6 commits — consider squashing before review
✅ Not in draft Ready for review
✅ Branch up to date Up to date with dev
❌ Copilot review No Copilot review yet — it may still be processing
✅ Changeset present Changeset file found
✅ Scope clean No .squad/ or docs/proposals/ files
✅ No merge conflicts No merge conflicts
✅ Copilot threads resolved All 1 Copilot thread(s) resolved
✅ CI passing All checks passing

Files Changed (28 files, +691 −122)

File +/−
.changeset/secure-release-paths.md +8 −0
packages/squad-cli/src/cli/commands/doctor.ts +1 −1
packages/squad-cli/src/cli/commands/migrate.ts +12 −7
packages/squad-cli/src/cli/core/team-md.ts +8 −1
packages/squad-cli/src/cli/core/upgrade.ts +8 −7
packages/squad-cli/src/cli/shell/index.ts +6 −1
packages/squad-sdk/src/agents/onboarding.ts +22 −7
packages/squad-sdk/src/backend/durable-http-backend.ts +3 −1
packages/squad-sdk/src/casting/handwritten-registry.ts +15 −4
packages/squad-sdk/src/client/adapters/apply.ts +12 −3
packages/squad-sdk/src/client/adapters/coordinator.ts +5 −2
packages/squad-sdk/src/config/init.ts +73 −44
packages/squad-sdk/src/config/team-capabilities.ts +26 −4
packages/squad-sdk/src/platform/comms-teams.ts +19 −1
packages/squad-sdk/src/platform/detect.ts +25 −6
packages/squad-sdk/src/ralph/triage.ts +44 −8
packages/squad-sdk/src/resolution.ts +89 −18
packages/squad-sdk/src/state-backend.ts +8 −4
packages/squad-sdk/src/storage/in-memory-storage-provider.ts +2 −1
test/clients.test.ts +1 −1
test/comms-teams.test.ts +5 −0
test/init-scaffolding.test.ts +2 −0
test/init-sdk.test.ts +98 −0
test/migrate.test.ts +76 −0
test/platform-adapter.test.ts +27 −0
test/profile-boundary.test.ts +83 −1
test/ralph-triage.test.ts +9 −0
test/team-capabilities.test.ts +4 −0

Total: +691 −122


This check runs automatically on every push. Fix any ❌ items and push again.
See CONTRIBUTING.md and PR Requirements for details.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🏗️ Architectural Review

Authoritative evidence: scanners from the PR base commit, posted by the default-branch workflow_run reporter.
Results for head commit 19a17809eb1bc2e92d0747ba3d0e526379ad01c8.

⚠️ Architectural review: 2 warning(s).

Severity Category Finding Files
🟡 warning bootstrap-area 2 file(s) in the bootstrap area (packages/squad-cli/src/cli/core/) were modified. These files must maintain zero external dependencies. Review carefully. packages/squad-cli/src/cli/core/team-md.ts, packages/squad-cli/src/cli/core/upgrade.ts
🟡 warning sweeping-refactor This PR touches 28 files (28 modified/added, 0 deleted). Large PRs are harder to review — consider splitting if possible. —

Automated architectural review — informational only.

tamirdresher and others added 2 commits November 19, 2026 14:57
Relates to #2538

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Relates to #2538

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI 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.

🟡 Changes recommended

The migration generator still interpolates unescaped Markdown values, which can produce invalid squad.config.ts or allow crafted values to execute when the configuration is loaded.

1 open issue
What changed in this PR

This PR hardens input handling across Squad’s CLI and SDK as part of the Squad 2.0.0 release remediation.

Changes:

  • Escape generated configuration and Markdown, validate Azure remote hosts, and restrict self-upgrade selections.
  • Replace several complex regular expressions with explicit string scanning.
  • Add targeted regression coverage and a CLI/SDK patch changeset.
File Description
test/​team-capabilities.test.ts Tests backslash escaping and malformed HTML comments.
test/​platform-adapter.test.ts Covers spoofed Azure hosts and valid SSH remotes.
test/​init-sdk.test.ts Checks generated configuration preserves escaped project metadata.
test/​init-scaffolding.test.ts Adds invalid SemVer greeting cases.
test/​comms-teams.test.ts Tests single-pass entity decoding and nested markup.
test/​clients.test.ts Simplifies an expected-value assertion without changing coverage.
packages/​squad-sdk/​src/​storage/​in-memory-storage-provider.ts Simplifies trailing-slash removal after path normalization.
packages/​squad-sdk/​src/​state-backend.ts Removes trailing slashes with explicit scanning.
packages/​squad-sdk/​src/​resolution.ts Trims project-key edge hyphens without complex matching.
packages/​squad-sdk/​src/​ralph/​triage.ts Scans Markdown links and simplifies routing token matching.
packages/​squad-sdk/​src/​platform/​detect.ts Validates remote protocols and hosts before selecting Azure.
packages/​squad-sdk/​src/​platform/​comms-teams.ts Scans HTML tags and decodes entities once.
packages/​squad-sdk/​src/​config/​team-capabilities.ts Strengthens comment removal and Markdown escaping.
packages/​squad-sdk/​src/​config/​init.ts Escapes generated metadata and updates version and remote parsing.
packages/​squad-sdk/​src/​client/​adapters/​coordinator.ts Extracts headings using prefix checks.
packages/​squad-sdk/​src/​client/​adapters/​apply.ts Simplifies TOML matching and trailing-line-break handling.
packages/​squad-sdk/​src/​casting/​handwritten-registry.ts Simplifies agent-ID and universe-metadata parsing.
packages/​squad-sdk/​src/​backend/​durable-http-backend.ts Scans trailing URL slashes explicitly.
packages/​squad-sdk/​src/​agents/​onboarding.ts Replaces the routing-array regex with string scanning.
packages/​squad-cli/​src/​cli/​shell/​index.ts Detects quota errors through line-based scanning.
packages/​squad-cli/​src/​cli/​core/​upgrade.ts Restricts upgrade selections and reuses host-based remote detection.
packages/​squad-cli/​src/​cli/​core/​team-md.ts Removes coding-agent sections using explicit boundaries.
packages/​squad-cli/​src/​cli/​commands/​migrate.ts Strengthens JavaScript string-literal escaping.
packages/​squad-cli/​src/​cli/​commands/​doctor.ts Simplifies trailing-separator matching on resolved paths.
.changeset/​secure-release-paths.md Records patch releases for the CLI and SDK hardening.

Review effort: Max (adaptive)

tamirdresher and others added 2 commits November 19, 2026 16:24
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Reject legacy team roots before accessing profile paths, while preserving fail-closed alias resolution. Closes #2538

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Comment thread packages/squad-sdk/src/config/init.ts Resolved
Escape agent-derived configuration values and resolve profile links without following them into retired trees. Closes #2538

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@tamirdresher
tamirdresher merged commit cbaef50 into dev Nov 19, 2026
31 checks passed
@tamirdresher tamirdresher mentioned this pull request Nov 19, 2026
11 of 17 tasks
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.

3 participants