fix(security): validate trashDir to prevent SSH command injection (fixes #35)#39
Conversation
iamlukethedev#53) Adds regex validation for baseDir, workspaceDir, and managedSkillsDir in the skill removal endpoint. These values are passed as SSH positional arguments and should only contain safe filesystem characters. Uses the same safe-path pattern established in PR iamlukethedev#39 for trashDir validation, ensuring consistency across all SSH-facing inputs.
iamlukethedev
left a comment
There was a problem hiding this comment.
I don't think this PR should be merged as-is.
The new trashDir regex is too strict and can reject valid restore paths, especially when the OpenClaw state directory is overridden to a path containing spaces. Both restore implementations already do the important safety check by resolving the path and verifying that it stays under the OpenClaw state directory, so this API-layer validation can introduce false negatives for legitimate restores.
Please revise the fix so it protects the SSH execution path without rejecting valid filesystem paths, and add a test that covers restoring from a valid trashDir under a state directory whose path includes spaces.
|
Suggested direction for a safer fix:
I’d also audit the other |
Adds regex validation for the
trashDirparameter in the PUT handler of/api/gateway/agent-state/route.ts. The value is now checked against^[a-zA-Z0-9_.~\/-]+$before being passed to SSH commands, preventing shell metacharacter injection.Fixes #35.