Skip to content

πŸ™Œ OpenHands: AI-Driven Development

Remove deprecated SecurityConfig class (Legacy-V0) (#14212)

Tim O'Farrell0a54ea5ae6b2
diff --git a/openhands/app_server/settings/settings_models.py b/openhands/app_server/settings/settings_models.py
index c1492a0e62..85db53e4a3 100644
--- a/openhands/app_server/settings/settings_models.py
+++ b/openhands/app_server/settings/settings_models.py
@@ -399,8 +399,8 @@ class Settings(BaseModel):
agent_settings=LLMAgentSettings(**agent_settings_dict),
conversation_settings=ConversationSettings.model_validate(
{
- 'confirmation_mode': bool(app_config.security.confirmation_mode),
- 'security_analyzer': app_config.security.security_analyzer,
+ 'confirmation_mode': False,
+ 'security_analyzer': None,
'max_iterations': app_config.max_iterations,
}
),
diff --git a/openhands/core/config/__init__.py b/openhands/core/config/__init__.py
index 368b7a1989..fb80331ec9 100644
--- a/openhands/core/config/__init__.py
+++ b/openhands/core/config/__init__.py
@@ -10,7 +10,6 @@ from openhands.core.config.llm_config import LLMConfig
from openhands.core.config.mcp_config import MCPConfig
from openhands.core.config.openhands_config import OpenHandsConfig
from openhands.core.config.sandbox_config import SandboxConfig
-from openhands.core.config.security_config import SecurityConfig
from openhands.core.config.utils import (
finalize_config,
get_llm_config_arg,
@@ -28,7 +27,6 @@ __all__ = [
'MCPConfig',
'LLMConfig',
'SandboxConfig',
- 'SecurityConfig',
'load_openhands_config',
'load_from_env',
'load_from_toml',
diff --git a/openhands/core/config/openhands_config.py b/openhands/core/config/openhands_config.py
index 2d8ec090f8..8d75104878 100644
--- a/openhands/core/config/openhands_config.py
+++ b/openhands/core/config/openhands_config.py
@@ -20,7 +20,6 @@ from openhands.core.config.config_utils import (
from openhands.core.config.llm_config import LLMConfig
from openhands.core.config.mcp_config import MCPConfig
from openhands.core.config.sandbox_config import SandboxConfig
-from openhands.core.config.security_config import SecurityConfig
class OpenHandsConfig(BaseModel):
@@ -31,7 +30,6 @@ class OpenHandsConfig(BaseModel):
The default configuration is stored under the 'llm' key.
default_agent: Name of the default agent to use.
sandbox: Sandbox configuration settings.
- security: Security configuration settings.
runtime: Runtime environment identifier.
file_store: Type of file store to use.
file_store_path: Path to the file store.
@@ -64,7 +62,6 @@ class OpenHandsConfig(BaseModel):
llms: dict[str, LLMConfig] = Field(default_factory=dict)
default_agent: str = Field(default=OH_DEFAULT_AGENT)
sandbox: SandboxConfig = Field(default_factory=SandboxConfig)
- security: SecurityConfig = Field(default_factory=SecurityConfig)
runtime: str = Field(default='docker')
file_store: str = Field(default='local')
file_store_path: str = Field(default='~/.openhands')
diff --git a/openhands/core/config/security_config.py b/openhands/core/config/security_config.py
deleted file mode 100644
index e8bc12f8fe..0000000000
--- a/openhands/core/config/security_config.py
+++ /dev/null
@@ -1,42 +0,0 @@
-# IMPORTANT: LEGACY V0 CODE - Deprecated since version 1.0.0, scheduled for removal April 1, 2026
-# This file is part of the legacy (V0) implementation of OpenHands and will be removed soon as we complete the migration to V1.
-# OpenHands V1 uses the Software Agent SDK for the agentic core and runs a new application server. Please refer to:
-# - V1 agentic core (SDK): https://github.com/OpenHands/software-agent-sdk
-# - V1 application server (in this repo): openhands/app_server/
-# Unless you are working on deprecation, please avoid extending this legacy file and consult the V1 codepaths above.
-# Tag: Legacy-V0
-from pydantic import BaseModel, ConfigDict, Field, ValidationError
-
-
-class SecurityConfig(BaseModel):
- """Configuration for security related functionalities.
-
- Attributes:
- confirmation_mode: Whether to enable confirmation mode.
- security_analyzer: The security analyzer to use.
- """
-
- confirmation_mode: bool = Field(default=False)
- security_analyzer: str | None = Field(default=None)
-
- model_config = ConfigDict(extra='forbid')
-
- @classmethod
- def from_toml_section(cls, data: dict) -> dict[str, 'SecurityConfig']:
- """Create a mapping of SecurityConfig instances from a toml dictionary representing the [security] section.
-
- The configuration is built from all keys in data.
-
- Returns:
- dict[str, SecurityConfig]: A mapping where the key "security" corresponds to the [security] configuration
- """
- # Initialize the result mapping
- security_mapping: dict[str, SecurityConfig] = {}
-
- # Try to create the configuration instance
- try:
- security_mapping['security'] = cls.model_validate(data)
- except ValidationError as e:
- raise ValueError(f'Invalid security configuration: {e}')
-
- return security_mapping
diff --git a/openhands/core/config/utils.py b/openhands/core/config/utils.py
index 81be5b3a29..66f3a51d8d 100644
--- a/openhands/core/config/utils.py
+++ b/openhands/core/config/utils.py
@@ -27,7 +27,6 @@ from openhands.core.config.llm_config import LLMConfig
from openhands.core.config.mcp_config import mcp_config_from_toml
from openhands.core.config.openhands_config import OpenHandsConfig
from openhands.core.config.sandbox_config import SandboxConfig
-from openhands.core.config.security_config import SecurityConfig
JWT_SECRET = '.jwt_secret'
load_dotenv()
@@ -194,21 +193,6 @@ def load_from_toml(cfg: OpenHandsConfig, toml_file: str = 'config.toml') -> None
f'Cannot parse [llm] config from toml, values have not been applied.\nError: {e}'
)
- # Process security section if present
- if 'security' in toml_config:
- try:
- security_mapping = SecurityConfig.from_toml_section(toml_config['security'])
- # We only use the base security config for now
- if 'security' in security_mapping:
- cfg.security = security_mapping['security']
- except (TypeError, KeyError, ValidationError) as e:
- logger.openhands_logger.warning(
- f'Cannot parse [security] config from toml, values have not been applied.\nError: {e}'
- )
- except ValueError:
- # Re-raise ValueError from SecurityConfig.from_toml_section
- raise ValueError('Error in [security] section in config.toml')
-
# Process sandbox section if present
if 'sandbox' in toml_config:
try:
@@ -238,13 +222,12 @@ def load_from_toml(cfg: OpenHandsConfig, toml_file: str = 'config.toml') -> None
raise ValueError('Error in MCP sections in config.toml')
# Check for unknown sections
- # Note: 'agent', 'extended', 'condenser', 'model_routing', and 'kubernetes'
- # are kept for backwards compatibility with old config files - they are
- # silently ignored
+ # Note: 'agent', 'extended', 'condenser', 'model_routing', 'kubernetes',
+ # and 'security' are kept for backwards compatibility with old config
+ # files - they are silently ignored
known_sections = {
'core',
'llm',
- 'security',
'sandbox',
'mcp',
'agent', # Legacy, ignored
@@ -252,6 +235,7 @@ def load_from_toml(cfg: OpenHandsConfig, toml_file: str = 'config.toml') -> None
'condenser', # Legacy, ignored
'kubernetes', # Legacy, ignored
'model_routing', # Legacy, ignored
+ 'security', # Legacy, ignored
}
for key in toml_config:
if key.lower() not in known_sections:
diff --git a/tests/unit/core/config/test_config.py b/tests/unit/core/config/test_config.py
index 6036a24440..bbf6a66e7b 100644
--- a/tests/unit/core/config/test_config.py
+++ b/tests/unit/core/config/test_config.py
@@ -331,12 +331,12 @@ def test_load_from_env_with_list(monkeypatch, default_config):
)
-def test_security_config_from_toml(default_config, temp_toml_file):
- """Test loading security specific configurations."""
+def test_security_section_in_toml_is_silently_ignored(default_config, temp_toml_file):
+ """Test that a legacy [security] section in TOML is silently ignored."""
with open(temp_toml_file, 'w', encoding='utf-8') as toml_file:
toml_file.write(
"""
-[core] # make sure core is loaded first
+[core]
workspace_base = "/opt/files/workspace"
[llm]
@@ -349,25 +349,8 @@ security_analyzer = "semgrep"
)
load_from_toml(default_config, temp_toml_file)
- assert default_config.security.confirmation_mode is False
- assert default_config.security.security_analyzer == 'semgrep'
-
-
-def test_security_config_from_dict():
- """Test creating SecurityConfig instance from dictionary."""
- from openhands.core.config.security_config import SecurityConfig
-
- # Test with all fields
- config_dict = {
- 'confirmation_mode': True,
- 'security_analyzer': 'some_analyzer',
- }
-
- security_config = SecurityConfig(**config_dict)
-
- # Verify all fields are correctly set
- assert security_config.confirmation_mode is True
- assert security_config.security_analyzer == 'some_analyzer'
+ # Security section is ignored; no error raised
+ assert default_config.get_llm_config().model == 'test-model'
def test_defaults_dict_after_updates(default_config):
@@ -489,16 +472,12 @@ model = "test-model"
timeout = 1
base_container_image = "custom_image"
user_id = 1001
-
-[security]
-security_analyzer = "semgrep"
""")
load_from_toml(default_config, temp_toml_file)
assert default_config.get_llm_config().model == 'test-model'
assert default_config.sandbox.base_container_image == 'custom_image'
assert default_config.sandbox.user_id == 1001
- assert default_config.security.security_analyzer == 'semgrep'
def test_load_from_toml_partial_invalid(default_config, temp_toml_file, caplog):
@@ -506,8 +485,8 @@ def test_load_from_toml_partial_invalid(default_config, temp_toml_file, caplog):
This ensures that:
1. Valid configuration sections are properly loaded
- 2. Invalid fields in security and sandbox sections raise ValueError
- 4. The config object maintains correct values for valid fields
+ 2. Invalid fields in sandbox sections raise ValueError
+ 3. The config object maintains correct values for valid fields
"""
with open(temp_toml_file, 'w', encoding='utf-8') as f:
f.write("""
@@ -554,23 +533,6 @@ invalid_field_in_sandbox = "test"
openhands_logger.removeHandler(handler)
-def test_load_from_toml_security_invalid(default_config, temp_toml_file):
- """Test that invalid security configuration raises ValueError."""
- with open(temp_toml_file, 'w', encoding='utf-8') as f:
- f.write("""
-[core]
-debug = true
-
-[security]
-invalid_security_field = "test"
-""")
-
- with pytest.raises(ValueError) as excinfo:
- load_from_toml(default_config, temp_toml_file)
-
- assert 'Error in [security] section in config.toml' in str(excinfo.value)
-
-
def test_finalize_config(default_config):
# Test finalize config
assert default_config.workspace_mount_path is None
diff --git a/tests/unit/storage/data_models/test_settings.py b/tests/unit/storage/data_models/test_settings.py
index 967574856a..fd6d2808a4 100644
--- a/tests/unit/storage/data_models/test_settings.py
+++ b/tests/unit/storage/data_models/test_settings.py
@@ -13,7 +13,6 @@ from openhands.app_server.settings.settings_router import LITE_LLM_API_URL
from openhands.core.config.llm_config import LLMConfig
from openhands.core.config.openhands_config import OpenHandsConfig
from openhands.core.config.sandbox_config import SandboxConfig
-from openhands.core.config.security_config import SecurityConfig
from openhands.sdk.llm import LLM
from openhands.sdk.settings import (
AGENT_SETTINGS_SCHEMA_VERSION,
@@ -27,10 +26,6 @@ def test_settings_from_config():
mock_app_config = OpenHandsConfig(
default_agent='test-agent',
max_iterations=100,
- security=SecurityConfig(
- security_analyzer='llm',
- confirmation_mode=True,
- ),
llms={
'llm': LLMConfig(
model='test-model',
@@ -51,8 +46,8 @@ def test_settings_from_config():
assert settings.language == 'en'
assert settings.agent_settings.agent == 'test-agent'
assert settings.conversation_settings.max_iterations == 100
- assert settings.conversation_settings.security_analyzer == 'llm'
- assert settings.conversation_settings.confirmation_mode is True
+ assert settings.conversation_settings.security_analyzer is None
+ assert settings.conversation_settings.confirmation_mode is False
assert settings.agent_settings.llm.model == 'test-model'
assert settings.agent_settings.llm.api_key.get_secret_value() == 'test-key'
assert settings.agent_settings.llm.base_url == 'https://test.example.com'
@@ -64,10 +59,6 @@ def test_settings_from_config_no_api_key():
mock_app_config = OpenHandsConfig(
default_agent='test-agent',
max_iterations=100,
- security=SecurityConfig(
- security_analyzer='llm',
- confirmation_mode=True,
- ),
llms={
'llm': LLMConfig(
model='test-model', api_key=None, base_url='https://test.example.com'