Validate a dev server command against the security allowlist. Extracts all commands from the shell string and checks each against the effective allowlist (global + org + project). Raises HTTPException if any command is blocked or not allowed. Args: command: The shell c
(command: str, project_dir: Path)
| 202 | |
| 203 | |
| 204 | def validate_dev_command(command: str, project_dir: Path) -> None: |
| 205 | """ |
| 206 | Validate a dev server command against the security allowlist. |
| 207 | |
| 208 | Extracts all commands from the shell string and checks each against |
| 209 | the effective allowlist (global + org + project). Raises HTTPException |
| 210 | if any command is blocked or not allowed. |
| 211 | |
| 212 | Args: |
| 213 | command: The shell command string to validate |
| 214 | project_dir: Project directory for loading project-level allowlists |
| 215 | |
| 216 | Raises: |
| 217 | HTTPException 400: If the command fails validation |
| 218 | """ |
| 219 | commands = extract_commands(command) |
| 220 | if not commands: |
| 221 | raise HTTPException( |
| 222 | status_code=400, |
| 223 | detail="Could not parse command for security validation" |
| 224 | ) |
| 225 | |
| 226 | allowed_commands, blocked_commands = get_effective_commands(project_dir) |
| 227 | |
| 228 | for cmd in commands: |
| 229 | if cmd in blocked_commands: |
| 230 | logger.warning("Blocked dev server command '%s' (in blocklist) for project dir %s", cmd, project_dir) |
| 231 | raise HTTPException( |
| 232 | status_code=400, |
| 233 | detail=f"Command '{cmd}' is blocked and cannot be used as a dev server command" |
| 234 | ) |
| 235 | if not is_command_allowed(cmd, allowed_commands): |
| 236 | logger.warning("Rejected dev server command '%s' (not in allowlist) for project dir %s", cmd, project_dir) |
| 237 | raise HTTPException( |
| 238 | status_code=400, |
| 239 | detail=f"Command '{cmd}' is not in the allowed commands list" |
| 240 | ) |
| 241 | |
| 242 | |
| 243 | # ============================================================================ |
no test coverage detected