Skip to content

fix: replace bare except clauses and add path validation in PAM base#1901

Open
jlima8900 wants to merge 15 commits intoKeeper-Security:masterfrom
jlima8900:fix/pam-base-error-handling-pr1892
Open

fix: replace bare except clauses and add path validation in PAM base#1901
jlima8900 wants to merge 15 commits intoKeeper-Security:masterfrom
jlima8900:fix/pam-base-error-handling-pr1892

Conversation

@jlima8900
Copy link
Copy Markdown

Summary

  • Replace all 35 bare except: with specific exception types
  • Add path traversal check in file validation methods

Test plan

  • Tested on Python 3.7 and 3.12

ukumar-ks and others added 15 commits March 12, 2026 09:05
* commander KC - (1128, 1115, 1114) bug fix chnages

* File flag fix under "epm deployment download" in commander

* confirmation promp added  for kepm agent delete command without --force flag

* Kepm PR review changes
* Fixed double new lines on some terminals (Linux, MacOS)
* Improved handling of non-terminal protocols
* Update to keeper_pam_webrtc_rs>=2.1.5
Corrects logic in needs_security_audit: remove the erroneous "or None" that forced password mismatch to always be true, and determine alignment by comparing stored score and breach-watch revisions only when a current password exists. Adds retrieval of score_revision and sec_revision and updates needs_alignment accordingly. Includes new unit and integration tests (unit-tests/test_security_audit.py and tests/test_security_audit_refresh.py) to validate revision-based alignment, password removal, and other audit-refresh scenarios.
* Added "Connect As" options allowing for aditional records to provide credentials and host:port

* Added keeper webrtc version to SDP attribute a=keeper-webrtc:X.Y.Z
The execute_rest() function previously retried throttled (403) responses
every 10 seconds with no maximum retry count. This caused Commander to
hang indefinitely when throttled, and the 10-second retry interval
prevented the server's cooldown timer from expiring.

Changes:
- Add max retry count (3 attempts) before raising KeeperApiError
- Parse the server's "try again in X minutes/seconds" message
- Use exponential backoff (30s, 60s, 120s) capped at server's suggestion
- Cap server wait time at 300s to prevent excessive delays
- Log throttle attempts as warnings instead of debug
- After max retries, raise KeeperApiError so callers can handle it

The --fail-on-throttle flag continues to work as before (immediate error).

Unit tests (9 cases):
- Normal request unaffected by throttle logic
- Throttle twice then succeed (backoff 30s, 60s)
- KeeperApiError raised after 3 retries
- --fail-on-throttle skips retries entirely
- Parses "try again in X seconds" correctly
- Parses "try again in X minutes" correctly
- Caps server wait at 300s
- Exponential backoff progression (30s, 60s, 120s)
- Missing message defaults to 60s
…er-Security#1885)

- Make record argument optional; session-only probes run without it
  - Add Python-side network probes: DNS, HTTPS, WebSocket, TCP/UDP STUN,
    TURN Allocate, UDP port sweep across ephemeral range
  - Add PAM Configuration section (record required): DAG load, config
    linkage, gateway registered/online, connections/portForwards
  - Add --verbose flag for DAG allowedSettings table and record typed fields
- Replace all 35 bare except: in PAM base record loaders
- json.loads sites: catch only json.JSONDecodeError with e.msg,
  e.lineno, e.colno for actionable diagnostics
- import_schedule_field: split into JSONDecodeError vs (ValueError,
  KeyError) to distinguish parse errors from structural errors
- Add path traversal check in file validation methods
…16 tests

- CRON exception handler used type(e).__name__ but local variable
  `type = data.get("type", None)` shadows the builtin, causing
  TypeError when ValueError/KeyError is caught
- Add 16 tests covering all 30+ load() methods, CRON exception split,
  path traversal validation, and edge cases
Copy link
Copy Markdown
Contributor

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants