Skip to content

fix: prevent early return in PathList lookup when intermediate path fails#81

Merged
jason-famedly merged 1 commit into
mainfrom
fix/pathlist-early-return
Apr 9, 2026
Merged

fix: prevent early return in PathList lookup when intermediate path fails#81
jason-famedly merged 1 commit into
mainfrom
fix/pathlist-early-return

Conversation

@nikzen

@nikzen nikzen commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix a bug in get_path_in_dict where a PathList with multiple paths would short-circuit on the first failing path instead of trying subsequent ones.
  • When an intermediate segment resolved to a non-dict value (e.g. because the top-level key was missing), the inner loop's return None aborted the entire function. Changed to break + for/else so only fully traversed paths produce a result.
  • Add tests covering missing keys, non-dict intermediates, and a real-world Zitadel admin_path scenario with project-scoped role claims.

Context

When admin_path is configured as a PathList (e.g. [["roles", "Admin"], ["urn:zitadel:iam:org:project:<id>:roles", "MatrixAdmin"]]), the first path ["roles", "Admin"] fails on tokens that don't have a roles key. The bug caused the function to return None immediately without ever checking the second path, making it impossible to use PathList for fallback admin detection.

Test plan

  • All existing test_get_path_in_dict assertions still pass
  • New test test_get_path_in_dict_pathlist_fallback_on_missing_key — verifies fallback when the first path's key is entirely absent
  • New test test_get_path_in_dict_pathlist_non_dict_intermediate — verifies fallback when an intermediate value is a non-dict (int, string)
  • New test test_get_path_in_dict_zitadel_admin_path — real-world scenario with Zitadel project-scoped role claims, testing both path orderings

Made with Cursor

@nikzen
nikzen requested a review from a team as a code owner March 31, 2026 21:56
…ails

When `get_path_in_dict` received a PathList (list of lists) and the
first path encountered a missing key at an intermediate segment, the
function returned `None` immediately instead of trying the remaining
paths.

The root cause was `return None` inside the inner loop's
`not isinstance(r, dict)` guard. This aborted the entire outer loop
rather than just the current path. Replaced with `break` and moved the
result check into a `for/else` block so that only fully traversed paths
are considered.

Made-with: Cursor
@nikzen
nikzen force-pushed the fix/pathlist-early-return branch from 7258973 to d6e3415 Compare March 31, 2026 21:59
@codecov

codecov Bot commented Mar 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.18%. Comparing base (8ad0e2a) to head (d6e3415).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #81      +/-   ##
==========================================
+ Coverage   83.08%   83.18%   +0.09%     
==========================================
  Files          18       18              
  Lines        1874     1885      +11     
  Branches      193      193              
==========================================
+ Hits         1557     1568      +11     
  Misses        234      234              
  Partials       83       83              
Files with missing lines Coverage Δ
synapse_token_authenticator/utils.py 90.90% <100.00%> (ø)
tests/test_sta_utils.py 98.03% <100.00%> (+0.53%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8ad0e2a...d6e3415. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jason-famedly jason-famedly left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Apologizes for the length of time it took me to understand enough of the code base to understand what this was even for. This should be fine 🚀

@jason-famedly
jason-famedly added this pull request to the merge queue Apr 7, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 7, 2026
@jason-famedly
jason-famedly added this pull request to the merge queue Apr 9, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 9, 2026
@jason-famedly
jason-famedly added this pull request to the merge queue Apr 9, 2026
Merged via the queue into main with commit 924ff93 Apr 9, 2026
5 checks passed
@jason-famedly
jason-famedly deleted the fix/pathlist-early-return branch April 9, 2026 12:44
This was referenced Apr 9, 2026
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.

2 participants