From 8fe56bfa8281ced34f638d2951eee3e287f99434 Mon Sep 17 00:00:00 2001 From: blupants Date: Wed, 3 Jul 2024 11:36:10 -0500 Subject: [PATCH] Added keyboard interrupt for n0s1 scan and proper error handling for lack of access on Jira and Confluence --- src/n0s1/controllers/confluence_controller.py | 6 ++++++ src/n0s1/controllers/jira_controller.py | 6 ++++++ src/n0s1/n0s1.py | 16 ++++++++++++---- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/n0s1/controllers/confluence_controller.py b/src/n0s1/controllers/confluence_controller.py index 22b2930..5dcb548 100644 --- a/src/n0s1/controllers/confluence_controller.py +++ b/src/n0s1/controllers/confluence_controller.py @@ -122,6 +122,7 @@ def is_connected(self): return False def get_data(self, include_coments=False, limit=None): + from atlassian.confluence import ApiPermissionError if not self._client: return {} @@ -150,6 +151,11 @@ def get_data(self, include_coments=False, limit=None): while not pages_finished: try: pages = self._client.get_all_pages_from_space(key, start=pages_start, limit=limit) + except ApiPermissionError as e: + message = str(e) + f" get_all_pages_from_space({key}, start={pages_start}, limit={limit}). Skipping..." + self.log_message(message, logging.WARNING) + pages = [{}] + break except Exception as e: message = str(e) + f" get_all_pages_from_space({key}, start={pages_start}, limit={limit})" self.log_message(message, logging.WARNING) diff --git a/src/n0s1/controllers/jira_controller.py b/src/n0s1/controllers/jira_controller.py index 198c0f9..e502fec 100644 --- a/src/n0s1/controllers/jira_controller.py +++ b/src/n0s1/controllers/jira_controller.py @@ -65,6 +65,7 @@ def is_connected(self): return False def get_data(self, include_coments=False, limit=None): + from jira.exceptions import JIRAError if not self._client: return {} start = 0 @@ -85,6 +86,11 @@ def get_data(self, include_coments=False, limit=None): while not issues_finished: try: issues = self._client.search_issues(ql, startAt=issue_start, maxResults=limit) + except JIRAError as e: + self.log_message(f"Error while searching issues on Jira project: [{key}]. Skipping...", logging.WARNING) + self.log_message(e) + issues = [{}] + break except Exception as e: message = str(e) + f" client.search_issues({ql}, startAt={issue_start}, maxResults={limit})" self.log_message(message, logging.WARNING) diff --git a/src/n0s1/n0s1.py b/src/n0s1/n0s1.py index 7d91944..f2ba85d 100755 --- a/src/n0s1/n0s1.py +++ b/src/n0s1/n0s1.py @@ -628,10 +628,18 @@ def main(callback=None): "timeout": timeout, "limit": limit} report_json["tool"]["scan_arguments"] = scan_arguments - scan(regex_config, controller, scan_arguments) - _save_report(report_format) - - log_message("Done!") + try: + scan(regex_config, controller, scan_arguments) + except KeyboardInterrupt: + log_message("Keyboard interrupt detected. Saving findings and exiting...") + sys.exit(130) + except Exception as e: + log_message("Execution interrupted by an exception. Saving partial report and exiting...") + log_message(e) + sys.exit(1) + finally: + _save_report(report_format) + log_message("Done!") if __name__ == "__main__":