Skip to content

fix: security hardening and input validation improvements#14

Merged
rarce merged 2 commits into
mainfrom
feat/issue-10-security-hardening
Apr 6, 2026
Merged

fix: security hardening and input validation improvements#14
rarce merged 2 commits into
mainfrom
feat/issue-10-security-hardening

Conversation

@rarce
Copy link
Copy Markdown
Contributor

@rarce rarce commented Apr 6, 2026

Related Issue

Closes #10

OPSX Change

  • Archived to: openspec/changes/archive/2026-04-06-issue-10-security-hardening/
  • Specs synced: input-validation (new), error-ux-missing-input (modified)

Changes Summary

  • src/validators.ts (new): Centralized validation module with parseJsonFlag(), validateUrl(), and validateSource()
  • src/commands/convert.ts: Apply all three validators
  • src/commands/identify.ts: Apply validateSource()
  • src/commands/steps/run.ts: Apply all three validators
  • src/commands/types/export.ts: Add --force flag and file overwrite protection

Acceptance Criteria

  • --metadata '{"invalid' shows clear error instead of crash with stack trace
  • --webhook-url validates URL format before sending to SDK
  • types export -o file.json warns if file exists (--force to overwrite)
  • Nonexistent source files show descriptive error before calling SDK
  • Validations centralized in reusable helpers

Testing

  • 13 unit tests for validators.ts (all functions, valid and invalid inputs)
  • 6 integration tests for convert command validation
  • 2 integration tests for identify command validation
  • 3 integration tests for steps run validation (added to existing test file)
  • 3 integration tests for types export --force flag
  • All 61 tests passing, build clean

Breaking Changes

  • types export -o now requires --force to overwrite existing files (acceptable in v0.1.x)

🤖 Generated with Claude Code

Add centralized input validation for CLI flags and arguments:
- Validate --metadata JSON before passing to SDK
- Validate --webhook-url format (http/https only)
- Check source file existence before readFileSync
- Add --force flag to types export to prevent accidental overwrites

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens CLI input handling by centralizing validation for JSON flags, webhook URLs, and source file arguments, and adds output overwrite protection for types export to prevent accidental data loss.

Changes:

  • Introduces src/validators.ts and applies it across convert, identify, and steps run to validate --metadata, --webhook-url, and source inputs before SDK calls.
  • Adds --force to types export -o with a preflight check to prevent overwriting existing files by default.
  • Adds/updates unit + integration tests and updates OpenSpec specs to document the new validation behavior.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/validators.ts New centralized validators for JSON, URLs, and file/URL sources
src/commands/convert.ts Uses validators instead of inline parsing/checks
src/commands/identify.ts Uses validateSource before reading files
src/commands/steps/run.ts Uses validators for metadata, webhook URL, and source
src/commands/types/export.ts Adds --force and blocks overwrite by default
test/validators.test.ts Unit tests for validator helpers
test/commands/convert.test.ts Integration tests for convert validation failures
test/commands/identify.test.ts Integration tests for identify source validation
test/commands/steps/run.test.ts Adds validation-related integration tests
test/commands/types/export.test.ts Tests overwrite protection and --force
openspec/specs/input-validation/spec.md New/updated spec documenting validation requirements
openspec/specs/error-ux-missing-input/spec.md Updates error UX spec to include validation errors
openspec/changes/archive/** Archived change artifacts (proposal/design/spec snapshots/tasks)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/validators.ts Outdated
Comment thread src/validators.ts
Comment thread src/commands/types/export.ts
- Validate parseJsonFlag returns a plain object, rejecting arrays/primitives/null
- Return original URL from validateUrl instead of normalized toString()
- Detect directory as --output path in types export with dedicated error

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@rarce rarce merged commit 81e3601 into main Apr 6, 2026
@rarce rarce deleted the feat/issue-10-security-hardening branch April 6, 2026 23:16
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.

fix: security hardening and input validation improvements

2 participants