Merged
Conversation
Add test_atomic_security.py covering: - atomic_svc.py: hashlib.md5() calls must use usedforsecurity=False for FIPS compliance - Atomic test YAML files: parseability and required fields validation (attack_technique, atomic_tests) - Payloads directory existence check
There was a problem hiding this comment.
Pull request overview
Adds a new security-focused pytest module to the Atomic plugin test suite, aimed at catching FIPS-incompatible hashlib.md5() usage and validating expected Atomic plugin data/layout.
Changes:
- Add AST-based test to require
usedforsecurity=Falseonhashlib.md5()calls inatomic_svc.pyfor FIPS compliance. - Add tests to validate Atomic Red Team YAML presence/shape and parseability.
- Add test asserting the plugin
payloads/directory exists.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+94
to
+100
| def test_yaml_files_exist(self): | ||
| """The atomic data directory should contain YAML test definitions.""" | ||
| yaml_files = self._get_atomic_yaml_files() | ||
| assert len(yaml_files) > 0, ( | ||
| f"No YAML files found in {ATOMICS_DIR} — " | ||
| f"run 'git submodule update --init' to populate data" | ||
| ) |
Comment on lines
+46
to
+74
| def test_md5_calls_use_usedforsecurity_false(self): | ||
| """All hashlib.md5() calls must pass usedforsecurity=False. | ||
|
|
||
| On FIPS-enabled systems, hashlib.md5() raises ValueError unless | ||
| usedforsecurity=False is explicitly set. Since these hashes are | ||
| used for payload naming (not cryptographic security), they should | ||
| be annotated accordingly. | ||
| """ | ||
| md5_calls = self._find_md5_calls() | ||
| for call_node in md5_calls: | ||
| keyword_names = [kw.arg for kw in call_node.keywords] | ||
| has_usedforsecurity = 'usedforsecurity' in keyword_names | ||
| if has_usedforsecurity: | ||
| for kw in call_node.keywords: | ||
| if kw.arg == 'usedforsecurity': | ||
| assert ( | ||
| isinstance(kw.value, ast.Constant) | ||
| and kw.value.value is False | ||
| ), ( | ||
| f"hashlib.md5() at line {call_node.lineno} has " | ||
| f"usedforsecurity set to a non-False value" | ||
| ) | ||
| break | ||
| else: | ||
| pytest.fail( | ||
| f"hashlib.md5() at line {call_node.lineno} in atomic_svc.py " | ||
| f"is missing usedforsecurity=False — required for FIPS " | ||
| f"compliance" | ||
| ) |
Comment on lines
+7
to
+11
| PLUGIN_DIR = os.path.join(os.path.dirname(__file__), '..') | ||
| ATOMIC_SVC_PATH = os.path.join(PLUGIN_DIR, 'app', 'atomic_svc.py') | ||
| PAYLOADS_DIR = os.path.join(PLUGIN_DIR, 'payloads') | ||
| DATA_DIR = os.path.join(PLUGIN_DIR, 'data') | ||
| ATOMICS_DIR = os.path.join(DATA_DIR, 'atomic-red-team', 'atomics') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tests/test_atomic_security.pywith security-focused tests for the atomic pluginhashlib.md5()calls inatomic_svc.pyincludeusedforsecurity=Falsefor FIPS complianceattack_technique,atomic_tests)payloadsdirectory existsTest plan
pytest plugins/atomic/tests/test_atomic_security.py -vfrom caldera rootusedforsecurity=Falseneeds to be added tohashlib.md5()calls