Skip to content

DSL Engine #1587

Open
Aarush289 wants to merge 31 commits into
OWASP:masterfrom
Aarush289:DSL_engine
Open

DSL Engine #1587
Aarush289 wants to merge 31 commits into
OWASP:masterfrom
Aarush289:DSL_engine

Conversation

@Aarush289

Copy link
Copy Markdown
Contributor

Proposed change

This PR introduces DSL (Domain Specific Language) support for service/version extraction in Nettacker.
(This work is derived from the DSL PR by Rishi after minor changes)
Fixes #1586

Type of change

  • New core framework functionality
  • Bugfix (non-breaking change that fixes an issue)
  • Code refactoring without any functionality changes
  • New or existing module/payload change
  • Documentation/localization improvement
  • Test coverage improvement
  • Dependency upgrade
  • Other improvement (best practice, cleanup, optimization, etc)

Checklist

  • I've followed the contributing guidelines
  • I've digitally signed all my commits in this PR
  • I've run make pre-commit and confirm it didn't generate any warnings/changes
  • I've run make test and I confirm all tests passed locally
  • I've added/updated any relevant documentation in the docs/ folder
  • I've linked this PR with an open issue
  • I've tested and verified that my code works as intended and resolves the issue as described
  • I've attached screenshots demonstrating that my code works as intended (if applicable)
  • I've checked all other open PRs to avoid submitting duplicate work
  • I confirm that the code and comments in this PR are not direct unreviewed outputs of AI
  • I confirm that I am the Sole Responsible Author for every line of code, comment, and design decision

rxerium and others added 28 commits October 19, 2025 19:59
Signed-off-by: Aarush <cs24b064@smail.iitm.ac.in>
Removed entry for FortiWeb authentication bypass vulnerability.

Signed-off-by: Aarush <cs24b064@smail.iitm.ac.in>
Signed-off-by: Aarush <cs24b064@smail.iitm.ac.in>
Signed-off-by: Aarush <cs24b064@smail.iitm.ac.in>
@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 19a41a13-16da-4fb7-9fae-932f197129c9

📥 Commits

Reviewing files that changed from the base of the PR and between d3cafd8 and 8371b67.

📒 Files selected for processing (2)
  • nettacker/core/lib/http.py
  • nettacker/core/utils/dsl_matcher.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • nettacker/core/lib/http.py
  • nettacker/core/utils/dsl_matcher.py

Summary by CodeRabbit

Release Notes

  • New Features
    • Enhanced HTTP response analysis by extracting detected versions from response content or selected headers using configurable patterns.
    • Added DSL-based version matching for extracted versions, with support for logical operators, comparisons, ranges, and wildcard/semantic matching (including optional reverse behavior).
  • Dependencies
    • Added the semver library to improve version comparison behavior.

Walkthrough

Adds a new DSLMatcher class in nettacker/core/utils/dsl_matcher.py that evaluates version-matching DSL expressions against target version strings using multiple operator types and fallback comparison strategies. Two wrapper helpers are exposed via common.py, and two new HTTP response condition types (version_match, version_dsl) are added to http.py. The semver package is added as a runtime dependency.

Changes

Version DSL Engine and HTTP Integration

