Nettacker icon indicating copy to clipboard operation
Nettacker copied to clipboard

fix(api): Display correct cert error message

Open jess-tech-lab opened this issue 8 months ago β€’ 6 comments

Proposed change

  • Enhanced SSL Error Trapping: Added a try-except block to the API engine to catch ssl.SSLError and ValueError during the Flask server initialization.
  • New Localization Keys: Added two new message keys to en.yaml to provide user-friendly feedback when certificate loading fails, replacing generic tracebacks with actionable error messages.
  • Implemented an explicit sys.exit(1) within start_api_server. If the child process terminates with a non-zero exit code (e.g., due to an SSL PEM lib error), the parent process now calls sys.exit(1) immediately. This prevents the misleading Cannot specify the target(s) error.

With invalid cert files,

poetry run nettacker --start-api --api-host 127.0.0.1 --api-port 8080 --api-debug-mode --api-cert /etc/hosts --api-cert-key /etc/hosts
invalid_cert_file_fx



With wrong cert paths,

poetry run nettacker --start-api --api-host 127.0.0.1 --api-port 8080 --api-debug-mode --api-cert /etc/xxx --api-cert-key /etc/xxx
invalid_cert_file_not_found

Closes #1354

Type of change

  • [ ] New core framework functionality
  • [x] Bugfix (non-breaking change which 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

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

jess-tech-lab avatar Mar 06 '26 03:03 jess-tech-lab

Review Change Stack

[!NOTE]

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • [ ] ▢️ Resume reviews
  • [ ] πŸ” Trigger review

Walkthrough

Adds SSL and sys imports, introduces targeted exception handling for SSL/load/file-not-found errors during API subprocess startup, ensures the parent process exits with status 1 if the API child fails, and adds two English locale entries for those error messages.

Changes

API startup changes

Layer / File(s) Summary
Imports
nettacker/api/engine.py
Adds ssl and sys imports used by new exception and exit handling.
Subprocess SSL/file exception handling
nettacker/api/engine.py
Adds except ssl.SSLError and except FileNotFoundError branches in start_api_subprocess that call die_failure(...) with localized messages.
Parent exit on child failure
nettacker/api/engine.py
After waiting for the API child, parent checks p.exitcode and calls sys.exit(1) when the child exited non-zero.
Localization
nettacker/locale/en.yaml
Adds file_not_found and load_ssl_fail English message keys for the new error cases.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • OWASP/Nettacker#1343: Also modifies API startup behavior (changes Flask run to disable reloader); related to API lifecycle/run behavior.

Suggested labels

bug fixed

Suggested reviewers

  • arkid15r
  • securestep9
πŸš₯ Pre-merge checks | βœ… 5
βœ… Passed checks (5 passed)
Check name Status Explanation
Title check βœ… Passed The title 'fix(api): Display correct cert error message' directly corresponds to the main change of improving SSL certificate error messages displayed to users.
Description check βœ… Passed The description is well-detailed and directly related to the changeset, explaining the SSL error trapping, new localization keys, explicit process exit, and providing reproduction examples.
Linked Issues check βœ… Passed The PR fully implements the requirements from issue #1354: catches SSL errors with proper exception handling [engine.py], adds user-friendly error messages [en.yaml], and implements sys.exit(1) to prevent misleading 'Cannot specify targets' error.
Out of Scope Changes check βœ… Passed All changes are directly scoped to fixing the SSL certificate error handling issue: imports for ssl/sys, exception handling for SSLError/FileNotFoundError, child process exit code checking, and new localization strings for error messages.
Docstring Coverage βœ… Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
πŸ§ͺ Generate unit tests (beta)
  • [ ] Create PR with unit tests

[!TIP]

πŸ’¬ Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire orgβ€”no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-inβ€”scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

πŸ‘‰ Get started


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[bot] avatar Mar 06 '26 03:03 coderabbitai[bot]

Hi @securestep9 and @arkid15r, please review when you have a chance. Thanks.

jess-tech-lab avatar Mar 26 '26 22:03 jess-tech-lab

@arkid15r and @securestep9 - can you review? Thanks.

jess-tech-lab avatar May 08 '26 14:05 jess-tech-lab

@coderabbitai full review

securestep9 avatar May 09 '26 22:05 securestep9

βœ… Actions performed

Full review triggered.

coderabbitai[bot] avatar May 09 '26 22:05 coderabbitai[bot]

@securestep9 - I've addressed the Gemini review suggestions. Would you please take another look? Thanks!

jess-tech-lab avatar May 10 '26 11:05 jess-tech-lab