Skip to content

Commit

Permalink
Added keyboard interrupt for n0s1 scan and proper error handling for …
Browse files Browse the repository at this point in the history
…lack of access on Jira and Confluence
  • Loading branch information
blupants committed Jul 3, 2024
1 parent 993fedf commit 8fe56bf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/n0s1/controllers/confluence_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions src/n0s1/controllers/jira_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
16 changes: 12 additions & 4 deletions src/n0s1/n0s1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down

0 comments on commit 8fe56bf

Please sign in to comment.