Skip to content

Conversation

@subhash-0000
Copy link

This PR makes the Unix/Linux path handling OS-independent to ensure Nettacker works equally well on both Windows and Unix-like operating systems.

I've requested assignment for issue #933 and have completed the implementation with full testing on Windows.

Changes Made
Refactored path operations in 5 core files to use OS-independent methods:

Fixed graph discovery, language loading, and module loading in arg_parser
Fixed language discovery in messages module
Fixed file download headers in API engine
Added UTF-8 encoding to YAML file operations in template module for Windows compatibility
Added clarifying comment in common utils to distinguish URL parsing from file path operations
All changes replace hardcoded forward slash operations with pathlib properties and os.path functions.

Testing Performed
Tested comprehensively on Windows 10 with Python 3.10.0:

Scan Engine: All 117 modules discovered and loaded successfully
API: File download headers working correctly with Windows paths
WebUI: Language discovery (23 languages) and graph discovery (2 graphs) working
Module Loading: All YAML files parsed without encoding errors
Path Handling: Windows backslash paths working correctly
Database: SQLite connection and operations working
All changes are cross-platform and fully backwards compatible with Unix/Linux systems.

Fixes #933

Type of change
Bugfix (non-breaking change which fixes an issue)
Checklist
I've followed the contributing guidelines
I've run make pre-commit, it didn't generate any changes
I've run make test, all tests passed locally

Copilot AI review requested due to automatic review settings December 2, 2025 15:55
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 2, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Summary by CodeRabbit

  • Refactor

    • Improved path and filename handling for more consistent, cross-platform behavior.
    • Streamlined extraction of language and module metadata.
  • Documentation

    • Added and clarified docstrings and descriptive comments across core components.
  • Bug Fixes

    • Ensured template files are read using UTF-8.
    • Made result download filenames platform-agnostic.
  • Chores

    • Updated CI workflow action versions for consistency.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

Replaced fragile string-based path parsing with platform-agnostic pathlib/os.path usage, added UTF-8 when opening template YAMLs, and added/expanded docstrings. No changes to public interfaces or control flow; header filename extraction made OS-agnostic.

Changes

Cohort / File(s) Summary
API filename extraction
nettacker/api/engine.py
Use os.path.basename(filename) to derive Content-Disposition filename instead of filename.split("/")[-1].
Path parsing for graphs, modules, languages
nettacker/core/arg_parser.py, nettacker/core/messages.py
Replace string-splitting with pathlib.Path usage (.parent.name, .stem) to compute graph/module/language identifiers and module names; metadata logic preserved.
Template handling & docs
nettacker/core/template.py
Open YAML files with encoding="utf-8" and add docstrings for open() and format(); behavior unchanged otherwise.
Docstring clarification
nettacker/core/utils/common.py
Added detailed docstring to re_address_repeaters_key_name; no signature or logic changes.
CI workflow updates
.github/workflows/ci_cd.yml
Bumped several GitHub Action versions (checkout, upload/download-artifact, etc.) to newer major/minor releases.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • arkid15r
  • securestep9

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Out of Scope Changes check ❓ Inconclusive The CI/CD workflow changes (GitHub Actions version bumps) appear to be maintenance updates unrelated to the core path-handling objectives, though they represent minor scope creep beyond the primary issue. Clarify whether the GitHub Actions version bumps were intentional scope or unrelated maintenance; if unrelated, consider separating into a distinct PR.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: making Unix/Linux path handling OS-independent for Windows compatibility, which accurately summarizes the primary objective of the PR.
Description check ✅ Passed The description provides clear context about the OS-independent path refactoring, lists specific files changed, documents testing performed on Windows, and references the related issue #933.
Linked Issues check ✅ Passed The PR successfully addresses issue #933 by replacing Unix/Linux path assumptions with OS-independent methods (pathlib, os.path) across five core files and adding UTF-8 encoding for cross-platform compatibility.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR successfully refactors path handling operations across 5 core files to use OS-independent methods, ensuring Nettacker works correctly on both Windows and Unix-like operating systems. The changes replace hardcoded forward slash string operations with proper pathlib properties and os.path functions, which automatically handle platform-specific path separators.

