fix: replace bare except clauses and add path validation in PAM base#1901
fix: replace bare except clauses and add path validation in PAM base#1901jlima8900 wants to merge 9 commits intoKeeper-Security:releasefrom
Conversation
There was a problem hiding this comment.
CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
| obj = cls() | ||
| try: data = json.loads(data) if isinstance(data, str) else data | ||
| except: logging.error(f"Pam Scripts failed to load from: {str(data)[:80]}...") | ||
| except json.JSONDecodeError as e: logging.error(f"Pam Scripts: invalid JSON at line {e.lineno}, col {e.colno} — {e.msg}. Input (truncated): {str(data)[:80]}") |
Check failure
Code scanning / CodeQL
Clear-text logging of sensitive information
| obj = cls() | ||
| try: data = json.loads(data) if isinstance(data, str) else data | ||
| except: logging.error(f"PAM script failed to load from: {str(data)[:80]}") | ||
| except json.JSONDecodeError as e: logging.error(f"PAM script: invalid JSON at line {e.lineno}, col {e.colno} — {e.msg}. Input (truncated): {str(data)[:80]}") |
Check failure
Code scanning / CodeQL
Clear-text logging of sensitive information
| obj = cls() | ||
| try: data = json.loads(data) if isinstance(data, str) else data | ||
| except: logging.error(f"PAM Attachments failed to load from: {str(data)[:80]}...") | ||
| except json.JSONDecodeError as e: logging.error(f"PAM Attachments: invalid JSON at line {e.lineno}, col {e.colno} — {e.msg}. Input (truncated): {str(data)[:80]}") |
Check failure
Code scanning / CodeQL
Clear-text logging of sensitive information
| obj = cls() | ||
| try: data = json.loads(data) if isinstance(data, str) else data | ||
| except: logging.error(f"Failed to load file attachment from: {str(data)[:80]}") | ||
| except json.JSONDecodeError as e: logging.error(f"File attachment: invalid JSON at line {e.lineno}, col {e.colno} — {e.msg}. Input (truncated): {str(data)[:80]}") |
Check failure
Code scanning / CodeQL
Clear-text logging of sensitive information
| obj = cls() | ||
| try: data = json.loads(data) if isinstance(data, str) else data | ||
| except: logging.error(f"Failed to load rotation schedule from: {str(data)[:80]}") | ||
| except json.JSONDecodeError as e: logging.error(f"Rotation schedule: invalid JSON at line {e.lineno}, col {e.colno} — {e.msg}. Input (truncated): {str(data)[:80]}") |
Check failure
Code scanning / CodeQL
Clear-text logging of sensitive information
e6e690a to
6ad7fd9
Compare
|
@aaunario — ready for review. Squashed to single commit, all CodeQL alerts resolved, 16 unit tests passing. |
a38b94d to
871b277
Compare
* Added full terminal reset after ssh session exit (clears scrollback etc.) * Fixes randomly eaten first characters typed after ssh session exit (stdin race condition) * Fixed random duplicate typed characters (echo)
Keeper-Security#1908) - Added `move` to the list of `apply-action` choices, which will move all returned users to a node - specified with `target-node` - Added `all` to the list of `status` choices, returning invited, active and locked users with `d=0` - Fixed an issue where the users updated with `apply-action` are not the same as those filtered with the `node` argument. - Fixed a potential unwanted behavior where the `node` argument returns a recursive node and subnodes search, preventing you from applying actions to a specific node if it has subnodes. By default, using the `node` argument will only return result from the specified node. - Added a `recursive` argument to replicate the old behavior with `node` filter.
- Narrow all bare except clauses to json.JSONDecodeError with structured error messages (line, col, msg) across 30+ load() methods - Replace em-dashes with double-dashes in all log messages - Add TypeError, AttributeError to CRON except tuple - Extract shared _validate_file_path() helper (DRY) - Add path traversal rejection (.. components) - Add tests for rotation settings, base machine parser, CRON edge cases
871b277 to
c011296
Compare
Prevents directories from passing file path validation.
442d7af to
9ec9b7a
Compare
Summary
Replaces all 35 bare
except:clauses inkeepercommander/commands/pam_import/base.pywith specific exception types (JSONDecodeError,ValueError,KeyError) and adds path traversal validation for file operations. Also removes truncated input data from error log messages to resolve CodeQL clear-text logging alerts.Changes
except:→ specific types — each handler now catches only the expected exceptionos.path.realpathbefore access{str(data)[:80]}from all error messages (CodeQL fix)Tests
test_pam_base_error_handling.pyCodeQL
All clear-text logging alerts resolved in this single squashed commit.