fix(plugins): enforce strict validation and integrity checks for missing custom parser #1812 - #2041
Merged
utksh1 merged 2 commits intoJul 20, 2026
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens SecuScan’s plugin-loading and integrity-verification flow by treating output.parser == "custom" without a corresponding parser.py as an invalid plugin, preventing broken/tampered plugins from being loaded and failing later at execution time.
Changes:
- Make
_validate_pluginemit an error and hard-fail validation when a custom parser is declared butparser.pyis missing. - Extend
compute_plugin_digestwithrequire_parserto raiseFileNotFoundErrorwhen a custom parser is required but absent, and wire this into_verify_plugin_integrity. - Add a dedicated unit test suite covering validation failures, digest behavior, and integrity verification when
parser.pyis removed post-metadata load.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| backend/secuscan/plugins.py | Enforces custom-parser presence at validation time and strengthens integrity hashing to fail loudly when required files are missing. |
| testing/backend/unit/test_plugins_validation.py | Adds regression tests for missing custom parser handling and integrity verification behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("parser_type", ["default", "json", "regex", "builtin"]) |
|
|
||
|
|
||
| def test_non_custom_parser_plugin_loads_via_load_plugins(tmp_path): | ||
| make_plugin(tmp_path, "builtin-ok", parser_type="default", parser_content=None, checksum=None) |
Comment on lines
+231
to
+233
| plugin_dir = make_plugin( | ||
| tmp_path, "builtin-digest", parser_type="default", parser_content=None, checksum=None | ||
| ) |
utksh1
approved these changes
Jul 20, 2026
utksh1
left a comment
Owner
There was a problem hiding this comment.
Excellent security fix. This properly enforces validation for custom parsers by:
- Upgrading soft warning to hard failure in _validate_plugin
- Adding require_parser flag to compute_plugin_digest with FileNotFoundError
- Double-assertion in _verify_plugin_integrity to catch TOCTOU
- 240 lines of comprehensive test coverage (15 tests covering happy path, failures, race conditions, backward compat)
All CI passing. Merging.
This was referenced Jul 20, 2026
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.
📝 Description
Fixes #1812. This PR replaces the soft-warning behavior with a hard validation failure during the plugin loading phase when a plugin explicitly sets
output.parser == 'custom'but the physicalparser.pyfile is missing from its directory. This prevents invalid/broken plugins from silently loading and crashing downstream at execution time.🛠️ Key Changes
backend/secuscan/plugins.py(_validate_plugin):logger.warningto a explicitlogger.error.Falseearly to guarantee the plugin framework skips loading the broken instance.compute_plugin_digest:require_parser: bool = Falsedefensive keyword argument.FileNotFoundErrorif a custom parser is missing instead of hashing an empty fallback digest string._verify_plugin_integrity:require_parser=(plugin.output.get("parser") == "custom").🧪 Testing & Verification
testing/backend/unit/test_plugins_validation.pycontaining 15 unit tests.parser.pyis removed post-metadata parsing.default,json,regex,builtin) continue working seamlessly without a local file presence.