Layer / File(s) Summary
DSLMatcher module, version normalization, and semver dependency
nettacker/core/utils/dsl_matcher.py, pyproject.toml
DSLMatcher class and singleton are defined; _clean_version strips v/V prefixes and extracts version substrings via regex; parse_dsl_expression is the top-level entry point with exception-to-False handling. The semver ^3.0.0 runtime dependency is added.
DSL evaluation dispatch and comparison operators
nettacker/core/utils/dsl_matcher.py
_evaluate_dsl dispatches to logical OR/AND connectors, operator-prefixed comparisons, range/wildcard/exact-match fallbacks. _compare_version chains packaging.version.Versionsemver.compare_string_version_compare. _tilde_compare, _caret_compare, _evaluate_range, _evaluate_multiple, _evaluate_wildcard, _string_version_compare, and _compare_version_parts implement each sub-evaluation path.
CVE range matching and version extraction
nettacker/core/utils/dsl_matcher.py
match_cve_version_range classifies affected-version expressions into range-operator conditions (AND) vs exact conditions (OR) and evaluates against a cleaned target. extract_version_from_response iterates regex patterns and returns the first captured group or full match.
common.py wrappers and HTTP condition integration
nettacker/core/utils/common.py, nettacker/core/lib/http.py
version_matches_dsl and extract_version_from_content are added as thin wrappers over the dsl_matcher singleton. In http.py, version_match extracts a version from content or a named response header and evaluates one DSL expression; version_dsl extracts from content and evaluates multiple DSL expressions with OR semantics and optional reverse.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title "DSL Engine" is related to the changeset but is overly vague and generic, providing minimal insight into what the pull request actually implements. Consider a more descriptive title such as "Add DSL support for service and version extraction in HTTP responses" to better convey the scope and purpose of the changes.
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly relates to the changeset by explaining that it introduces DSL support for service/version extraction, references issue #1586, and confirms all checklist items were completed.
Linked Issues check ✅ Passed The pull request successfully implements DSL engine integration for version extraction by adding version matching and extraction utilities [#1586], fully addressing the linked issue's requirement to integrate a DSL engine for improved version scanning.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing DSL engine functionality: new DSL matcher class, version matching/extraction functions, HTTP response condition types, and semver dependency addition for version comparisons.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pyproject.toml (1)

46-69: ⚠️ Potential issue | 🔴 Critical

Add missing packaging runtime dependency to resolve import error in execution paths.

nettacker/core/utils/dsl_matcher.py imports from packaging.version import Version, InvalidVersion at line 12. This module is imported by common.py (line 17), which is in turn imported across all core entry points (config.py, app.py, graph.py, http.py, etc.). The packaging library is not declared in [tool.poetry.dependencies], causing a ModuleNotFoundError when these execution paths are triggered.

Suggested fix
 [tool.poetry.dependencies]
 python = "^3.10, <3.13"
 aiohttp = "^3.9.5"
@@
 zipp = "^3.19.1"
 semver = "^3.0.0"
+packaging = "^24.0"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pyproject.toml` around lines 46 - 69, The packaging library is missing from
the runtime dependencies in pyproject.toml. Add the packaging dependency to the
[tool.poetry.dependencies] section with an appropriate version constraint. This
will ensure that when dsl_matcher.py imports from packaging.version (which is
transitively required by common.py and used across all core entry points), the
module will be available at runtime.

Source: Pipeline failures

🧹 Nitpick comments (1)
nettacker/core/utils/common.py (1)

456-493: ⚡ Quick win

Add type hints to the new public wrapper APIs.

Lines 456 and 482 expose public helpers in nettacker/core/utils/common.py but currently omit practical type hints.

Suggested update
+from typing import Iterable, Optional
@@
-def version_matches_dsl(detected_version, dsl_expression):
+def version_matches_dsl(detected_version: str, dsl_expression: str) -> bool:
@@
-def extract_version_from_content(content, patterns):
+def extract_version_from_content(
+    content: str, patterns: Iterable[str]
+) -> Optional[str]:

As per coding guidelines, nettacker/**/*.py: "Keep functions small, use type hints where practical, and add docstrings for public APIs."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@nettacker/core/utils/common.py` around lines 456 - 493, The functions
version_matches_dsl and extract_version_from_content lack type hints for their
parameters and return types. Add proper type hints to both functions: for
version_matches_dsl, add type hints indicating both detected_version and
dsl_expression are strings, and the return type is bool; for
extract_version_from_content, add type hints indicating content is a string,
patterns is a list, and the return type is an optional string. This aligns with
the coding guidelines requiring type hints for public APIs in the nettacker
module.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@nettacker/core/lib/http.py`:
- Around line 96-121: In the version_match condition block, the code lowercases
the header_name variable but fails to normalize the response headers dictionary
itself, causing case-sensitive lookup failures. When extracting the header from
response.get("headers", {}), first convert the headers dictionary to have all
lowercase keys before accessing it with header_name.lower(), so that the lookup
succeeds regardless of the original casing in the response headers (e.g.,
"Server" vs "server").

In `@nettacker/core/utils/dsl_matcher.py`:
- Around line 447-454: The exception handling in the try-except block (lines
453-454) silently catches all exceptions without logging, which hides debugging
information about invalid regex patterns or configuration issues. Add logging to
the except block that captures the actual exception details and relevant context
(such as the pattern being attempted) before executing the continue statement.
This will make it easier to diagnose why pattern matching fails during
extraction.
- Around line 442-446: The issue in the extract_version_from_response method is
that line 445 unconditionally wraps patterns in a list with patterns =
[patterns], which creates a nested list structure when callers already pass a
list of patterns. This causes re.search to receive a list instead of a string
regex pattern, breaking the matching logic. Fix this by conditionally wrapping
patterns only if it is not already a list; check if patterns is a string and
only then wrap it in a list, otherwise leave it as-is.

---

Outside diff comments:
In `@pyproject.toml`:
- Around line 46-69: The packaging library is missing from the runtime
dependencies in pyproject.toml. Add the packaging dependency to the
[tool.poetry.dependencies] section with an appropriate version constraint. This
will ensure that when dsl_matcher.py imports from packaging.version (which is
transitively required by common.py and used across all core entry points), the
module will be available at runtime.

---

Nitpick comments:
In `@nettacker/core/utils/common.py`:
- Around line 456-493: The functions version_matches_dsl and
extract_version_from_content lack type hints for their parameters and return
types. Add proper type hints to both functions: for version_matches_dsl, add
type hints indicating both detected_version and dsl_expression are strings, and
the return type is bool; for extract_version_from_content, add type hints
indicating content is a string, patterns is a list, and the return type is an
optional string. This aligns with the coding guidelines requiring type hints for
public APIs in the nettacker module.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 45891a2c-51a7-4c9d-b836-c097700375d7

📥 Commits

Reviewing files that changed from the base of the PR and between cbed0c4 and 7fadbdd.

⛔ Files ignored due to path filters (1)
  • poetry.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • nettacker/api/database.sqlite3
  • nettacker/core/lib/http.py
  • nettacker/core/utils/common.py
  • nettacker/core/utils/dsl_matcher.py
  • pyproject.toml

Comment thread nettacker/core/lib/http.py
Comment thread nettacker/core/utils/dsl_matcher.py
Comment thread nettacker/core/utils/dsl_matcher.py
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.

[Feat] DSL engine

3 participants