Skip to content

fix: reject null bytes in capec_map_enricher CLI arguments - #3503

Closed
HarshRajSinghania wants to merge 1 commit into
OWASP:masterfrom
HarshRajSinghania:fix/capec-enricher-null-bytes
Closed

HarshRajSinghania wants to merge 1 commit into
OWASP:masterfrom
HarshRajSinghania:fix/capec-enricher-null-bytes

Conversation

@HarshRajSinghania

Copy link
Copy Markdown

Summary

Reject null bytes in scripts/capec_map_enricher.py CLI path and string arguments so the tool logs a clear error and exits instead of crashing with an unhandled ValueError from pathlib/pathvalidate.

Motivation

Fixes #3502. Maintainer requested validation wrappers around filepath and string arguments after fuzzed inputs with embedded null bytes caused an unhandled crash.

Implementation

  • Add validate_filepath_no_nulls() for --capec-json, --input-path, --source-dir, and --output-path.
  • Add _validate_no_null_bytes() for --version and --edition.
  • Catch argparse.ArgumentTypeError in parse_arguments() and exit with code 1 after logging.
  • Keep a defensive post-parse check in main() for the same fields.

Testing

  • python3 -m ast parse of both changed files succeeds.
  • Added unit tests in tests/scripts/capec_map_enricher_utest.py for path/version null bytes and the two validators.
  • Full project pytest was not run here: the repository is too large to clone in this environment and pathvalidate is not installed locally. CI on this PR should run tests/scripts/capec_map_enricher_utest.py.

@sydseter

sydseter commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

@HarshRajSinghania thank you for your contribution. Remember that you have to ask to be assigned before starting work on an issue. Otherwise, thank you!.

There is a complexity issue raised in the script. See:

./scripts/capec_map_enricher.py:274:1: C901 'main' is too complex (13)

@sydseter

Copy link
Copy Markdown
Collaborator

Please be aware of the contributor guidelines: https://github.com/OWASP/cornucopia/blob/master/CONTRIBUTING.md
You should use our default pull-request template when creating pull-request.

I will close this pull-request, but feel free to open a new pull-request in the correct way.

@sydseter sydseter closed this Sep 17, 2026
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.

Filter out null bytes in capec_map_enricher.py

2 participants