Skip to content

Commit aa452aa

Browse files
committed
removed redundant sanitise helper
Signed-off-by: Ambrish Rawat <[email protected]>
1 parent 969e0da commit aa452aa

File tree

3 files changed

+16
-61
lines changed

3 files changed

+16
-61
lines changed

mellea/security/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
SecurityMetadata,
1111
SecurityError,
1212
privileged,
13-
sanitize,
1413
declassify,
1514
taint_sources,
1615
)
@@ -21,7 +20,6 @@
2120
"SecurityMetadata",
2221
"SecurityError",
2322
"privileged",
24-
"sanitize",
2523
"declassify",
2624
"taint_sources",
2725
]

mellea/security/core.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -277,26 +277,6 @@ def wrapper(*args, **kwargs):
277277
return wrapper # type: ignore
278278

279279

280-
def sanitize(cblock: CBlock) -> CBlock:
281-
"""Create a sanitized version of a CBlock (non-mutating).
282-
283-
This function creates a new CBlock with the same content but marked
284-
as safe (SecLevel.none()). The original CBlock is not modified.
285-
286-
Args:
287-
cblock: The CBlock to sanitize
288-
289-
Returns:
290-
A new CBlock with safe security level
291-
"""
292-
# Create new meta dict with safe security
293-
new_meta = cblock._meta.copy() if cblock._meta else {}
294-
new_meta['_security'] = SecurityMetadata(SecLevel.none())
295-
296-
# Return new CBlock with same content but new security metadata
297-
return CBlock(cblock.value, new_meta)
298-
299-
300280
def declassify(cblock: CBlock) -> CBlock:
301281
"""Create a declassified version of a CBlock (non-mutating).
302282

test/stdlib_basics/test_security_comprehensive.py

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
SecurityMetadata,
99
SecurityError,
1010
privileged,
11-
sanitize,
1211
declassify,
1312
taint_sources
1413
)
@@ -115,30 +114,8 @@ def has_access(self, entitlement: str | None) -> bool:
115114
assert not cblock.is_safe(None)
116115

117116

118-
class TestSanitizeDeclassify:
119-
"""Test sanitize and declassify functions."""
120-
121-
def test_sanitize_creates_new_object(self):
122-
"""Test that sanitize creates a new object without mutating original."""
123-
original = CBlock("test content")
124-
original.mark_tainted()
125-
126-
sanitized = sanitize(original)
127-
128-
# Objects are different
129-
assert original is not sanitized
130-
assert id(original) != id(sanitized)
131-
132-
# Content is preserved
133-
assert original.value == sanitized.value
134-
135-
# Security levels are different
136-
assert not original.is_safe()
137-
assert sanitized.is_safe()
138-
assert sanitized._meta["_security"].sec_level.level_type == "none"
139-
140-
# Original is unchanged
141-
assert original._meta["_security"].is_tainted()
117+
class TestDeclassify:
118+
"""Test declassify function."""
142119

143120
def test_declassify_creates_new_object(self):
144121
"""Test that declassify creates a new object without mutating original."""
@@ -162,16 +139,16 @@ def test_declassify_creates_new_object(self):
162139
# Original is unchanged
163140
assert original._meta["_security"].is_tainted()
164141

165-
def test_sanitize_preserves_other_metadata(self):
166-
"""Test that sanitize preserves other metadata."""
142+
def test_declassify_preserves_other_metadata(self):
143+
"""Test that declassify preserves other metadata."""
167144
original = CBlock("test content", meta={"custom": "value", "other": 123})
168145
original.mark_tainted()
169146

170-
sanitized = sanitize(original)
147+
declassified = declassify(original)
171148

172-
assert sanitized._meta["custom"] == "value"
173-
assert sanitized._meta["other"] == 123
174-
assert sanitized._meta["_security"].sec_level.level_type == "none"
149+
assert declassified._meta["custom"] == "value"
150+
assert declassified._meta["other"] == 123
151+
assert declassified._meta["_security"].sec_level.level_type == "none"
175152

176153

177154
class TestPrivilegedDecorator:
@@ -189,17 +166,17 @@ def safe_function(cblock: CBlock) -> str:
189166
result = safe_function(safe_cblock)
190167
assert result == "Processed: safe content"
191168

192-
def test_privileged_accepts_sanitized_input(self):
193-
"""Test that privileged functions accept sanitized input."""
169+
def test_privileged_accepts_declassified_input(self):
170+
"""Test that privileged functions accept declassified input."""
194171
@privileged
195172
def safe_function(cblock: CBlock) -> str:
196173
return f"Processed: {cblock.value}"
197174

198175
tainted_cblock = CBlock("tainted content")
199176
tainted_cblock.mark_tainted()
200-
sanitized_cblock = sanitize(tainted_cblock)
177+
declassified_cblock = declassify(tainted_cblock)
201178

202-
result = safe_function(sanitized_cblock)
179+
result = safe_function(declassified_cblock)
203180
assert result == "Processed: tainted content"
204181

205182
def test_privileged_rejects_tainted_input(self):
@@ -371,8 +348,8 @@ def test_security_flow_through_generation(self):
371348
assert not mot.is_safe()
372349
assert mot._meta["_security"].is_tainted()
373350

374-
# Sanitize the output
375-
safe_mot = sanitize(mot)
351+
# Declassify the output
352+
safe_mot = declassify(mot)
376353
assert safe_mot.is_safe()
377354
assert safe_mot._meta["_security"].sec_level.level_type == "none"
378355

@@ -398,7 +375,7 @@ def process_response(mot: ModelOutputThunk) -> str:
398375
with pytest.raises(SecurityError):
399376
process_response(mot)
400377

401-
# Sanitize and try again
402-
safe_mot = sanitize(mot)
378+
# Declassify and try again
379+
safe_mot = declassify(mot)
403380
result = process_response(safe_mot)
404381
assert result == "Processed: tainted response"

0 commit comments

Comments
 (0)