diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a52346ab..38b1cf8d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,7 +58,7 @@ jobs: - name: Regression suites run: bash tests/run-tests.sh - # Blocking audit. Narrow advisory waivers are documented in the script. + # Block on production vulnerabilities or an incomplete audit. - name: npm audit gate run: python3 scripts/npm-audit-gate.py diff --git a/.github/workflows/claude.yml b/.github/workflows/claude.yml index b1a3201d..0cda4539 100644 --- a/.github/workflows/claude.yml +++ b/.github/workflows/claude.yml @@ -12,11 +12,14 @@ on: jobs: claude: + # Only the repository owner may ask the bot to act on public threads. if: | - (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) || - (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) || - (github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) || - (github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude'))) + github.actor == github.repository_owner && ( + (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) || + (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) || + (github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) || + (github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude'))) + ) runs-on: ubuntu-latest permissions: contents: read diff --git a/claude-terminal/CHANGELOG.md b/claude-terminal/CHANGELOG.md index 76f6d5c4..ebd9f3ee 100644 --- a/claude-terminal/CHANGELOG.md +++ b/claude-terminal/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 2.5.8 + +### 🐛 Bug Fix - Login Notifications +- Reassemble wrapped Claude login links from tmux and skip incomplete OAuth links when posting Home Assistant notifications. + +### 🔧 Technical - GitHub CLI +- Install GitHub CLI from Alpine's signed package repository to avoid GitHub API rate limits during image builds. + ## 2.5.7 ### ✨ New Feature - Paste Button diff --git a/claude-terminal/Dockerfile b/claude-terminal/Dockerfile index 8b68f45e..bb214e63 100644 --- a/claude-terminal/Dockerfile +++ b/claude-terminal/Dockerfile @@ -5,6 +5,7 @@ FROM ghcr.io/home-assistant/base:3.24 # Install packages in a single layer to minimize image size # Node.js and npm kept for image-service dependency. ttyd and tmux are baked in # (they used to be apk-installed on every boot) so startup never needs the network. +# Install gh from Alpine too, so its build does not depend on GitHub API limits. # apk upgrade first: the base image is only as fresh as its last publish, and # Alpine ships security fixes as package revisions in between. RUN apk upgrade --no-cache \ @@ -23,6 +24,7 @@ RUN apk upgrade --no-cache \ jq \ yq \ git \ + github-cli \ vim \ wget \ tree \ @@ -111,26 +113,6 @@ RUN ADDON_ARCH=$(cat /etc/addon-arch); \ chmod +x /usr/bin/ha && \ echo "Home Assistant CLI ${HA_VERSION} installed successfully" -# Install GitHub CLI (gh command), latest release -RUN ADDON_ARCH=$(cat /etc/addon-arch); \ - case "${ADDON_ARCH}" in \ - amd64) GH_ARCH="amd64"; GH_VERSION="latest" ;; \ - aarch64) GH_ARCH="arm64"; GH_VERSION="latest" ;; \ - *) echo "Unsupported architecture for gh: ${ADDON_ARCH}" && exit 1 ;; \ - esac && \ - if [ "${GH_VERSION}" = "latest" ]; then \ - echo "Fetching latest GitHub CLI version..."; \ - GH_VERSION=$(curl -fsSL https://api.github.com/repos/cli/cli/releases/latest | jq -r '.tag_name' | sed 's/^v//'); \ - fi && \ - echo "Installing GitHub CLI v${GH_VERSION} for ${GH_ARCH}..." && \ - curl -fsSL -o /tmp/gh.tar.gz \ - "https://github.com/cli/cli/releases/download/v${GH_VERSION}/gh_${GH_VERSION}_linux_${GH_ARCH}.tar.gz" && \ - tar -xzf /tmp/gh.tar.gz -C /tmp && \ - mv /tmp/gh_${GH_VERSION}_linux_${GH_ARCH}/bin/gh /usr/bin/gh && \ - chmod +x /usr/bin/gh && \ - rm -rf /tmp/gh* && \ - echo "GitHub CLI v${GH_VERSION} installed successfully" - # Home Assistant plugin for Claude Code (current HA syntax, YAML checks after # every edit). Pinned to a release tag of ESJavadex/claude-homeassistant-plugins # and installed from this local copy on first start (setup_ha_plugin in run.sh), diff --git a/claude-terminal/config.yaml b/claude-terminal/config.yaml index 6272af8c..cb37e38f 100644 --- a/claude-terminal/config.yaml +++ b/claude-terminal/config.yaml @@ -1,7 +1,7 @@ --- name: "Claude Terminal Pro" description: "Enhanced terminal interface for Anthropic's Claude Code CLI with persistent auth, package management, and image paste support. Fork of heytcass/home-assistant-addons" -version: "2.5.7" +version: "2.5.8" slug: "claude_terminal_pro" init: false diff --git a/claude-terminal/scripts/login-url-watcher.sh b/claude-terminal/scripts/login-url-watcher.sh index 32d9127e..0f4c85da 100644 --- a/claude-terminal/scripts/login-url-watcher.sh +++ b/claude-terminal/scripts/login-url-watcher.sh @@ -19,24 +19,44 @@ SUPERVISOR_URL="${LOGIN_WATCHER_SUPERVISOR_URL:-http://supervisor}" # Rebuild the URL from the pane. Claude hard-wraps it with real line breaks # (which capture-pane -J does not rejoin) and may indent it or draw a border -# round it, so take the URL characters from the first line and from each -# following line until a blank one. Only the OAuth authorize link counts: +# round it, so join following rows that contain only a URL fragment. +# Only a complete OAuth authorize link counts: # Remote Control session links and doc links are also claude.ai URLs. extract_url() { tmux capture-pane -p -J -t claude -S -500 2>/dev/null | awk ' - $0 ~ /https:\/\/(claude\.(com|ai)|console\.anthropic\.com|platform\.claude\.com)\/[^ ]*oauth\/authorize/ { - match($0, /https:\/\/[A-Za-z0-9._~:\/?#@!$&()*+,;=%-]*/) + function strip_border(line) { + sub(/^[[:space:]]*(│[[:space:]]*)?/, "", line) + sub(/[[:space:]]*(│[[:space:]]*)?$/, "", line) + return line + } + match($0, /https:\/\/(claude\.(com|ai)|console\.anthropic\.com|platform\.claude\.com)\/([A-Za-z0-9_-]+\/)*oauth\/authorize\?[A-Za-z0-9._~:\/?@!$&*+,;=%-]*/) { url = substr($0, RSTART, RLENGTH) - collecting = 1 + tail = strip_border(substr($0, RSTART + RLENGTH)) + truncated = (tail ~ /^…/) + collecting = (tail == "") next } collecting { - if (NF == 0) { collecting = 0 } - else if (match($0, /[A-Za-z0-9._~:\/?#@!$&()*+,;=%-]+/)) { - url = url substr($0, RSTART, RLENGTH) + chunk = strip_border($0) + if (chunk ~ /^[A-Za-z0-9._~:\/?@!$&*+,;=%-]+$/ && chunk !~ /:\/\// && url !~ /\.\.\.$/) { + url = url chunk + } else { + if (chunk ~ /^[A-Za-z0-9._~:\/?@!$&*+,;=%-]*…$/) truncated = 1 + collecting = 0 + } + } + END { + if (!truncated && url !~ /(\.\.\.|%[0-9A-Fa-f]?|[?&=])$/) { + query = substr(url, index(url, "?") + 1) + count = split(query, params, "&") + for (i = 1; i <= count; i++) { + if (params[i] ~ /^redirect_uri=.+/) redirect = 1 + if (params[i] ~ /^code_challenge=.+/) challenge = 1 + if (params[i] ~ /^state=.+/) state = 1 + } + if (redirect && challenge && state) print url } } - END { print url } ' } diff --git a/scripts/npm-audit-gate.py b/scripts/npm-audit-gate.py index bfc5dec2..f444ba22 100644 --- a/scripts/npm-audit-gate.py +++ b/scripts/npm-audit-gate.py @@ -3,24 +3,8 @@ Run locally with: python3 scripts/npm-audit-gate.py -Fails if the production dependency tree has any vulnerability, except the -explicitly waived advisories below. A waiver must always come with a reason -and a review date, otherwise delete it and fix the dependency instead. - -Waived advisories: - - GHSA-vfj7-8cjw-p6xm (CVE-2026-93687): braces <= 3.0.3 stack-exhaustion - DoS while compiling a deeply nested glob pattern. There is no fixed - release and upstream has stated none is planned; every maintained - version of http-proxy-middleware (2.x, 3.x, 4.x) pulls braces via - micromatch, so this cannot be resolved by upgrading either. - Not exploitable here: the add-on never passes attacker-controlled glob - patterns to braces. Express mounts the proxy at '/terminal', and the - proxy uses its default literal '/' filter rather than glob matching. - Reviewed: 2026-10-15. - - GHSA-fc5q-39xc-vjpf: picomatch ReDoS while compiling repeated extglobs. - No patched release is available. The same proxy configuration above - never compiles a glob: request URLs are candidate paths, not patterns. - Recheck for an upstream fix: 2026-12-17. +Fails if the production dependency audit reports a vulnerability or cannot +complete. """ import json @@ -29,40 +13,41 @@ from pathlib import Path SERVICE_DIR = Path(__file__).resolve().parent.parent / "claude-terminal" / "image-service" -WAIVED = {"GHSA-vfj7-8cjw-p6xm", "GHSA-fc5q-39xc-vjpf"} subprocess.run( ["npm", "install", "--package-lock-only", "--ignore-scripts"], cwd=SERVICE_DIR, check=True, capture_output=True, ) -# npm audit exits non-zero when it finds vulnerabilities, which is expected -# here: the gate itself decides whether they are waived or blocking -audit = json.loads( - subprocess.run( - ["npm", "audit", "--omit=dev", "--json"], - cwd=SERVICE_DIR, capture_output=True, text=True, - ).stdout +# npm audit can exit 1 for findings or for registry errors. Only a complete +# audit report can pass the gate, even if npm returned JSON for the error. +result = subprocess.run( + ["npm", "audit", "--omit=dev", "--json"], + cwd=SERVICE_DIR, capture_output=True, text=True, ) - -advisories = set() -for vuln in audit.get("vulnerabilities", {}).values(): - for via in vuln.get("via", []): - if isinstance(via, dict) and via.get("url"): - advisories.add(via["url"].rsplit("/", 1)[-1]) - -if not advisories: - print("npm audit: no known vulnerabilities in production dependencies") - sys.exit(0) - -unwaived = sorted(advisories - WAIVED) -for adv in sorted(advisories & WAIVED): - print(f"waived {adv} (documented in this script's header)") - -if unwaived: - print("\nFAIL: unwaived vulnerabilities in production dependencies:") - for adv in unwaived: - print(f" {adv} - https://github.com/advisories/{adv}") - print("\nFix them, or extend the waiver with a reason and review date.") +try: + audit = json.loads(result.stdout) +except ValueError: + sys.exit("FAIL: npm audit did not return a JSON report") + +if ( + result.returncode not in (0, 1) + or not isinstance(audit, dict) + or "error" in audit + or not isinstance(audit.get("vulnerabilities"), dict) +): + sys.exit("FAIL: npm audit did not return a complete vulnerability report") + +vulnerabilities = audit["vulnerabilities"] +if vulnerabilities: + print("FAIL: npm audit found vulnerabilities in production dependencies:") + for name, finding in sorted(vulnerabilities.items()): + print(f" {name}: {finding['severity']}") + for via in finding["via"]: + if isinstance(via, dict) and via.get("url"): + print(f" {via['url']}") sys.exit(1) -print("\nnpm audit gate passed (only waived advisories present)") +if result.returncode != 0: + sys.exit("FAIL: npm audit exited unsuccessfully without reporting vulnerabilities") + +print("npm audit: no known vulnerabilities in production dependencies") diff --git a/tests/test-login-url-watcher.sh b/tests/test-login-url-watcher.sh index 4a71a4c9..ec06678b 100755 --- a/tests/test-login-url-watcher.sh +++ b/tests/test-login-url-watcher.sh @@ -39,19 +39,37 @@ curl() { fi } -link='https://claude.com/cai/oauth/authorize?code=true&client_id=abc&state=STATE1' +link='https://claude.com/cai/oauth/authorize?code=true&client_id=abc&redirect_uri=https%3A%2F%2Fclaude.com%2Foauth%2Fcode%2Fcallback&code_challenge=challenge&state=STATE1' # A URL hard-wrapped across lines, indented and inside a border, is rebuilt whole cat > "$pane" << 'PANE' Browser didn't open? Use the url below to sign in: │ https://claude.com/cai/oauth/authorize?code=true&cl │ - │ ient_id=abc&state=STATE1 │ + │ ient_id=abc&redirect_uri=https%3A%2F%2Fclaude.com%2 │ + │ Foauth%2Fcode%2Fcallback&code_challenge=challenge&s │ + │ tate=STATE1 │ + │ │ Paste code here if prompted > PANE [ "$(extract_url)" = "$link" ] || fail "wrapped bordered URL rebuilt wrong: $(extract_url)" +printf 'Help: https://example.com then %s\nPaste code here if prompted >\n' "$link" > "$pane" +[ "$(extract_url)" = "$link" ] || fail "should extract the OAuth URL and stop at the prompt" + +# A newer login may render only its first row. Do not fall back to an older +# URL in scrollback or post a partial one. +printf '%s\n\n%s\nPaste code here if prompted >\n' "$link" "${link%%&redirect_uri=*}" > "$pane" +[ -z "$(extract_url)" ] || fail "missing redirect_uri should suppress the notification" + +for suffix in '&state=' '...' '…' '%2'; do + printf '%s%s\n' "${link%&state=*}" "$suffix" > "$pane" + [ -z "$(extract_url)" ] || fail "missing state should suppress the notification" + printf '%s%s\n' "$link" "$suffix" > "$pane" + [ -z "$(extract_url)" ] || fail "truncated URL should suppress the notification" +done + printf 'nothing to see here\n' > "$pane" [ -z "$(extract_url)" ] || fail "no URL should give empty output"