review: validate SSH host alias + rename LAST30DAYS_YT_SSH_HOST -> LAST30DAYS_YOUTUBE_SSH_HOST
Addresses two concerns surfaced during PR #376 review: 1. **SSH option-injection on the host value.** The original PR uses shlex.quote() on the remote command and added a `--` option terminator in front of the host, but neither one stops a hostile env var like `LAST30DAYS_YT_SSH_HOST=-oProxyCommand=...` from being read in the first place. Tighten `_ytdlp_ssh_host()` to validate the host against `^[a-zA-Z0-9._-]+$` (plain hostname/SSH-config-alias shape: letters, digits, dot, underscore, hyphen). Any value that doesn't match logs a warning to stderr and returns None, so the wrap function falls back to local execution. The `--` terminator stays as defense-in-depth for the case where a valid host happens to start with `-`, but the regex closes the door on the env var reaching ssh at all. 2. **Env var naming consistency.** Existing skill-internal config knobs spell out their domain: `LAST30DAYS_X_BACKEND`, `LAST30DAYS_X_MODEL`, `LAST30DAYS_PLANNER_MODEL`, `LAST30DAYS_RERANK_MODEL`, etc. The module is `youtube_yt.py`, the source key is `youtube`, the function family is `is_youtube_*()` — `YT` was the odd abbreviation out. Rename to `LAST30DAYS_YOUTUBE_SSH_HOST` so the variable matches the user mental model ("route YouTube fetches via residential IP") and the codebase's spelled-out convention. Adds three new tests: - test_host_alias_with_dash_prefix_is_rejected (validator rejects `-o...`) - test_host_alias_with_shell_metacharacters_is_rejected (rejects spaces, ;, $, `, &) - test_host_alias_validator_accepts_realistic_aliases (allows FQDNs, IPs, bare aliases) The existing test_wrap_cmd_uses_option_terminator is rewritten to use a valid host value (since an invalid one is now filtered upstream) and continues to assert the `--` terminator placement as defense-in-depth. 44/44 youtube_yt tests pass (40 prior + 4 net new validator tests).
This commit is contained in:
+1
-1
@@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Added
|
||||
|
||||
- `LAST30DAYS_YT_SSH_HOST` env var: when set, yt-dlp YouTube search invocations are routed through `ssh <host>` for residential-IP egress. Bypasses YouTube's bot-wall on datacenter IPs (Hetzner/DigitalOcean/AWS) where `ytsearch:` returns 0 results regardless of cookies (the IP fingerprint is checked first). The named host must be configured in `~/.ssh/config` and have yt-dlp installed. The transcript path is unchanged (uses the existing HTTP fallback when SSH-routing is on, since the timedtext API isn't bot-walled).
|
||||
- `LAST30DAYS_YOUTUBE_SSH_HOST` env var: when set, yt-dlp YouTube search invocations are routed through `ssh <host>` for residential-IP egress. Bypasses YouTube's bot-wall on datacenter IPs (Hetzner/DigitalOcean/AWS) where `ytsearch:` returns 0 results regardless of cookies (the IP fingerprint is checked first). The named host must be configured in `~/.ssh/config` and have yt-dlp installed. Host value is validated against `^[a-zA-Z0-9._-]+$` to reject SSH option-injection (e.g. a leading `-` masquerading as a flag). The transcript path is unchanged (uses the existing HTTP fallback when SSH-routing is on, since the timedtext API isn't bot-walled).
|
||||
|
||||
### Changed
|
||||
|
||||
|
||||
Reference in New Issue
Block a user