Skip to content

Comments

feat: Separate vulnerability types from code#29

Open
farnaboldi wants to merge 3 commits intopsyray:masterfrom
farnaboldi:separate_vulnerability_types_from_code
Open

feat: Separate vulnerability types from code#29
farnaboldi wants to merge 3 commits intopsyray:masterfrom
farnaboldi:separate_vulnerability_types_from_code

Conversation

@farnaboldi
Copy link

@farnaboldi farnaboldi commented Sep 4, 2025

Separates vulnerability types from the code, allowing easier modification of existing types, the addition of new ones, and to effortless import private ones

Screenshot 2025-09-03 at 1 04 12 PM

Summary by Sourcery

Separate vulnerability type metadata from code by moving definitions into a vulnerability/ directory of JSON files with a legacy fallback, and update analysis classes to capture and store args.

New Features:

  • Externalize vulnerability definitions into separate JSON files and dynamically load them at runtime
  • Add fallback to legacy hardcoded vulnerability mappings when JSON directory is absent

Enhancements:

  • Store command-line arguments on analyzer and pipeline instances by initializing self.args in their constructors

Note

Externalizes vulnerability type metadata into vulnerability/*.json and dynamically loads them at runtime, with pipelines now storing args.

  • Config:
    • Add load_vulnerability_definitions() and _get_legacy_vulnerability_mapping(); set VULNERABILITY_MAPPING = load_vulnerability_definitions().
    • Import JSON/Path utils and simplify built-in mapping to a minimal legacy fallback.
  • Data (new vulnerability/ JSON files):
    • Add definitions for sqli, xss, auth, session, csrf, crypto, ssrf, rce, cmdi, pathtra, idor, deser, rfi, lfi, redirect, logging, data, cors, jwt, upload, debug, xxe.
  • Analysis Pipeline:
    • Store args on AdaptiveAnalysisPipeline and BatchAdaptiveAnalysis constructors for downstream use.

Written by Cursor Bugbot for commit 4ae588b. This will update automatically on new commits. Configure here.

Major architectural enhancement that makes vulnerability definitions modular and extensible:

BREAKING CHANGES:
- Vulnerability definitions moved from hardcoded config to JSON files
- New vulnerability/ directory structure with 25 vulnerability types
- Dynamic loading system with backward compatibility fallback

NEW FEATURES:
- 9 additional vulnerability types: lfi, rfi, redirect, cmdi, debug, deser, upload, cors, jwt
- Extensible system allowing custom vulnerability definitions
- JSON-based vulnerability schema for easy maintenance
- Automatic detection and loading of custom vulnerability files

ENHANCEMENTS:
- Users can now add custom vulnerabilities by creating JSON files in vulnerability/
- Vulnerability definitions separated from application logic for better maintainability
- Support for organization-specific and domain-specific vulnerability patterns
- Enhanced help system displaying all available vulnerability types

FILES ADDED:
- vulnerability/: New directory with 25 vulnerability definition files
- vulnerability/*.json: Individual JSON files for each vulnerability type

FILES MODIFIED:
- oasis/config.py: Replaced hardcoded VULNERABILITY_MAPPING with dynamic loading system

USAGE:
- Existing: oasis -i ./code -v sqli,xss,rce (unchanged)
- New types: oasis -i ./app -v jwt,cors,upload,debug
- Custom: oasis -i ./code -v customvuln (if vulnerability/customvuln.json exists)
- Mixed: oasis -i ./api -v sqli,jwt,upload,cors

This change enables OASIS to be customized for specific security requirements while maintaining full backward compatibility.
…AdaptiveAnalysis classes

Resolves AttributeError where BatchAdaptiveAnalysis object was missing 'args' attribute
needed for _should_disable_progress() function calls.

CHANGES:
- AdaptiveAnalysisPipeline.__init__: Added self.args = analyzer.args
- BatchAdaptiveAnalysis.__init__: Added self.args = pipeline.analyzer.args

This ensures proper args propagation through the class hierarchy:
SecurityAnalyzer.args -> AdaptiveAnalysisPipeline.args -> BatchAdaptiveAnalysis.args

Fixes error: "'BatchAdaptiveAnalysis' object has no attribute 'args'"
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Sep 4, 2025

Reviewer's Guide

This PR externalizes the vulnerability type definitions into separate JSON files and implements a dynamic loader with a legacy fallback in config.py, while also propagating CLI arguments into analyzer and pipeline classes.

File-Level Changes

Change Details Files
Externalize vulnerability definitions into JSON files with dynamic loading and fallback
  • Removed the large hardcoded VULNERABILITY_MAPPING from config.py
  • Added load_vulnerability_definitions() to scan and parse JSON files in vulnerability/ directory
  • Introduced _get_legacy_vulnerability_mapping() as a fallback when JSON assets are missing
  • Updated VULNERABILITY_MAPPING to call load_vulnerability_definitions()
oasis/config.py
vulnerability/*.json
Propagate CLI arguments into analyzer and pipeline objects
  • Added self.args = analyzer.args in SecurityAnalyzer initialization
  • Added self.args = pipeline.analyzer.args in AdaptiveAnalysisPipeline initialization
oasis/analyze.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `oasis/config.py:260` </location>
<code_context>
-        ],
-        'impact': 'Unauthorized actions performed on behalf of authenticated users',
-        'mitigation': 'Use CSRF tokens, SameSite cookies, and verify request origins'
+def load_vulnerability_definitions() -> Dict[str, Any]:
+    """
+    Load vulnerability definitions from JSON files in the vulnerability/ directory.
</code_context>

<issue_to_address>
Consider using logging instead of print for error reporting.

The logging module provides configurable log levels and integrates with standard logging systems, making it more suitable for production error reporting than print.

Suggested implementation:

```python
import logging

def load_vulnerability_definitions() -> Dict[str, Any]:

```

```python
    vulnerabilities = {}

    # Optionally set up basic logging configuration if not already set elsewhere
    logging.basicConfig(level=logging.INFO)

    # Get the directory containing this config.py file
    config_dir = Path(__file__).parent
    # Look for vulnerability directory relative to the project root

```

If there are any `print` statements for error reporting in the rest of the `load_vulnerability_definitions` function (or elsewhere in this file), replace them with `logging.error`, `logging.warning`, or `logging.info` as appropriate. For example:
`print("Error loading vulnerability definitions")` should become `logging.error("Error loading vulnerability definitions")`.
</issue_to_address>

### Comment 2
<location> `oasis/config.py:280` </location>
<code_context>
+        return _get_legacy_vulnerability_mapping()
+    
+    # Load all JSON files from vulnerability directory
+    for json_file in vuln_dir.glob("*.json"):
+        try:
+            vuln_key = json_file.stem  # filename without extension
+            with open(json_file, 'r', encoding='utf-8') as f:
</code_context>

<issue_to_address>
Consider handling duplicate vulnerability keys from JSON files.

Currently, entries with the same key are overwritten without notice. Consider implementing a check or warning to prevent silent overwrites when duplicate keys are encountered.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
    for json_file in vuln_dir.glob("*.json"):
        try:
            vuln_key = json_file.stem  # filename without extension
            with open(json_file, 'r', encoding='utf-8') as f:
                vuln_data = json.load(f)
                vulnerabilities[vuln_key] = vuln_data
        except (json.JSONDecodeError, FileNotFoundError, PermissionError) as e:
            # Log error but continue loading other vulnerabilities
            print(f"Warning: Could not load vulnerability definition from {json_file}: {e}")
            continue
=======
    for json_file in vuln_dir.glob("*.json"):
        try:
            vuln_key = json_file.stem  # filename without extension
            if vuln_key in vulnerabilities:
                print(f"Warning: Duplicate vulnerability key '{vuln_key}' found in {json_file}. Skipping this file to avoid overwriting existing entry.")
                continue
            with open(json_file, 'r', encoding='utf-8') as f:
                vuln_data = json.load(f)
                vulnerabilities[vuln_key] = vuln_data
        except (json.JSONDecodeError, FileNotFoundError, PermissionError) as e:
            # Log error but continue loading other vulnerabilities
            print(f"Warning: Could not load vulnerability definition from {json_file}: {e}")
            continue
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

],
'impact': 'Unauthorized actions performed on behalf of authenticated users',
'mitigation': 'Use CSRF tokens, SameSite cookies, and verify request origins'
def load_vulnerability_definitions() -> Dict[str, Any]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider using logging instead of print for error reporting.

The logging module provides configurable log levels and integrates with standard logging systems, making it more suitable for production error reporting than print.

Suggested implementation:

import logging

def load_vulnerability_definitions() -> Dict[str, Any]:
    vulnerabilities = {}

    # Optionally set up basic logging configuration if not already set elsewhere
    logging.basicConfig(level=logging.INFO)

    # Get the directory containing this config.py file
    config_dir = Path(__file__).parent
    # Look for vulnerability directory relative to the project root

If there are any print statements for error reporting in the rest of the load_vulnerability_definitions function (or elsewhere in this file), replace them with logging.error, logging.warning, or logging.info as appropriate. For example:
print("Error loading vulnerability definitions") should become logging.error("Error loading vulnerability definitions").

@psyray
Copy link
Owner

psyray commented Sep 4, 2025

Thanks for the PR
Could you fix the sourcery recommendations, then I will test.

@psyray psyray changed the title Separate vulnerability types from code feat: Separate vulnerability types from code Nov 9, 2025
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is being reviewed by Cursor Bugbot

Details

You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

analyzer: SecurityAnalyzer instance with required methods and attributes
"""
self.analyzer = analyzer
self.args = analyzer.args
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Analyzer Args Missing, Pipeline Initialization Error

AdaptiveAnalysisPipeline.__init__ tries to access analyzer.args, but SecurityAnalyzer never stores the args parameter as an instance attribute. The SecurityAnalyzer.__init__ only extracts specific attributes from args but doesn't save args itself, causing an AttributeError when AdaptiveAnalysisPipeline is instantiated.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants