fix: security hardening and input validation improvements#14
Merged
Conversation
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>
There was a problem hiding this comment.
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.tsand applies it acrossconvert,identify, andsteps runto validate--metadata,--webhook-url, and source inputs before SDK calls. - Adds
--forcetotypes export -owith 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.
- 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issue
Closes #10
OPSX Change
openspec/changes/archive/2026-04-06-issue-10-security-hardening/input-validation(new),error-ux-missing-input(modified)Changes Summary
src/validators.ts(new): Centralized validation module withparseJsonFlag(),validateUrl(), andvalidateSource()src/commands/convert.ts: Apply all three validatorssrc/commands/identify.ts: ApplyvalidateSource()src/commands/steps/run.ts: Apply all three validatorssrc/commands/types/export.ts: Add--forceflag and file overwrite protectionAcceptance Criteria
--metadata '{"invalid'shows clear error instead of crash with stack trace--webhook-urlvalidates URL format before sending to SDKtypes export -o file.jsonwarns if file exists (--forceto overwrite)Testing
validators.ts(all functions, valid and invalid inputs)convertcommand validationidentifycommand validationsteps runvalidation (added to existing test file)types export --forceflagBreaking Changes
types export -onow requires--forceto overwrite existing files (acceptable in v0.1.x)🤖 Generated with Claude Code