Key Changes:

  • Replaced string .split("/") operations with pathlib properties (.stem, .parent.name) for extracting file path components
  • Added UTF-8 encoding to YAML file operations for Windows compatibility
  • Replaced string splitting with os.path.basename() for filename extraction

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
nettacker/core/utils/common.py Added clarifying comment to distinguish URL key delimiter from file path separator
nettacker/core/template.py Added UTF-8 encoding parameter when opening YAML module files to handle non-ASCII characters on Windows
nettacker/core/messages.py Replaced string splitting with language.stem to extract language names from file paths
nettacker/core/arg_parser.py Replaced string splitting with pathlib properties (.stem, .parent.name) in three locations: graph discovery, language loading, and module loading
nettacker/api/engine.py Replaced string splitting with os.path.basename() for extracting filename in file download headers

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@subhash-0000
Copy link
Author

@coderabbitai generate docstrings

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 2, 2025

✅ Actions performed

Initiated docstring generation; will generate only if new commits exist.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 2, 2025

Note

Docstrings generation - SUCCESS
Generated docstrings for this pull request at #1174

coderabbitai bot added a commit that referenced this pull request Dec 2, 2025
Docstrings generation was requested by @subhash-0000.

* #1173 (comment)

The following files were modified:

* `nettacker/api/engine.py`
* `nettacker/core/arg_parser.py`
* `nettacker/core/messages.py`
* `nettacker/core/template.py`
* `nettacker/core/utils/common.py`
@subhash-0000 subhash-0000 deleted the fix-windows-path-handling branch December 3, 2025 02:15
@subhash-0000 subhash-0000 restored the fix-windows-path-handling branch December 10, 2025 02:41
@subhash-0000 subhash-0000 reopened this Dec 10, 2025
subhash-0000 added a commit to subhash-0000/Nettacker that referenced this pull request Dec 12, 2025
@subhash-0000 subhash-0000 requested a review from Copilot December 12, 2025 11:23
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@subhash-0000
Copy link
Author

Hi maintainers

This PR fixes Windows path compatibility issues by replacing Unix-specific path operations with OS-independent methods (os.path.basename(), .stem, .parent.name).

Changes:

  • Replaced split("/") with proper pathlib/os.path methods
  • Added docstrings per CodeRabbit review
  • All formatting fixes applied

The CI workflow is awaiting approval to run. Could a maintainer please approve the workflow? Thanks!

Fixes #1039

@deekshithaby
Copy link

Hi @subhash-0000,

I tested PR #1173 locally on macOS. The path-handling changes work as expected, module resolution and the updated directory structure behave correctly.

The only failures I encountered were due to Python 3.12 removing ssl.wrap_socket,which affects the test suite but isn’t related to your changes.

To address this and make the test suite compatible with Python 3.12+, I opened a separate test-only compatibility PR here:
#1180

With that shim applied, all 214 tests pass locally, and PR #1173 runs cleanly.

Happy to test anything else if needed!

@subhash-0000
Copy link
Author

@deekshithaby
Thank you so much for testing this locally

Great to hear the path-handling changes work correctly on macOS and that module resolution is functioning as expected. I appreciate you opening #1180 to address the Python 3.12 SSL compatibility issue separately - that's very helpful!

Looking forward to getting this merged once the maintainers approve the workflow and review the changes. Thanks again for your thorough testing!

@subhash-0000
Copy link
Author

Friendly ping @arkid15r @securestep9

This PR has been tested by @deekshithaby on macOS and is ready for review. The workflow is awaiting approval to run CI checks.

Thanks for your time!

@subhash-0000
Copy link
Author

Friendly ping @arkid15r @securestep9

This PR has been tested on macOS and is ready for review. The workflow is awaiting approval to run CI checks.

@securestep9
Copy link
Collaborator

@subhash-0000 the CI is failing due to pre-commit checks on ruff formatting and the commits in the PR missing verified signatures. Please learn how to digitally sign your commits.

Refactored path operations to use OS-independent methods:
- Replaced hardcoded forward slash '/' string splits with pathlib properties (Path.stem, Path.name, Path.parent.name)
- Used os.path.basename() for string-based path operations
- Added UTF-8 encoding to YAML file operations for Windows compatibility
- Added clarifying comment to distinguish URL parsing from file path operations

