π OpenHands: AI-Driven Development
fix: logger with more masking of sensitive data (#2470)
tobiteged2509a19c892
diff --git a/opendevin/core/config.py b/opendevin/core/config.pyindex e17a3f7b24..fd67b1f292 100644--- a/opendevin/core/config.py+++ b/opendevin/core/config.py@@ -224,7 +224,12 @@ class AppConfig(metaclass=Singleton):attr_name = f.nameattr_value = getattr(self, f.name)- if attr_name in ['e2b_api_key', 'github_token']:+ if attr_name in [+ 'e2b_api_key',+ 'github_token',+ 'jwt_secret',+ 'ssh_password',+ ]:attr_value = '******' if attr_value else Noneattr_str.append(f'{attr_name}={repr(attr_value)}')diff --git a/opendevin/core/logger.py b/opendevin/core/logger.pyindex 340a7ec955..a20610535a 100644--- a/opendevin/core/logger.py+++ b/opendevin/core/logger.py@@ -81,6 +81,8 @@ class SensitiveDataFilter(logging.Filter):'aws_secret_access_key','e2b_api_key','github_token',+ 'jwt_secret',+ 'ssh_password',]# add env var names@@ -88,7 +90,9 @@ class SensitiveDataFilter(logging.Filter):sensitive_patterns.extend(env_vars)# and some special cases+ sensitive_patterns.append('JWT_SECRET')sensitive_patterns.append('LLM_API_KEY')+ sensitive_patterns.append('GITHUB_TOKEN')sensitive_patterns.append('SANDBOX_ENV_GITHUB_TOKEN')# this also formats the message with % argsdiff --git a/tests/unit/test_config.py b/tests/unit/test_config.pyindex f01680c591..9ab65cf2da 100644--- a/tests/unit/test_config.py+++ b/tests/unit/test_config.py@@ -315,9 +315,15 @@ def test_api_keys_repr_str():llm=llm_config,agent=agent_config,e2b_api_key='my_e2b_api_key',+ jwt_secret='my_jwt_secret',+ ssh_password='my_ssh_password',)assert "e2b_api_key='******'" in repr(app_config)assert "e2b_api_key='******'" in str(app_config)+ assert "jwt_secret='******'" in repr(app_config)+ assert "jwt_secret='******'" in str(app_config)+ assert "ssh_password='******'" in repr(app_config)+ assert "ssh_password='******'" in str(app_config)# Check that no other attrs in AppConfig have 'key' or 'token' in their name# This will fail when new attrs are added, and attract attentiondiff --git a/tests/unit/test_logging.py b/tests/unit/test_logging.pyindex db8ec35ff6..8a585acda3 100644--- a/tests/unit/test_logging.py+++ b/tests/unit/test_logging.py@@ -102,6 +102,7 @@ def test_sensitive_env_vars_masking(test_handler):'AWS_SECRET_ACCESS_KEY': 'AWS_SECRET_ACCESS_KEY_VALUE','E2B_API_KEY': 'E2B_API_KEY_VALUE','GITHUB_TOKEN': 'GITHUB_TOKEN_VALUE',+ 'JWT_SECRET': 'JWT_SECRET_VALUE',}log_message = ' '.join(