Skip to content

DSL Engine - #1587

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

DSL Engine #1587
Aarush289 wants to merge 34 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

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@Aarush289, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 18 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a1931ee9-93d3-4589-868f-0f2354d29a15

📥 Commits

Reviewing files that changed from the base of the PR and between 1a5e199 and 7d306f8.

📒 Files selected for processing (1)
  • nettacker/core/lib/http.py

Walkthrough

Adds a DSLMatcher for version expressions, comparison operators, range matching, and response extraction. Wrapper helpers expose the matcher, HTTP response conditions support version matching from content or headers, and semver is added as a runtime dependency.

Changes

Version DSL Engine and HTTP Integration

Layer / File(s) Summary
Matcher foundation and dependency
nettacker/core/utils/dsl_matcher.py, pyproject.toml
Defines DSLMatcher, normalizes versions, adds the semver dependency, and creates a shared matcher instance.
DSL evaluation and comparison operators
nettacker/core/utils/dsl_matcher.py
Supports logical connectors, comma-separated conditions, comparisons, semantic operators, ranges, wildcards, and fallback version comparisons.
CVE ranges and response extraction
nettacker/core/utils/dsl_matcher.py
Matches exact and range-style CVE expressions and extracts versions from response content using regex patterns.
Helper wrappers and HTTP conditions
nettacker/core/utils/common.py, nettacker/core/lib/http.py
Adds matcher wrappers and integrates version_match and version_dsl response conditions for content and headers.

Estimated code review effort: 4 (Complex) | ~50 minutes

Suggested reviewers: arkid15r, securestep9

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

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.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is short and clearly references the DSL engine added in this PR.
Description check ✅ Passed The description matches the PR and explains the DSL/version-extraction work.
Linked Issues check ✅ Passed The changes implement DSL-based version extraction and scanning, matching issue #1586.
Out of Scope Changes check ✅ Passed The changes stay focused on DSL/version matching and a supporting dependency update.
✨ 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.

@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
@securestep9

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

https://github.com/OWASP/Nettacker/blob/8371b67aaef5bc7c7b87cc5997bccff0296a8a04/nettacker/api/database.sqlite3#L1
P2 Badge Remove the seeded scan result from the template DB

The binary SQLite diff is not just metadata: dumping it shows a new hosts_log row for 210.65.127.194 with scan id manual_test. This file is documented as the empty sample API database, so shipping it with a pre-populated scan result leaks a real target and makes fresh installs/tests start with stale findings instead of an empty database.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +255 to +258
next_major = v2_parts.copy()
next_major[0] += 1
for i in range(1, len(next_major)):
next_major[i] = 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Bound caret ranges for zero-major versions

When a DSL expression uses a caret constraint on a pre-1.0 version, this always advances to the next major version, so ^0.2.3 accepts targets up to <1.0.0 (for example 0.9.0). Caret semantics for 0.x versions only allow changes within the next non-zero component, so modules using this matcher for vulnerability ranges can falsely flag unaffected pre-1.0 services.

Useful? React with 👍 / 👎.

else:
condition_results["responsetime"] = []
# DSL version matching support
if condition == "version_match":

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Allow DSL conditions in module schema validation

The new version_match/version_dsl runtime conditions are still absent from tests/test_yaml_schema_and_regex.py's HTTP_CONDITION_SCHEMA, which validates HTTP conditions with ignore_extra_keys=False. Any module that actually uses this DSL condition will therefore fail the repo's YAML schema test, so the feature cannot be added to Nettacker modules until that whitelist is updated.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We will update the schema

version_config = conditions[condition]
# Extract version from response using patterns
version_patterns = version_config.get("patterns", [])
dsl_expressions = version_config.get("expressions", [])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Accept a single version_dsl expression

When a module defines version_dsl with the same single-expression shape as version_match (for example expression: '>=1.2.3'), this lookup leaves dsl_expressions empty and the condition always returns no match even after extracting a valid version. Either accepting the singular key or clearly normalizing it to a list is needed, otherwise one-expression version_dsl checks are silently unusable.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

its not an issue, user can use "expressions" always

@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: 1

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

19-19: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Add docstrings to public methods.

parse_dsl_expression (Line 19) and extract_version_from_response (Line 442) are public entry points but lack docstrings, unlike the private helpers below them. A short docstring documenting args/return would align them with the rest of the module.

As per coding guidelines: "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/dsl_matcher.py` at line 19, Add concise docstrings to
the public methods parse_dsl_expression and extract_version_from_response,
documenting their parameters and return values. Match the module’s existing
documentation style and leave the private helper implementations unchanged.

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 16-22: Resolve the import conflict at the module’s import block by
removing all raw merge markers and retaining all four required symbols:
replace_dependent_response, reverse_and_regex_condition, version_matches_dsl,
and extract_version_from_content. Ensure the resulting imports are valid Python
and preserve their existing usages.

---

Nitpick comments:
In `@nettacker/core/utils/dsl_matcher.py`:
- Line 19: Add concise docstrings to the public methods parse_dsl_expression and
extract_version_from_response, documenting their parameters and return values.
Match the module’s existing documentation style and leave the private helper
implementations unchanged.
🪄 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: 639b7bd4-1b1c-462f-99ff-5a65b9ad26cd

📥 Commits

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

⛔ Files ignored due to path filters (1)
  • poetry.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • nettacker/core/lib/http.py
  • nettacker/core/utils/common.py
  • nettacker/core/utils/dsl_matcher.py
  • pyproject.toml
🚧 Files skipped from review as they are similar to previous changes (2)
  • nettacker/core/utils/common.py
  • pyproject.toml

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