Tested on Windows with all functionality working:
- Scan Engine: Module discovery and loading (117 modules)
- API: File download headers and path handling
- WebUI: Language and graph discovery

Changes are backwards compatible with Unix/Linux systems.

Fixes issue regarding Windows path handling
dependabot bot and others added 8 commits January 5, 2026 09:58
Bumps [urllib3](https://github.com/urllib3/urllib3) from 2.5.0 to 2.6.0.
- [Release notes](https://github.com/urllib3/urllib3/releases)
- [Changelog](https://github.com/urllib3/urllib3/blob/main/CHANGES.rst)
- [Commits](urllib3/urllib3@2.5.0...2.6.0)

---
updated-dependencies:
- dependency-name: urllib3
  dependency-version: 2.6.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 5 to 6.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](actions/upload-artifact@v5...v6)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 6 to 7.
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](actions/download-artifact@v6...v7)

---
updated-dependencies:
- dependency-name: actions/download-artifact
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [actions/checkout](https://github.com/actions/checkout) from 5 to 6.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@v5...v6)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@subhash-0000 subhash-0000 force-pushed the fix-windows-path-handling branch from e30262d to 10552c4 Compare January 5, 2026 04:30
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
.github/workflows/ci_cd.yml (1)

26-26: Consider separating workflow updates from path handling changes.

These GitHub Actions version bumps appear unrelated to the PR's core objective of making path handling OS-independent. While the updates may be beneficial, mixing unrelated changes in a single PR can complicate review, increase merge risk, and make it harder to track changes historically.

Consider whether these workflow updates should be in a separate PR, unless they're specifically required for testing the Windows path handling changes.

Also applies to: 50-50, 70-70, 93-93, 110-110, 126-126, 134-134, 157-157, 234-234, 254-254, 285-285, 322-322, 348-348

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e30262d and 10552c4.

⛔ Files ignored due to path filters (1)
  • poetry.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • .github/workflows/ci_cd.yml
  • nettacker/api/engine.py
  • nettacker/core/arg_parser.py
  • nettacker/core/messages.py
  • nettacker/core/template.py
  • nettacker/core/utils/common.py
✅ Files skipped from review due to trivial changes (1)
  • nettacker/core/utils/common.py
🚧 Files skipped from review as they are similar to previous changes (4)
  • nettacker/core/messages.py
  • nettacker/core/template.py
  • nettacker/core/arg_parser.py
  • nettacker/api/engine.py
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-06T16:37:47.916Z
Learnt from: arkid15r
Repo: OWASP/Nettacker PR: 0
File: :0-0
Timestamp: 2025-08-06T16:37:47.916Z
Learning: In the OWASP/Nettacker repository's GitHub Actions workflow, artifacts are downloaded by name (specifically the 'dist' artifact) rather than by artifact ID, so updates to actions/download-artifact that affect ID-based downloads don't impact this codebase.

Applied to files:

  • .github/workflows/ci_cd.yml
🔇 Additional comments (2)
.github/workflows/ci_cd.yml (2)

110-110: actions/upload-artifact@v6 is stable for GitHub-hosted runners.

Version 6 is a stable release. The main change is Node.js 24 support and requires Actions Runner 2.327.1+, which is not an issue for GitHub-hosted runners. No new behavioral breaking changes in v6 affect artifact upload/download workflows.


26-26: All version upgrades are valid and safe.

actions/checkout@v6, actions/upload-artifact@v6, and actions/download-artifact@v7 are stable releases. The credential persistence change in checkout@v6 requires no workflow modifications. The workflow's single upload-artifact step to 'dist' and multiple download-artifact steps from the same artifact are fully compatible with v6 and v7. All versions require Actions Runner v2.327.1+, which is met by default on GitHub-hosted runners.

Also applies to: 50-50, 70-70, 93-93, 126-126, 157-157, 234-234, 254-254, 285-285

@subhash-0000
Copy link
Author

@securestep9
pre-commit checks on ruff formatting is resolved and the commits in the PR commits are signed
The PR is ready for review

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.

Refactor the code to make sure os path related logic is OS agnostic

3 participants