fix(api): Display correct cert error message
Proposed change
- Enhanced SSL Error Trapping: Added a try-except block to the API engine to catch
ssl.SSLErrorandValueErrorduring the Flask server initialization. - New Localization Keys: Added two new message keys to
en.yamlto provide user-friendly feedback when certificate loading fails, replacing generic tracebacks with actionable error messages. - Implemented an explicit
sys.exit(1)withinstart_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 callssys.exit(1)immediately. This prevents the misleadingCannot 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
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
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-commitand 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
[!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_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto 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.
Comment @coderabbitai help to get the list of available commands and usage tips.
Hi @securestep9 and @arkid15r, please review when you have a chance. Thanks.
@arkid15r and @securestep9 - can you review? Thanks.
@coderabbitai full review
Full review triggered.β
Actions performed
@securestep9 - I've addressed the Gemini review suggestions. Would you please take another look? Thanks!