stage-11: security hardening
- Prompt injection protection: external messages wrapped in [EXTERNAL CONTENT] markers, system prompt instructs Claude to never follow external instructions - Invocation logging: all Claude CLI calls logged with channel, model, duration, token counts to echo-core.invoke logger - Security logging: separate echo-core.security logger for unauthorized access attempts (DMs from non-admins, unauthorized admin/owner commands) - Security log routed to logs/security.log in addition to main log - Extended echo doctor: Claude CLI functional check, config.json secret scan, .gitignore completeness, file permissions, Ollama reachability, bot process - Subprocess env stripping logged at debug level 373 tests pass (10 new security tests). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
15
src/main.py
15
src/main.py
@@ -23,15 +23,28 @@ LOG_DIR = PROJECT_ROOT / "logs"
|
||||
|
||||
def setup_logging():
|
||||
LOG_DIR.mkdir(parents=True, exist_ok=True)
|
||||
fmt = "%(asctime)s [%(levelname)s] %(name)s: %(message)s"
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
|
||||
format=fmt,
|
||||
handlers=[
|
||||
logging.FileHandler(LOG_DIR / "echo-core.log"),
|
||||
logging.StreamHandler(sys.stderr),
|
||||
],
|
||||
)
|
||||
|
||||
# Security log — separate file for unauthorized access attempts
|
||||
security_handler = logging.FileHandler(LOG_DIR / "security.log")
|
||||
security_handler.setFormatter(logging.Formatter(fmt))
|
||||
security_logger = logging.getLogger("echo-core.security")
|
||||
security_logger.addHandler(security_handler)
|
||||
|
||||
# Invocation log — all Claude CLI calls
|
||||
invoke_handler = logging.FileHandler(LOG_DIR / "echo-core.log")
|
||||
invoke_handler.setFormatter(logging.Formatter(fmt))
|
||||
invoke_logger = logging.getLogger("echo-core.invoke")
|
||||
invoke_logger.addHandler(invoke_handler)
|
||||
|
||||
|
||||
def main():
|
||||
setup_logging()
|
||||
|
||||
Reference in New Issue
Block a user