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): stop install-time credential source-injection in extension installers
Daniel817887d12a12
diff --git a/extensions/banana/install.sh b/extensions/banana/install.shindex 517ae48..74d6ddb 100755--- a/extensions/banana/install.sh+++ b/extensions/banana/install.sh@@ -91,42 +91,49 @@ else:# Configure MCP serverecho "→ Configuring nanobanana-mcp server..."- python3 -c "-import json, os+ # Credentials are passed as argv (never interpolated into the source string)+ # and the settings file is written atomically with 0600 permissions.+ python3 - "${SETTINGS_FILE}" "${GOOGLE_AI_API_KEY}" <<'PY'+import json, os, sys, tempfile-settings_path = '${SETTINGS_FILE}'+settings_path, api_key = sys.argv[1:3]-# Read existing settings or create newif os.path.exists(settings_path):- with open(settings_path, 'r') as f:- settings = json.load(f)+ try:+ with open(settings_path) as f:+ settings = json.load(f)+ except json.JSONDecodeError:+ settings = {}else:settings = {}-# Ensure mcpServers key exists-if 'mcpServers' not in settings:- settings['mcpServers'] = {}--# Add nanobanana-mcp server config-settings['mcpServers']['nanobanana-mcp'] = {+settings.setdefault('mcpServers', {})['nanobanana-mcp'] = {'command': 'npx','args': ['-y', '@ycse/[email protected]'],'env': {- 'GOOGLE_AI_API_KEY': '''${GOOGLE_AI_API_KEY}'''- }+ 'GOOGLE_AI_API_KEY': api_key,+ },}-# Write back-os.makedirs(os.path.dirname(settings_path), exist_ok=True)-with open(settings_path, 'w') as f:- json.dump(settings, f, indent=2)+os.makedirs(os.path.dirname(settings_path) or '.', exist_ok=True)+fd, tmp = tempfile.mkstemp(dir=os.path.dirname(settings_path) or '.', prefix='.settings.', suffix='.json')+try:+ with os.fdopen(fd, 'w') as f:+ json.dump(settings, f, indent=2)+ os.chmod(tmp, 0o600)+ os.replace(tmp, settings_path)+except Exception:+ if os.path.exists(tmp):+ os.unlink(tmp)+ raiseprint(' ✓ nanobanana-mcp configured in settings.json')-" || {+PY+ if [ $? -ne 0 ]; thenecho "✗ Could not auto-configure MCP server."echo " See: extensions/banana/docs/BANANA-SETUP.md"exit 1- }+ fifi# Install skilldiff --git a/extensions/dataforseo/install.sh b/extensions/dataforseo/install.shindex eb46700..08d357b 100755--- a/extensions/dataforseo/install.sh+++ b/extensions/dataforseo/install.sh@@ -109,48 +109,52 @@ main() {echo "→ Configuring MCP server..."FIELD_CONFIG_PATH="${SEO_SKILL_DIR}/dataforseo-field-config.json"- python3 -c "-import json, os, sys+ # Credentials are passed as argv (never interpolated into the source string)+ # and the settings file is written atomically with 0600 permissions.+ python3 - "${SETTINGS_FILE}" "${DFSE_USERNAME}" "${DFSE_PASSWORD}" "${FIELD_CONFIG_PATH}" <<'PY'+import json, os, sys, tempfile-settings_path = '${SETTINGS_FILE}'-username = '''${DFSE_USERNAME}'''-password = '''${DFSE_PASSWORD}'''-field_config = '${FIELD_CONFIG_PATH}'+settings_path, username, password, field_config = sys.argv[1:5]-# Read existing settings or create newif os.path.exists(settings_path):- with open(settings_path, 'r') as f:- settings = json.load(f)+ try:+ with open(settings_path) as f:+ settings = json.load(f)+ except json.JSONDecodeError:+ settings = {}else:settings = {}-# Ensure mcpServers key exists-if 'mcpServers' not in settings:- settings['mcpServers'] = {}--# Add DataForSEO server config-settings['mcpServers']['dataforseo'] = {+settings.setdefault('mcpServers', {})['dataforseo'] = {'command': 'npx','args': ['-y', '[email protected]'],'env': {'DATAFORSEO_USERNAME': username,'DATAFORSEO_PASSWORD': password,'ENABLED_MODULES': 'SERP,KEYWORDS_DATA,ONPAGE,DATAFORSEO_LABS,BACKLINKS,DOMAIN_ANALYTICS,BUSINESS_DATA,CONTENT_ANALYSIS,AI_OPTIMIZATION',- 'FIELD_CONFIG_PATH': field_config- }+ 'FIELD_CONFIG_PATH': field_config,+ },}-# Write back-os.makedirs(os.path.dirname(settings_path), exist_ok=True)-with open(settings_path, 'w') as f:- json.dump(settings, f, indent=2)+os.makedirs(os.path.dirname(settings_path) or '.', exist_ok=True)+fd, tmp = tempfile.mkstemp(dir=os.path.dirname(settings_path) or '.', prefix='.settings.', suffix='.json')+try:+ with os.fdopen(fd, 'w') as f:+ json.dump(settings, f, indent=2)+ os.chmod(tmp, 0o600)+ os.replace(tmp, settings_path)+except Exception:+ if os.path.exists(tmp):+ os.unlink(tmp)+ raiseprint(' ✓ MCP server configured in settings.json')-" || {+PY+ if [ $? -ne 0 ]; thenecho " ⚠ Could not auto-configure MCP server."echo " Add the dataforseo server manually to ~/.claude/settings.json"echo " See: extensions/dataforseo/docs/DATAFORSEO-SETUP.md"- }+ fi# Pre-warm npm package without starting the MCP server binary.echo "→ Pre-downloading dataforseo-mcp-server..."diff --git a/extensions/firecrawl/install.sh b/extensions/firecrawl/install.shindex 6c00a68..de94c63 100755--- a/extensions/firecrawl/install.sh+++ b/extensions/firecrawl/install.sh@@ -81,43 +81,49 @@ main() {# Merge MCP config into settings.jsonecho "-> Configuring MCP server..."- python3 -c "-import json, os, sys+ # Credentials are passed as argv (never interpolated into the source string)+ # and the settings file is written atomically with 0600 permissions.+ python3 - "${SETTINGS_FILE}" "${FIRECRAWL_API_KEY}" <<'PY'+import json, os, sys, tempfile-settings_path = '${SETTINGS_FILE}'-api_key = '''${FIRECRAWL_API_KEY}'''+settings_path, api_key = sys.argv[1:3]-# Read existing settings or create newif os.path.exists(settings_path):- with open(settings_path, 'r') as f:- settings = json.load(f)+ try:+ with open(settings_path) as f:+ settings = json.load(f)+ except json.JSONDecodeError:+ settings = {}else:settings = {}-# Ensure mcpServers key exists-if 'mcpServers' not in settings:- settings['mcpServers'] = {}--# Add Firecrawl server config-settings['mcpServers']['firecrawl-mcp'] = {+settings.setdefault('mcpServers', {})['firecrawl-mcp'] = {'command': 'npx','args': ['-y', '[email protected]'],'env': {- 'FIRECRAWL_API_KEY': api_key- }+ 'FIRECRAWL_API_KEY': api_key,+ },}-# Write back-os.makedirs(os.path.dirname(settings_path), exist_ok=True)-with open(settings_path, 'w') as f:- json.dump(settings, f, indent=2)+os.makedirs(os.path.dirname(settings_path) or '.', exist_ok=True)+fd, tmp = tempfile.mkstemp(dir=os.path.dirname(settings_path) or '.', prefix='.settings.', suffix='.json')+try:+ with os.fdopen(fd, 'w') as f:+ json.dump(settings, f, indent=2)+ os.chmod(tmp, 0o600)+ os.replace(tmp, settings_path)+except Exception:+ if os.path.exists(tmp):+ os.unlink(tmp)+ raiseprint(' v MCP server configured in settings.json')-" || {+PY+ if [ $? -ne 0 ]; thenecho " Warning: Could not auto-configure MCP server."echo " Add the firecrawl-mcp server manually to ~/.claude/settings.json"echo " See: extensions/firecrawl/docs/FIRECRAWL-SETUP.md"- }+ fi# Pre-warm npm package without starting the MCP server binary.echo "-> Pre-downloading firecrawl-mcp..."diff --git a/tests/test_extension_installer_injection.py b/tests/test_extension_installer_injection.pynew file mode 100644index 0000000..962589e--- /dev/null+++ b/tests/test_extension_installer_injection.py@@ -0,0 +1,68 @@+"""Regression: extension installers must not source-inject credentials.++Before the fix, the DataForSEO / Firecrawl / Banana shell installers+interpolated user-supplied credentials directly into a ``python3 -c``+source string, so a credential containing ``'''`` broke out of the string+literal and executed arbitrary code at install time. The fix passes+credentials as ``sys.argv`` via a quoted heredoc and writes the+credential-bearing settings file atomically with ``0600`` perms.+"""++from __future__ import annotations++import json+import re+import subprocess+import sys+from pathlib import Path++import pytest++ROOT = Path(__file__).resolve().parents[1]++# rel path -> number of argv slots the heredoc consumes (incl. settings path)+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+}++_HEREDOC_RE = re.compile(r"<<'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)++[email protected]("rel,argc", INSTALLERS.items())+def test_installer_uses_safe_credential_pattern(rel: str, argc: int) -> 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 "<<'PY'" in text, f"{rel} missing quoted heredoc"+ assert "sys.argv" in text, f"{rel} not reading credentials from argv"+ assert "0o600" in text, f"{rel} not writing settings with 0600 perms"++[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")++ 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)++ 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"