Skip to content

fix(rls): check the rule's current tables when an update rebinds it - #45214

Open
verdier wants to merge 3 commits into
apache:masterfrom
verdier:fix/rls-update-retarget-access
Open

verdier wants to merge 3 commits into
apache:masterfrom
verdier:fix/rls-update-retarget-access

Conversation

@verdier

@verdier verdier commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

SUMMARY

#40650 enforces datasource access in the RLS rule commands, and #41294 extends the check to partial updates that omit tables. When the payload does carry tables, though, UpdateRLSRuleCommand only checks the submitted tables. A caller with access to dataset B but not to dataset A can therefore rebind a rule from A to B, which lifts the filter from A.

The update now always checks the rule's current tables, then the submitted ones when tables is present.

TESTING INSTRUCTIONS

pytest tests/unit_tests/commands/security/rls_test.py

The new test test_update_rls_rule_forbidden_when_retargeting_away_from_denied_tables fails on master and passes with this change.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
  • Introduces new feature or API
  • Removes existing feature or API

Affects unreleased code only: #40650 is not in 6.1.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Muk4ptfk2ka1wrxivBHH7U

UpdateRLSRuleCommand only checked datasource access on the submitted
tables when the payload carried `tables`. A caller could therefore
rebind a rule from a datasource they cannot access to one they can,
lifting the filter from the former.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Muk4ptfk2ka1wrxivBHH7U
# tables, which lifts the filter from the tables it leaves. The caller
# must therefore access the rule's current tables, and the new ones
# when ``tables`` is present.
raise_for_datasource_access(self._model.tables)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: A concurrent rebind after this check lets a caller authorized only for the old table modify the rule now bound to an inaccessible table; this transaction takes no lock.

Assessment: 🔴 Critical · 🔁 Occurrence: Rarely · 🏷️ Race condition

Use CodeAnt Skill Fix in Cursor Fix in VSCode Claude

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset/commands/security/update.py
**Line:** 76:76
**Comment:**
	*Race Condition: A concurrent rebind after this check lets a caller authorized only for the old table modify the rule now bound to an inaccessible table; this transaction takes no lock.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This check-then-write window exists in every Superset command (RLS create/delete and the partial-update branch from #41294 included); none of them lock. Exploiting it needs a privileged user to rebind the rule within the same few milliseconds, which the caller cannot trigger. Locking only here would make this command the odd one out, and it does nothing on SQLite. This PR closes the deterministic rebind bypass and opens nothing new, so I'd keep it focused.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Customized review instruction saved!

Instruction:

Do not flag the existing check-then-write race in this update command as a new regression; recommend locking only when it can be addressed consistently across commands and supported backends.

Applied to:

  • superset/commands/security/update.py

💡 To manage or update this instruction, visit: CodeAnt AI Settings

@codeant-ai-for-open-source

codeant-ai-for-open-source Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

CodeAnt  CodeAnt PR Risk

🟢  Low Risk

  • The PR appears safe to merge; the reported check-then-write race predates this change, which adds access checks for the rule's current tables when retargeting.

Assessed commit: 2ea6c2a46bdb

@codecov

codecov Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.42%. Comparing base (7a46732) to head (2ea6c2a).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #45214   +/-   ##
=======================================
  Coverage   86.42%   86.42%           
=======================================
  Files        3183     3184    +1     
  Lines      222605   222615   +10     
  Branches    52996    53003    +7     
=======================================
+ Hits       192377   192386    +9     
- Misses      26758    26759    +1     
  Partials     3470     3470           
Flag Coverage Δ
hive 33.63% <0.00%> (ø)
mysql 51.83% <100.00%> (ø)
postgres 51.85% <100.00%> (-0.01%) ⬇️
presto 35.32% <0.00%> (ø)
python 88.81% <100.00%> (ø)
sqlite 51.55% <100.00%> (ø)
unit 84.37% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@EnxDev EnxDev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Read through this and the change is right. On master a role with RLS write and access to dataset B but not A could move a rule from A to B and lift the filter from A, because only the submitted tables were checked. Checking self._model.tables unconditionally closes that, and the new test covers exactly that path.

No inline notes. Agree with leaving the check-then-write window alone here, it's the same across the RLS commands.

@sha174n sha174n left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving. This closes a real authorization gap: before this change the update command only validated access against the submitted tables when the payload carried tables, so a caller authorized for the target dataset but not the rule's current one could rebind the rule and drop its filter off a dataset they are not allowed to manage. Moving the current-tables check so it always runs, then additionally checking the submitted tables, makes a rebind require access to both the old and the new datasources, which is the right invariant and keeps the create/delete commands consistent. The partial-update protection from the earlier change is preserved since the old else-branch is just folded into the unconditional call.

The new unit test is a proper red-green: it fails on master and passes here, and it asserts the rebind is refused because of the rule's existing table rather than the submitted one.

On the concurrent-rebind note: agree with keeping this focused. That check-then-write window is present uniformly across these commands and is not introduced here; addressing it piecemeal in one command (and as a no-op on SQLite) would be inconsistent. Worth a separate, cross-command discussion if we want row locking at all.

One optional follow-up: consider a companion test for the mirror case (caller holds the current table but not the new target) to lock the both-ends requirement explicitly. Not blocking.

@EnxDev
EnxDev requested a review from rusackas November 29, 2026 08:55

This branch has not been deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants