@@ -157,10 +157,33 @@ def show_http_error_codes():
157157 settings .print_data_to_stdout (settings .print_bold_debug_msg (debug_msg ))
158158
159159"""
160- Automatically create a Github issue with unhandled exception information.
160+ Masks sensitive data in the supplied message.
161+ """
162+ def mask_sensitive_data (err_msg ):
163+ for item in settings .SENSITIVE_OPTIONS :
164+ match = re .search (r"(?i)commix.+(" + str (item ) + r")(\s+|=)([^-]+)" , err_msg )
165+ if match :
166+ err_msg = err_msg .replace (match .group (3 ), '<sanitized>' + settings .SINGLE_WHITESPACE )
167+ return err_msg
168+
169+ """
170+ Print a user-friendly message with a URL for reporting an issue.
171+ """
172+ def print_report_issue (url , prepared ):
173+ if prepared :
174+ msg = ("Sanitized GitHub issue has been generated. Submit it at: " + url )
175+ settings .print_data_to_stdout (settings .print_info_msg (msg ))
176+ else :
177+ msg = ("Sanitized GitHub issue generation skipped. Report it manually at: " + url )
178+ settings .print_data_to_stdout (settings .print_warning_msg (msg ))
179+
180+ """
181+ Create a Github issue with unhandled exception information.
161182PS: Greetz @ sqlmap dev team for that great idea! :)
162183"""
163184def create_github_issue (err_msg , exc_msg ):
185+
186+ # Normalize exception message to generate a stable fingerprint
164187 _ = re .sub (r"'[^']+'" , "''" , exc_msg )
165188 _ = re .sub (r"\s+line \d+" , "" , _ )
166189 _ = re .sub (r'File ".+?/(\w+\.py)' , r"\g<1>" , _ )
@@ -169,97 +192,78 @@ def create_github_issue(err_msg, exc_msg):
169192 _ = re .sub (r"= _" , "= " , _ )
170193 _ = _ .encode (settings .DEFAULT_CODEC )
171194
195+ # Generate short hash used as issue identifier
172196 key = hashlib .md5 (_ ).hexdigest ()[:8 ]
173197
198+ # Build GitHub issue title using the last non-empty exception line
174199 bug_report = (
175200 "Bug Report: Unhandled exception \" "
176201 + str ([i for i in exc_msg .split (settings .END_LINE .LF ) if i ][- 1 ])
177202 + "\" (#" + key + ")"
178203 )
179204
180- while True :
181- try :
182- message = "Do you want to prepare a sanitized GitHub issue report "
183- message += "for manual submission? [y/N] "
184- choise = read_input (message , default = "N" , check_batch = True )
185- if choise in settings .CHOICE_YES :
186- break
187- elif choise in settings .CHOICE_NO :
188- settings .print_data_to_stdout (settings .SINGLE_WHITESPACE )
189- return
190- else :
191- invalid_option (choise )
192- except :
193- settings .print_data_to_stdout ("" )
194- raise SystemExit ()
195-
196- err_msg = err_msg [err_msg .find (settings .END_LINE .LF ):]
197-
198205 request = _urllib .request .Request (
199206 url = "https://api.github.com/search/issues?q=" +
200207 _urllib .parse .quote (
201- "repo:commixproject/commix" +
202- settings .SINGLE_WHITESPACE +
203- str (bug_report )
208+ "repo:commixproject/commix"
209+ + settings .SINGLE_WHITESPACE
210+ + str (bug_report )
204211 )
205212 )
206213
207214 try :
208- content = _urllib .request .urlopen (
209- request ,
210- timeout = settings .TIMEOUT
211- ).read ()
215+ content = _urllib .request .urlopen (request , timeout = settings .TIMEOUT ).read ()
212216 _ = json .loads (content )
217+
213218 duplicate = _ ["total_count" ] > 0
214219 closed = duplicate and _ ["items" ][0 ]["state" ] == "closed"
220+
215221 if duplicate :
216- warn_msg = "That issue seems to be already reported"
222+ info_msg = "That issue seems to be already reported"
217223 if closed :
218- warn_msg += " and resolved. Please update to the latest "
219- warn_msg += "(dev) version from official GitHub repository at '"
220- warn_msg += settings .GIT_URL + "'"
221- warn_msg += "." + settings .END_LINE .LF
222- settings .print_data_to_stdout (
223- settings .print_warning_msg (warn_msg )
224- )
224+ info_msg += " and resolved. Please update to the latest "
225+ info_msg += "(dev) version from official GitHub repository at '"
226+ info_msg += settings .GIT_URL + "'"
227+ info_msg += "."
228+ settings .print_data_to_stdout (settings .print_bold_info_msg (info_msg ))
225229 return
226230 except :
231+ # Ignore GitHub API errors and continue normally
227232 pass
228233
234+ while True :
235+ try :
236+ message = "Do you want to generate a sanitized GitHub issue report? [Y/n] "
237+ choise = read_input (message , default = "Y" , check_batch = True )
238+ if choise in settings .CHOICE_YES :
239+ # Mask any potentially sensitive data before submission
240+ err_msg = mask_sensitive_data (err_msg )
241+ break
242+ elif choise in settings .CHOICE_NO :
243+ print_report_issue (settings .ISSUES_PAGE , prepared = False )
244+ return
245+ else :
246+ invalid_option (choise )
247+ except :
248+ settings .print_data_to_stdout ("" )
249+ raise SystemExit ()
250+
251+ # Trim banner/output lines before the actual error content
252+ err_msg = err_msg [err_msg .find (settings .END_LINE .LF ):]
253+
254+ # Prepare pre-filled GitHub issue parameters
229255 params = {
230256 "title" : str (bug_report ),
231257 "body" :
232- "```" + str (err_msg ) + settings .END_LINE .LF +
233- "```" + settings .END_LINE .LF +
234- "```" + str (exc_msg ) + "```"
258+ "**Runtime Information**```" + str (err_msg ) + "```" + settings .END_LINE .LF +
259+ "**Python Traceback**```" + settings .END_LINE .LF + str (exc_msg ) + "```"
235260 }
236261
237- issue_url = (
238- "https://github.com/commixproject/commix/issues/new?"
239- + _urllib .parse .urlencode (params )
240- )
241-
242- info_msg = (
243- "A sanitized GitHub issue has been prepared with " +
244- "relevant error details for manual review and submission:" +
245- settings .END_LINE .LF +
246- issue_url
247- )
248-
249- settings .print_data_to_stdout (
250- settings .print_info_msg (info_msg )
251- )
252-
253- """
254- Masks sensitive data in the supplied message.
255- """
256- def mask_sensitive_data (err_msg ):
257- for item in settings .SENSITIVE_OPTIONS :
258- match = re .search (r"(?i)commix.+(" + str (item ) + r")(\s+|=)([^-]+)" , err_msg )
259- if match :
260- err_msg = err_msg .replace (match .group (3 ), '*' * len (match .group (3 )) + settings .SINGLE_WHITESPACE )
262+ # Build final GitHub issue URL (prefilled)
263+ issue_url = (settings .ISSUES_PAGE + "?" + _urllib .parse .urlencode (params ))
261264
262- return err_msg
265+ # Inform user that a sanitized issue has been prepared
266+ print_report_issue (issue_url , prepared = True )
263267
264268"""
265269Returns detailed message about occurred unhandled exception.
@@ -370,21 +374,17 @@ def unhandled_exception():
370374 raise SystemExit ()
371375
372376 else :
373- err_msg = "Unhandled exception occurred in '" + settings .VERSION [1 :] + "'. It is recommended to retry your "
374- err_msg += "run with the latest (dev) version from official GitHub "
375- err_msg += "repository at '" + settings .GIT_URL + "'. If the exception persists, please open a new issue "
376- err_msg += "at '" + settings .ISSUES_PAGE + "' "
377- err_msg += "with the following text and any other information required to "
378- err_msg += "reproduce the bug. The "
379- err_msg += "developers will try to reproduce the bug, fix it accordingly "
380- err_msg += "and get back to you." + settings .END_LINE .LF
381- err_msg += settings .APPLICATION .capitalize () + " version: " + settings .VERSION [1 :] + settings .END_LINE .LF
382- err_msg += "Python version: " + settings .PYTHON_VERSION + settings .END_LINE .LF
383- err_msg += "Operating system: " + os .name + settings .END_LINE .LF
384- err_msg += "Command line: " + re .sub (r".+?\bcommix\.py\b" , "commix.py" , " " .join (sys .argv )) + settings .END_LINE .LF
385- err_msg = mask_sensitive_data (err_msg )
386- exc_msg = re .sub (r'".+?[/\\](\w+\.py)' , r"\"\g<1>" , exc_msg )
387- settings .print_data_to_stdout (settings .print_critical_msg (err_msg + settings .END_LINE .LF + exc_msg .rstrip ()))
377+ err_msg = "Unhandled exception occurred in '" + settings .VERSION [1 :] + "'. "
378+ err_msg += "It is recommended to retry your run with the latest (dev) version from the official GitHub repository at '" + settings .GIT_URL + "'. "
379+ err_msg += "If the issue still occurs, you can report it on GitHub by generating a sanitized report, that removes sensitive data, or by submitting the details manually." + settings .END_LINE .LF
380+ err_msg += settings .SUB_CONTENT_SIGN_TYPE + " " + settings .APPLICATION .capitalize () + " version: " + settings .VERSION [1 :] + settings .END_LINE .LF
381+ err_msg += settings .SUB_CONTENT_SIGN_TYPE + " Python version: " + settings .PYTHON_VERSION + settings .END_LINE .LF
382+ err_msg += settings .SUB_CONTENT_SIGN_TYPE + " Operating system: " + os .name + settings .END_LINE .LF
383+ err_msg += settings .SUB_CONTENT_SIGN_TYPE + " Command summary: " + re .sub (r".+?\bcommix\.py\b" , "commix.py" , " " .join (sys .argv )) + settings .END_LINE .LF
384+ exc_msg = settings .TRACEBACK + re .sub (r'".+?[/\\](\w+\.py)' , r"\"\g<1>" , exc_msg )
385+ settings .print_data_to_stdout (settings .print_critical_msg (err_msg + exc_msg .rstrip ()))
386+ strip_ansi = lambda s : re .sub (r"\x1B\[[0-9;]*m" , "" , s )
387+ err_msg , exc_msg = map (strip_ansi , (err_msg , exc_msg ))
388388 create_github_issue (err_msg , exc_msg [:])
389389
390390"""
0 commit comments