Skip to content

Universal SEO skill for Claude Code. 26 sub-skills + 19 sub-agents covering technical SEO, E-E-A-T, schema, GEO/AEO, agent readiness (Lighthouse Agentic Browsing, WebMCP, llms.txt), backlinks, local SEO, e-commerce, international SEO, Google APIs, and PDF/Excel reporting. 9 optional extensions for live SEO data.

fix(security): keep installer secrets out of argv and never clobber a bad config

Agrici Daniel095ca767a2d1
diff --git a/extensions/ahrefs/install.sh b/extensions/ahrefs/install.sh
index cd32e17..aee7d8b 100755
--- a/extensions/ahrefs/install.sh
+++ b/extensions/ahrefs/install.sh
@@ -51,20 +51,22 @@ main() {
# Merge MCP config into ~/.claude.json atomically.
mkdir -p "$(dirname "${MCP_CONFIG_JSON}")"
- python3 - "${MCP_CONFIG_JSON}" "${AHREFS_TOKEN}" <<'PY'
+ CLAUDE_SEO_SECRET="${AHREFS_TOKEN}" python3 - "${MCP_CONFIG_JSON}" <<'PY'
import json
import os
import sys
import tempfile
-path, token = sys.argv[1], sys.argv[2]
+# The token arrives in the environment, not argv: argv is visible to other
+# local users through ps, the environment is not.
+path, token = sys.argv[1], os.environ["CLAUDE_SEO_SECRET"]
data = {}
if os.path.exists(path):
try:
with open(path) as fh:
data = json.load(fh)
except json.JSONDecodeError:
- data = {}
+ sys.exit(f"✗ {path} is not valid JSON. Nothing was changed; fix it and rerun.")
data.setdefault("mcpServers", {})["ahrefs"] = {
"command": "npx",
"args": ["--yes", "--package=@ahrefs/[email protected]", "mcp"],
diff --git a/extensions/banana/install.sh b/extensions/banana/install.sh
index 742f218..567535b 100755
--- a/extensions/banana/install.sh
+++ b/extensions/banana/install.sh
@@ -97,17 +97,17 @@ PY
echo "→ Configuring nanobanana-mcp server..."
# Credentials are passed as argv (never interpolated into the source string)
# and the settings file is written atomically with 0600 permissions.
- python3 - "${MCP_CONFIG_FILE}" "${GOOGLE_AI_API_KEY}" <<'PY'
+ CLAUDE_SEO_SECRET="${GOOGLE_AI_API_KEY}" python3 - "${MCP_CONFIG_FILE}" <<'PY'
import json, os, sys, tempfile
-settings_path, api_key = sys.argv[1:3]
+settings_path, api_key = sys.argv[1], os.environ["CLAUDE_SEO_SECRET"]
if os.path.exists(settings_path):
try:
with open(settings_path) as f:
settings = json.load(f)
except json.JSONDecodeError:
- settings = {}
+ sys.exit(f"✗ {settings_path} is not valid JSON. Nothing was changed; fix it and rerun.")
else:
settings = {}
diff --git a/extensions/bing-webmaster/install.ps1 b/extensions/bing-webmaster/install.ps1
index cb7a3f4..b32f4fe 100644
--- a/extensions/bing-webmaster/install.ps1
+++ b/extensions/bing-webmaster/install.ps1
@@ -14,11 +14,14 @@ New-Item -ItemType Directory -Path $SkillTarget -Force | Out-Null
Copy-Item (Join-Path $SourceDir "skills/seo-bing/SKILL.md") (Join-Path $SkillTarget "SKILL.md") -Force
$py = @"
import json, os, sys, tempfile
-path, bing, idx_key, idx_loc = sys.argv[1:5]
+path = sys.argv[1]
+idx_loc = sys.argv[2] if len(sys.argv) > 2 else ''
+bing = os.environ.get('CLAUDE_SEO_SECRET', '')
+idx_key = os.environ.get('CLAUDE_SEO_INDEXNOW_KEY', '')
data = {}
if os.path.exists(path):
try: data = json.load(open(path))
- except: data = {}
+ except ValueError: sys.exit('x ' + path + ' is not valid JSON. Nothing was changed; fix it and rerun.')
env = data.setdefault('env', {})
if bing: env['BING_WEBMASTER_API_KEY'] = bing
if idx_key: env['INDEXNOW_KEY'] = idx_key
@@ -27,5 +30,7 @@ fd, tmp = tempfile.mkstemp(dir=os.path.dirname(path) or '.', prefix='.settings.'
with os.fdopen(fd, 'w') as fh: json.dump(data, fh, indent=2)
os.replace(tmp, path)
"@
-$py | python - $SettingsJson $BingPlain $IdxKey $IdxLoc
+$env:CLAUDE_SEO_SECRET = $BingPlain
+$env:CLAUDE_SEO_INDEXNOW_KEY = $IdxKey
+try { $py | python - $SettingsJson $IdxLoc } finally { Remove-Item Env:CLAUDE_SEO_SECRET -ErrorAction SilentlyContinue; Remove-Item Env:CLAUDE_SEO_INDEXNOW_KEY -ErrorAction SilentlyContinue }
Write-Host "Done."
diff --git a/extensions/bing-webmaster/install.sh b/extensions/bing-webmaster/install.sh
index 6054c5d..40e2b74 100755
--- a/extensions/bing-webmaster/install.sh
+++ b/extensions/bing-webmaster/install.sh
@@ -34,13 +34,16 @@ main() {
mkdir -p "${SKILL_DIR}/seo-bing"
cp "${SOURCE_DIR}/skills/seo-bing/SKILL.md" "${SKILL_DIR}/seo-bing/SKILL.md"
- python3 - "${SETTINGS_JSON}" "${BING_KEY}" "${INDEXNOW_KEY}" "${INDEXNOW_LOC}" <<'PY'
+ CLAUDE_SEO_SECRET="${BING_KEY}" CLAUDE_SEO_INDEXNOW_KEY="${INDEXNOW_KEY}" python3 - "${SETTINGS_JSON}" "${INDEXNOW_LOC}" <<'PY'
import json, os, sys, tempfile
-path, bing, idx_key, idx_loc = sys.argv[1:5]
+path = sys.argv[1]
+idx_loc = sys.argv[2] if len(sys.argv) > 2 else ""
+bing = os.environ.get("CLAUDE_SEO_SECRET", "")
+idx_key = os.environ.get("CLAUDE_SEO_INDEXNOW_KEY", "")
data = {}
if os.path.exists(path):
try: data = json.load(open(path))
- except json.JSONDecodeError: data = {}
+ except json.JSONDecodeError: sys.exit(f"✗ {path} is not valid JSON. Nothing was changed; fix it and rerun.")
env = data.setdefault("env", {})
if bing: env["BING_WEBMASTER_API_KEY"] = bing
if idx_key: env["INDEXNOW_KEY"] = idx_key
diff --git a/extensions/dataforseo/install.sh b/extensions/dataforseo/install.sh
index 5e02665..7ba6279 100755
--- a/extensions/dataforseo/install.sh
+++ b/extensions/dataforseo/install.sh
@@ -114,17 +114,19 @@ main() {
# Credentials are passed as argv (never interpolated into the source string)
# and the settings file is written atomically with 0600 permissions.
- python3 - "${MCP_CONFIG_FILE}" "${DFSE_USERNAME}" "${DFSE_PASSWORD}" "${FIELD_CONFIG_PATH}" <<'PY'
+ CLAUDE_SEO_USERNAME="${DFSE_USERNAME}" CLAUDE_SEO_SECRET="${DFSE_PASSWORD}" python3 - "${MCP_CONFIG_FILE}" "${FIELD_CONFIG_PATH}" <<'PY'
import json, os, sys, tempfile
-settings_path, username, password, field_config = sys.argv[1:5]
+settings_path, field_config = sys.argv[1:3]
+username = os.environ["CLAUDE_SEO_USERNAME"]
+password = os.environ["CLAUDE_SEO_SECRET"]
if os.path.exists(settings_path):
try:
with open(settings_path) as f:
settings = json.load(f)
except json.JSONDecodeError:
- settings = {}
+ sys.exit(f"✗ {settings_path} is not valid JSON. Nothing was changed; fix it and rerun.")
else:
settings = {}
diff --git a/extensions/firecrawl/install.sh b/extensions/firecrawl/install.sh
index 967c517..cbb9957 100755
--- a/extensions/firecrawl/install.sh
+++ b/extensions/firecrawl/install.sh
@@ -86,17 +86,17 @@ main() {
# Credentials are passed as argv (never interpolated into the source string)
# and the settings file is written atomically with 0600 permissions.
- python3 - "${MCP_CONFIG_FILE}" "${FIRECRAWL_API_KEY}" <<'PY'
+ CLAUDE_SEO_SECRET="${FIRECRAWL_API_KEY}" python3 - "${MCP_CONFIG_FILE}" <<'PY'
import json, os, sys, tempfile
-settings_path, api_key = sys.argv[1:3]
+settings_path, api_key = sys.argv[1], os.environ["CLAUDE_SEO_SECRET"]
if os.path.exists(settings_path):
try:
with open(settings_path) as f:
settings = json.load(f)
except json.JSONDecodeError:
- settings = {}
+ sys.exit(f"✗ {settings_path} is not valid JSON. Nothing was changed; fix it and rerun.")
else:
settings = {}
diff --git a/extensions/matomo/install.ps1 b/extensions/matomo/install.ps1
index 15dc231..3e5b0d2 100644
--- a/extensions/matomo/install.ps1
+++ b/extensions/matomo/install.ps1
@@ -37,14 +37,15 @@ Copy-Item (Join-Path $SourceDir "agents/seo-matomo.md") $AgentTarget -Force
# it. matomo_auth.py still falls back to the MATOMO_* environment variables.
if (-not (Test-Path $MatomoAuth)) { throw "$MatomoAuth not found" }
$py = @"
-import importlib.util, sys
+import importlib.util, os, sys
# PowerShell 5.1 drops an empty string argument to a native command, so the
# optional site ID may simply not arrive. Tolerate that rather than crashing
# the installer after the token has already been typed.
args = sys.argv[1:]
-auth_path, url, token = args[0], args[1], args[2]
-site = args[3] if len(args) > 3 else ""
+auth_path, url = args[0], args[1]
+site = args[2] if len(args) > 2 else ""
+token = os.environ['CLAUDE_SEO_SECRET']
spec = importlib.util.spec_from_file_location('matomo_auth', auth_path)
matomo_auth = importlib.util.module_from_spec(spec)
sys.modules['matomo_auth'] = matomo_auth
@@ -57,5 +58,6 @@ matomo_auth.save_config({
})
print('Wrote Matomo credentials to ' + matomo_auth.CONFIG_PATH)
"@
-$py | python - $MatomoAuth $MatomoUrl $TokenPlain $SiteId
+$env:CLAUDE_SEO_SECRET = $TokenPlain
+try { $py | python - $MatomoAuth $MatomoUrl $SiteId } finally { Remove-Item Env:CLAUDE_SEO_SECRET -ErrorAction SilentlyContinue }
Write-Host "Done. MATOMO_URL / MATOMO_API_TOKEN / MATOMO_SITE_ID still override the file."
\ No newline at end of file
diff --git a/extensions/matomo/install.sh b/extensions/matomo/install.sh
index e28d76f..be3b9f7 100755
--- a/extensions/matomo/install.sh
+++ b/extensions/matomo/install.sh
@@ -61,15 +61,16 @@ main() {
# business in it. matomo_auth.py still falls back to the MATOMO_*
# environment variables, which stays the right choice on a shared machine.
[ -f "${MATOMO_AUTH}" ] || { echo "✗ ${MATOMO_AUTH} not found."; exit 1; }
- python3 - "${MATOMO_AUTH}" "${MATOMO_URL}" "${MATOMO_TOKEN}" "${MATOMO_SITE_ID}" <<'PY'
-import importlib.util, sys
+ CLAUDE_SEO_SECRET="${MATOMO_TOKEN}" python3 - "${MATOMO_AUTH}" "${MATOMO_URL}" "${MATOMO_SITE_ID}" <<'PY'
+import importlib.util, os, sys
# PowerShell 5.1 drops an empty string argument to a native command, so the
# optional site ID may simply not arrive. Tolerate that rather than crashing
# the installer after the token has already been typed.
args = sys.argv[1:]
-auth_path, url, token = args[0], args[1], args[2]
-site = args[3] if len(args) > 3 else ""
+auth_path, url = args[0], args[1]
+site = args[2] if len(args) > 2 else ""
+token = os.environ["CLAUDE_SEO_SECRET"] # environment, not argv (ps)
spec = importlib.util.spec_from_file_location("matomo_auth", auth_path)
matomo_auth = importlib.util.module_from_spec(spec)
sys.modules["matomo_auth"] = matomo_auth
diff --git a/extensions/profound/install.ps1 b/extensions/profound/install.ps1
index 3574a1d..35de845 100644
--- a/extensions/profound/install.ps1
+++ b/extensions/profound/install.ps1
@@ -12,15 +12,16 @@ Copy-Item (Join-Path $SourceDir "skills/seo-profound/SKILL.md") `
(Join-Path $SkillTarget "SKILL.md") -Force
$py = @"
import json, os, sys, tempfile
-path, key = sys.argv[1], sys.argv[2]
+path, key = sys.argv[1], os.environ['CLAUDE_SEO_SECRET']
data = {}
if os.path.exists(path):
try: data = json.load(open(path))
- except: data = {}
+ except ValueError: sys.exit('x ' + path + ' is not valid JSON. Nothing was changed; fix it and rerun.')
data.setdefault('env', {})['PROFOUND_API_KEY'] = key
fd, tmp = tempfile.mkstemp(dir=os.path.dirname(path) or '.', prefix='.settings.', suffix='.json')
with os.fdopen(fd, 'w') as fh: json.dump(data, fh, indent=2)
os.replace(tmp, path)
"@
-$py | python - $SettingsJson $Plain
+$env:CLAUDE_SEO_SECRET = $Plain
+try { $py | python - $SettingsJson } finally { Remove-Item Env:CLAUDE_SEO_SECRET -ErrorAction SilentlyContinue }
Write-Host "Done."
diff --git a/extensions/profound/install.sh b/extensions/profound/install.sh
index e61418e..6fd2832 100755
--- a/extensions/profound/install.sh
+++ b/extensions/profound/install.sh
@@ -26,13 +26,13 @@ main() {
mkdir -p "${SKILL_DIR}/seo-profound"
cp "${SOURCE_DIR}/skills/seo-profound/SKILL.md" "${SKILL_DIR}/seo-profound/SKILL.md"
- python3 - "${SETTINGS_JSON}" "${PROFOUND_KEY}" <<'PY'
+ CLAUDE_SEO_SECRET="${PROFOUND_KEY}" python3 - "${SETTINGS_JSON}" <<'PY'
import json, os, sys, tempfile
-path, key = sys.argv[1], sys.argv[2]
+path, key = sys.argv[1], os.environ["CLAUDE_SEO_SECRET"]
data = {}
if os.path.exists(path):
try: data = json.load(open(path))
- except json.JSONDecodeError: data = {}
+ except json.JSONDecodeError: sys.exit(f"✗ {path} is not valid JSON. Nothing was changed; fix it and rerun.")
data.setdefault("env", {})["PROFOUND_API_KEY"] = key
fd, tmp = tempfile.mkstemp(dir=os.path.dirname(path) or ".", prefix=".settings.", suffix=".json")
with os.fdopen(fd, "w") as fh: json.dump(data, fh, indent=2)
diff --git a/extensions/seranking/install.ps1 b/extensions/seranking/install.ps1
index 45c647f..3b50229 100644
--- a/extensions/seranking/install.ps1
+++ b/extensions/seranking/install.ps1
@@ -24,16 +24,17 @@ Copy-Item -Path (Join-Path $SourceDir "skills/seo-seranking/SKILL.md") `
$pyScript = @"
import json, os, sys, tempfile
-path, key = sys.argv[1], sys.argv[2]
+path, key = sys.argv[1], os.environ['CLAUDE_SEO_SECRET']
data = {}
if os.path.exists(path):
try: data = json.load(open(path))
- except: data = {}
+ except ValueError: sys.exit('x ' + path + ' is not valid JSON. Nothing was changed; fix it and rerun.')
data.setdefault('env', {})['SERANKING_API_KEY'] = key
fd, tmp = tempfile.mkstemp(dir=os.path.dirname(path) or '.', prefix='.settings.', suffix='.json')
with os.fdopen(fd, 'w') as fh:
json.dump(data, fh, indent=2)
os.replace(tmp, path)
"@
-$pyScript | python - $SettingsJson $Plain
+$env:CLAUDE_SEO_SECRET = $Plain
+try { $pyScript | python - $SettingsJson } finally { Remove-Item Env:CLAUDE_SEO_SECRET -ErrorAction SilentlyContinue }
Write-Host "Done. Try: /seo seranking ai-visibility brandname"
diff --git a/extensions/seranking/install.sh b/extensions/seranking/install.sh
index 55860be..b68bead 100755
--- a/extensions/seranking/install.sh
+++ b/extensions/seranking/install.sh
@@ -35,13 +35,13 @@ main() {
echo "✓ Installed skill: ${SKILL_DIR}/seo-seranking/SKILL.md"
mkdir -p "$(dirname "${SETTINGS_JSON}")"
- python3 - "${SETTINGS_JSON}" "${SR_KEY}" <<'PY'
+ CLAUDE_SEO_SECRET="${SR_KEY}" python3 - "${SETTINGS_JSON}" <<'PY'
import json, os, sys, tempfile
-path, key = sys.argv[1], sys.argv[2]
+path, key = sys.argv[1], os.environ["CLAUDE_SEO_SECRET"]
data = {}
if os.path.exists(path):
try: data = json.load(open(path))
- except json.JSONDecodeError: data = {}
+ except json.JSONDecodeError: sys.exit(f"✗ {path} is not valid JSON. Nothing was changed; fix it and rerun.")
data.setdefault("env", {})["SERANKING_API_KEY"] = key
fd, tmp = tempfile.mkstemp(dir=os.path.dirname(path) or ".", prefix=".settings.", suffix=".json")
with os.fdopen(fd, "w") as fh:
diff --git a/tests/test_extension_installer_injection.py b/tests/test_extension_installer_injection.py
index ff3e8cc..55d2ad2 100644
--- a/tests/test_extension_installer_injection.py
+++ b/tests/test_extension_installer_injection.py
@@ -21,52 +21,81 @@ import pytest
ROOT = Path(__file__).resolve().parents[1]
-# rel path -> number of argv slots the heredoc consumes (incl. settings path)
+# rel path -> (extra argv after the settings path, env var carrying the secret).
+# Secrets travel in the environment: argv is readable by other local users
+# through ps, the environment of a process is not.
INSTALLERS = {
- "extensions/dataforseo/install.sh": 4, # settings, username, password, field_config
- "extensions/firecrawl/install.sh": 2, # settings, api_key
- "extensions/banana/install.sh": 2, # settings, api_key
+ "extensions/dataforseo/install.sh": (["field.json"], "CLAUDE_SEO_SECRET"),
+ "extensions/firecrawl/install.sh": ([], "CLAUDE_SEO_SECRET"),
+ "extensions/banana/install.sh": ([], "CLAUDE_SEO_SECRET"),
+ "extensions/ahrefs/install.sh": ([], "CLAUDE_SEO_SECRET"),
+ "extensions/profound/install.sh": ([], "CLAUDE_SEO_SECRET"),
+ "extensions/seranking/install.sh": ([], "CLAUDE_SEO_SECRET"),
+ "extensions/bing-webmaster/install.sh": (["https://e.test/key.txt"], "CLAUDE_SEO_SECRET"),
}
+BASE_ENV = {"CLAUDE_SEO_USERNAME": "user", "CLAUDE_SEO_INDEXNOW_KEY": "idx"}
-_HEREDOC_RE = re.compile(r"<<'PY'\n(.*?)\nPY\n", re.DOTALL)
+_HEREDOC_RE = re.compile(r"python3 - [^\n]*<<'PY'\n(.*?)\nPY\n", re.DOTALL)
def _extract_writer(text: str) -> str:
- match = _HEREDOC_RE.search(text)
- assert match, "no quoted <<'PY' heredoc found in installer"
- return match.group(1)
+ matches = [m.group(1) for m in _HEREDOC_RE.finditer(text)]
+ writers = [m for m in matches if "os.replace" in m]
+ assert writers, "no quoted <<'PY' settings writer found in installer"
+ return writers[0]
[email protected]("rel,argc", INSTALLERS.items())
-def test_installer_uses_safe_credential_pattern(rel: str, argc: int) -> None:
+def _run(tmp_path: Path, rel: str, secret: str, settings: Path):
+ extra, env_name = INSTALLERS[rel]
+ script = tmp_path / "writer.py"
+ script.write_text(_extract_writer((ROOT / rel).read_text(encoding="utf-8")), encoding="utf-8")
+ env = {**os.environ, **BASE_ENV, env_name: secret}
+ return subprocess.run([sys.executable, str(script), str(settings), *extra],
+ cwd=tmp_path, env=env, capture_output=True, text=True)
+
+
[email protected]("rel", INSTALLERS)
+def test_installer_uses_safe_credential_pattern(rel: str) -> None:
text = (ROOT / rel).read_text(encoding="utf-8")
- # The unsafe signature was a shell variable interpolated into a Python
- # triple-quoted string literal (e.g. '''${DFSE_PASSWORD}''').
- assert "'''${" not in text, f"{rel} still interpolates a credential into Python source"
+ assert "\'\'\'${" not in text, f"{rel} still interpolates a credential into Python source"
assert "<<'PY'" in text, f"{rel} missing quoted heredoc"
- assert "sys.argv" in text, f"{rel} not reading credentials from argv"
+ assert "os.environ" in text, f"{rel} not reading the secret from the environment"
assert "0o600" in text, f"{rel} not writing settings with 0600 perms"
@pytest.mark.skipif(
os.name != "posix", reason="asserts 0o600 mode bits, which Windows does not represent"
)
[email protected]("rel,argc", INSTALLERS.items())
-def test_installer_credential_injection_is_inert(tmp_path: Path, rel: str, argc: int) -> None:
- writer = _extract_writer((ROOT / rel).read_text(encoding="utf-8"))
- script = tmp_path / "writer.py"
- script.write_text(writer, encoding="utf-8")
-
[email protected]("rel", INSTALLERS)
+def test_installer_credential_injection_is_inert(tmp_path: Path, rel: str) -> None:
settings = tmp_path / "settings.json"
marker = tmp_path / "PWNED"
- payload = f"x'''; open({str(marker)!r}, 'w').write('pwned'); y='''"
-
- # settings path + credential slots; the first credential carries the payload
- argv = [sys.executable, str(script), str(settings), payload]
- argv += ["filler"] * (argc - 2)
- subprocess.run(argv, check=True, cwd=tmp_path)
-
+ payload = f"x\'\'\'; open({str(marker)!r}, 'w').write('pwned'); y=\'\'\'"
+ result = _run(tmp_path, rel, payload, settings)
+ assert result.returncode == 0, result.stderr
assert not marker.exists(), f"{rel}: credential injection executed code"
blob = json.dumps(json.loads(settings.read_text(encoding="utf-8")))
assert payload in blob, f"{rel}: credential not stored literally"
assert (settings.stat().st_mode & 0o777) == 0o600, f"{rel}: settings not 0600"
+
+
[email protected]("rel", INSTALLERS)
+def test_installer_never_overwrites_an_unparseable_config(tmp_path: Path, rel: str) -> None:
+ """A malformed ~/.claude.json or settings.json must survive untouched."""
+ settings = tmp_path / "settings.json"
+ original = '{"mcpServers": {"mine": {}}, oops'
+ settings.write_text(original, encoding="utf-8")
+ result = _run(tmp_path, rel, "secret-value", settings)
+ assert result.returncode != 0
+ assert settings.read_text(encoding="utf-8") == original
+ assert "Nothing was changed" in result.stderr
+
+
[email protected]("rel", sorted(Path(ROOT, "extensions").glob("*/install.sh")))
+def test_no_installer_passes_a_secret_on_the_command_line(rel: Path) -> None:
+ text = rel.read_text(encoding="utf-8")
+ for line in text.splitlines():
+ if "python3 -" in line and "<<'PY'" in line:
+ args = line.split("python3 -", 1)[1]
+ for word in ("KEY", "TOKEN", "PASSWORD", "SECRET"):
+ assert word not in args.split("<<")[0].replace("CONFIG", ""), (rel, line)
diff --git a/tests/test_matomo_report.py b/tests/test_matomo_report.py
index 07db3e0..691f89b 100644
--- a/tests/test_matomo_report.py
+++ b/tests/test_matomo_report.py
@@ -817,8 +817,9 @@ def test_installers_do_not_put_the_token_in_settings_json():
)
-def test_installers_pass_credentials_through_argv_not_source():
- """No credential is interpolated into a Python source string (issue #189)."""
+def test_installers_pass_credentials_through_env_not_source_or_argv():
+ """No credential is interpolated into Python source (issue #189) or put on
+ the command line, where other local users can read it through ps."""
sh = INSTALL_SH.read_text(encoding="utf-8")
assert "<<'PY'" in sh, "install.sh must use a quoted heredoc"
assert "sys.argv" in sh
@@ -826,10 +827,12 @@ def test_installers_pass_credentials_through_argv_not_source():
ps1 = INSTALL_PS1.read_text(encoding="utf-8")
# PowerShell here-strings: @" ... "@ interpolates, so the credential must
- # arrive on the pipeline as an argument, never inside the here-string.
+ # arrive in the environment, never inside the here-string or on argv.
assert "sys.argv" in ps1
assert "$TokenPlain" not in ps1.split('@"')[1].split('"@')[0]
- assert "python - $MatomoAuth $MatomoUrl $TokenPlain $SiteId" in ps1
+ assert "$env:CLAUDE_SEO_SECRET = $TokenPlain" in ps1
+ assert "python - $MatomoAuth $MatomoUrl $SiteId" in ps1
+ assert 'CLAUDE_SEO_SECRET="${MATOMO_TOKEN}" python3 -' in sh
def test_uninstall_removes_the_config_and_the_legacy_env_entry():
@@ -869,9 +872,9 @@ def test_installer_writer_is_inert_against_an_injection_shaped_token(tmp_path):
proc = subprocess.run(
[sys.executable, "-c", _installer_writer(),
str(ROOT / "scripts" / "matomo_auth.py"),
- "https://analytics.example.com", nasty, "3"],
+ "https://analytics.example.com", "3"],
capture_output=True, text=True,
- env={**os.environ, "HOME": str(home)},
+ env={**os.environ, "HOME": str(home), "CLAUDE_SEO_SECRET": nasty},
)
assert proc.returncode == 0, proc.stderr
assert not (tmp_path / "pwned").exists(), "installer executed the token"
@@ -888,9 +891,9 @@ def test_installer_writer_survives_a_dropped_optional_argument(tmp_path):
proc = subprocess.run(
[sys.executable, "-c", _installer_writer(),
str(ROOT / "scripts" / "matomo_auth.py"),
- "https://analytics.example.com", SECRET_TOKEN], # no 4th argument
+ "https://analytics.example.com"], # no site-ID argument
capture_output=True, text=True,
- env={**os.environ, "HOME": str(home)},
+ env={**os.environ, "HOME": str(home), "CLAUDE_SEO_SECRET": SECRET_TOKEN},
)
assert proc.returncode == 0, proc.stderr
stored = json.loads((home / ".config" / "claude-seo" / "matomo.json").read_text())