You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "rusackas (via GitHub)" <gi...@apache.org> on 2026/08/29 00:04:15 UTC
[PR] fix(dashboards): close CSS validation gaps in dashboard import and edits [superset]
rusackas opened a new pull request, #43666:
URL: https://github.com/apache/superset/pull/43666
### SUMMARY
`validate_css` (added in #40640) blocks `expression(`, script-scheme URIs, and `@import` on dashboard `css` at create/update time, but two gaps let a dangerous value through or block edits it shouldn't:
- `ImportV1DashboardSchema.css` had no validator at all, so a YAML/ZIP dashboard bundle import bypassed the check entirely while the create/update API paths enforced it. Custom CSS is injected into the page unsanitised (`injectCustomCss.ts` sets `style.innerHTML` directly on a real `<style>` tag), so an imported `@import` genuinely fetches and executes at render regardless of how it was saved. `external_url` in the same schema already gets its own validator threaded through import in the same PR, so this looked like a straightforward miss rather than an intentional gap.
- `DashboardPutSchema.css` re-validated on every PUT. A dashboard save resends the full object, so renaming a dashboard, moving a chart, or editing a filter all go through the same PUT and re-trigger the check even when `css` isn't the field being changed. A dashboard whose existing `css` already contained `@import` (from before this check existed, or via the import bypass above) became uneditable for any change at all, not just a change to `css`.
This closes the import gap by adding `validate_css` to `ImportV1DashboardSchema.css`, and moves PUT-path enforcement from the schema to `UpdateDashboardCommand`, which now only validates `css` when the incoming value actually differs from what's stored. A genuinely new `css` value, or an existing dangerous value being changed to a different dangerous value, is still rejected exactly as before, only an unrelated edit that resends an already-stored value (safe or not) stops being blocked.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — backend validation change, no UI change.
### TESTING INSTRUCTIONS
```bash
pytest tests/unit_tests/dashboards/schema_tests.py \
tests/unit_tests/commands/dashboard/update_test.py -q
```
New/changed coverage:
- `test_dashboard_import_css_rejects_dangerous_constructs` — import now rejects the same constructs create/update already do.
- `test_dashboard_put_schema_does_not_validate_css` — replaces the old PUT-schema-level test; documents that enforcement moved to the command.
- `tests/unit_tests/commands/dashboard/update_test.py` (new file) — `UpdateDashboardCommand` accepts an unchanged existing `css` value even when it contains `@import`, still rejects a genuinely new dangerous value, still rejects a changed value that's dangerous in a different way, and skips the check entirely when `css` isn't in the payload.
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(dashboards): close CSS validation gaps in dashboard import and edits [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #43666:
URL: https://github.com/apache/superset/pull/43666#issuecomment-5799183160
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers an incremental AI Review.
- `/review full` - Manually triggers a full AI Review.
- `/pause` - Pauses automatic reviews on this pull request.
- `/resume` - Resumes automatic reviews.
- `/resolve` - Marks all Bito-posted review comments as resolved.
- `/abort` - Cancels all in-progress reviews.
Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(dashboards): close CSS validation gaps in dashboard import and edits [superset]
Posted by "sadpandajoe (via GitHub)" <gi...@apache.org>.
sadpandajoe commented on code in PR #43666:
URL: https://github.com/apache/superset/pull/43666#discussion_r3989738293
##########
superset/dashboards/schemas.py:
##########
@@ -596,7 +601,7 @@ class GetFavStarIdsSchema(Schema):
class ImportV1DashboardSchema(Schema):
dashboard_title = fields.String(required=True)
description = fields.String(allow_none=True)
- css = fields.String(allow_none=True)
+ css = fields.String(allow_none=True, validate=validate_css)
Review Comment:
This rejects a same-version export containing grandfathered CSS even though the update path deliberately permits that stored value to remain: export serializes `Dashboard.css` verbatim, then this schema rejects the ZIP during restore or migration. Could the export/import path safely preserve that round trip, for example by explicitly cleaning or quarantining the CSS instead of making the generated bundle unimportable?
##########
superset/commands/dashboard/update.py:
##########
@@ -131,6 +132,19 @@ def validate(self) -> None:
except ValidationError as ex:
exceptions.append(ex)
+ # A dashboard PUT resends the full object on every save, so only
+ # validate css when it's actually changing -- otherwise a dashboard
+ # whose existing css predates this check (or was imported without
+ # going through it) becomes uneditable for unrelated changes like a
+ # rename or a chart move.
+ if "css" in self._properties:
+ new_css = self._properties["css"]
+ if new_css != self._model.css:
+ try:
+ validate_css(new_css)
Review Comment:
This moves dangerous-CSS failures from the existing schema-level 400 response with a `css` error into a command-level 422 whose direct `ValidationError` is keyed as `_schema`. Could we preserve the established status and field-shaped error contract when validating only changed CSS?
##########
superset/commands/dashboard/update.py:
##########
@@ -130,6 +131,19 @@ def validate(self) -> None:
except ValidationError as ex:
exceptions.append(ex)
+ # A dashboard PUT resends the full object on every save, so only
+ # validate css when it's actually changing -- otherwise a dashboard
+ # whose existing css predates this check (or was imported without
+ # going through it) becomes uneditable for unrelated changes like a
+ # rename or a chart move.
+ if "css" in self._properties:
+ new_css = self._properties["css"]
Review Comment:
This PR removes the schema guard only for CSS, so the general lost-update window becomes a validation bypass: request A can restore CSS that a direct PUT would now reject. Could we keep the lock or write-time recheck scoped to accepting an unchanged disallowed CSS value and cover that A/B sequence?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(dashboards): close CSS validation gaps in dashboard import and edits [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #43666:
URL: https://github.com/apache/superset/pull/43666#issuecomment-5687352641
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers an incremental AI Review.
- `/review full` - Manually triggers a full AI Review.
- `/pause` - Pauses automatic reviews on this pull request.
- `/resume` - Resumes automatic reviews.
- `/resolve` - Marks all Bito-posted review comments as resolved.
- `/abort` - Cancels all in-progress reviews.
Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(dashboards): close CSS validation gaps in dashboard import and edits [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #43666:
URL: https://github.com/apache/superset/pull/43666#issuecomment-5795111408
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers an incremental AI Review.
- `/review full` - Manually triggers a full AI Review.
- `/pause` - Pauses automatic reviews on this pull request.
- `/resume` - Resumes automatic reviews.
- `/resolve` - Marks all Bito-posted review comments as resolved.
- `/abort` - Cancels all in-progress reviews.
Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(dashboards): close CSS validation gaps in dashboard import and edits [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on code in PR #43666:
URL: https://github.com/apache/superset/pull/43666#discussion_r4018196572
##########
superset/commands/dashboard/update.py:
##########
@@ -131,6 +132,19 @@ def validate(self) -> None:
except ValidationError as ex:
exceptions.append(ex)
+ # A dashboard PUT resends the full object on every save, so only
+ # validate css when it's actually changing -- otherwise a dashboard
+ # whose existing css predates this check (or was imported without
+ # going through it) becomes uneditable for unrelated changes like a
+ # rename or a chart move.
+ if "css" in self._properties:
+ new_css = self._properties["css"]
+ if new_css != self._model.css:
+ try:
+ validate_css(new_css)
Review Comment:
Fixed, css errors come back keyed under "css" again instead of "_schema". Status stayed 422 though, thats the existing convention for command-level validation (slug uniqueness does the same), didnt want to special-case just this one field.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(dashboards): close CSS validation gaps in dashboard import and edits [superset]
Posted by "sadpandajoe (via GitHub)" <gi...@apache.org>.
sadpandajoe commented on code in PR #43666:
URL: https://github.com/apache/superset/pull/43666#discussion_r3890336418
##########
superset/commands/dashboard/update.py:
##########
@@ -130,6 +131,19 @@ def validate(self) -> None:
except ValidationError as ex:
exceptions.append(ex)
+ # A dashboard PUT resends the full object on every save, so only
+ # validate css when it's actually changing -- otherwise a dashboard
+ # whose existing css predates this check (or was imported without
+ # going through it) becomes uneditable for unrelated changes like a
+ # rename or a chart move.
+ if "css" in self._properties:
+ new_css = self._properties["css"]
Review Comment:
This changes the previous behavior for concurrent saves: before this change, the PUT schema rejected a stale `@import` value before the command ran. Now request A can read that value, skip this check because it matches its stale model, request B can replace it with safe CSS, and A can subsequently write its stale payload and restore the unsafe CSS. Could the exemption be conditioned on the persisted value at write time, or the update be serialized, so a concurrent cleanup cannot be undone?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(dashboards): close CSS validation gaps in dashboard import and edits [superset]
Posted by "sadpandajoe (via GitHub)" <gi...@apache.org>.
sadpandajoe commented on code in PR #43666:
URL: https://github.com/apache/superset/pull/43666#discussion_r4129232687
##########
superset/commands/dashboard/update.py:
##########
@@ -168,6 +169,24 @@ def validate(self) -> None:
except ValidationError as ex:
exceptions.append(ex)
+ # A dashboard PUT resends the full object on every save, so only
+ # validate css when it's actually changing -- otherwise a dashboard
+ # whose existing css predates this check (or was imported without
+ # going through it) becomes uneditable for unrelated changes like a
+ # rename or a chart move.
+ if "css" in self._properties:
+ new_css = self._properties["css"]
+ if new_css != self._model.css:
+ try:
+ validate_css(new_css)
+ except ValidationError as ex:
+ # Re-key under "css" -- validate_css() raises with the
+ # default "_schema" field_name, since it's also used as
+ # a marshmallow field validator elsewhere, where
+ # marshmallow assigns the field name itself regardless
+ # of what's set here.
+ exceptions.append(ValidationError(ex.messages, field_name="css"))
Review Comment:
This moves a rejected `css` value from the schema-level `ValidationError` path (`DashboardPutSchema.load()` failing, caught in the API view and returned as HTTP 400) to this command-level `DashboardInvalidError`, which the same view maps to HTTP 422 instead. A client or integration that branches on 400 vs. 422 for this PUT endpoint now gets a different status code for the same rejected `css` value than it did before this PR. Is that status change intentional, or should a rejected css value keep returning 400?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(dashboards): close CSS validation gaps in dashboard import and edits [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on code in PR #43666:
URL: https://github.com/apache/superset/pull/43666#discussion_r4031365382
##########
tests/unit_tests/commands/dashboard/update_test.py:
##########
@@ -166,3 +171,85 @@ def test_process_native_filter_diff_only_touches_reports_on_the_updated_dashboar
# NATIVE_FILTER-2 is the only one dropped from the new metadata.
report_dao.find_by_native_filter_id.assert_called_once_with("NATIVE_FILTER-2")
report_dao.update.assert_called_once_with(own_report, {"active": False})
+
+
+def _mock_dependencies(mocker: MockerFixture, existing_css: str) -> None:
+ model = mocker.MagicMock(id=1, tags=[], css=existing_css)
+ mocker.patch(
+ "superset.commands.dashboard.update.DashboardDAO.find_by_id",
+ return_value=model,
+ )
Review Comment:
Fixed, set `is_managed_externally=False` on the mock.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(dashboards): close CSS validation gaps in dashboard import and edits [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #43666:
URL: https://github.com/apache/superset/pull/43666#issuecomment-5553558277
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers an incremental AI Review.
- `/review full` - Manually triggers a full AI Review.
- `/pause` - Pauses automatic reviews on this pull request.
- `/resume` - Resumes automatic reviews.
- `/resolve` - Marks all Bito-posted review comments as resolved.
- `/abort` - Cancels all in-progress reviews.
Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(dashboards): close CSS validation gaps in dashboard import and edits [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas merged PR #43666:
URL: https://github.com/apache/superset/pull/43666
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(dashboards): close CSS validation gaps in dashboard import and edits [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on code in PR #43666:
URL: https://github.com/apache/superset/pull/43666#discussion_r4029856331
##########
tests/unit_tests/commands/dashboard/update_test.py:
##########
@@ -166,3 +171,85 @@ def test_process_native_filter_diff_only_touches_reports_on_the_updated_dashboar
# NATIVE_FILTER-2 is the only one dropped from the new metadata.
report_dao.find_by_native_filter_id.assert_called_once_with("NATIVE_FILTER-2")
report_dao.update.assert_called_once_with(own_report, {"active": False})
+
+
+def _mock_dependencies(mocker: MockerFixture, existing_css: str) -> None:
+ model = mocker.MagicMock(id=1, tags=[], css=existing_css)
+ mocker.patch(
+ "superset.commands.dashboard.update.DashboardDAO.find_by_id",
+ return_value=model,
+ )
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Mock missing managed flag</b></div>
<div id="fix">
The `MagicMock` model's `is_managed_externally` attribute defaults to a truthy MagicMock, so `raise_if_managed_externally()` (utils.py:96) raises `DashboardForbiddenError` in `validate()` (update.py:138-142) before the css check. All four new tests fail. Set `is_managed_externally=False` on the mock, matching the pattern in `test_update_managed_externally.py`.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
def _mock_dependencies(mocker: MockerFixture, existing_css: str) -> None:
model = mocker.MagicMock(id=1, tags=[], css=existing_css, is_managed_externally=False)
mocker.patch(
"superset.commands.dashboard.update.DashboardDAO.find_by_id",
return_value=model,
)
````
</div>
</details>
</div>
<small><i>Code Review Run #28bd22</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(dashboards): close CSS validation gaps in dashboard import and edits [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on code in PR #43666:
URL: https://github.com/apache/superset/pull/43666#discussion_r4031366306
##########
tests/unit_tests/commands/dashboard/update_test.py:
##########
@@ -166,3 +171,85 @@ def test_process_native_filter_diff_only_touches_reports_on_the_updated_dashboar
# NATIVE_FILTER-2 is the only one dropped from the new metadata.
report_dao.find_by_native_filter_id.assert_called_once_with("NATIVE_FILTER-2")
report_dao.update.assert_called_once_with(own_report, {"active": False})
+
+
+def _mock_dependencies(mocker: MockerFixture, existing_css: str) -> None:
+ model = mocker.MagicMock(id=1, tags=[], css=existing_css)
+ mocker.patch(
+ "superset.commands.dashboard.update.DashboardDAO.find_by_id",
+ return_value=model,
+ )
Review Comment:
<!-- Bito Reply -->
The update to set `is_managed_externally=False` in the mock is appropriate. This change ensures the mock correctly simulates a dashboard that is not managed externally, preventing the `DashboardForbiddenError` during validation and allowing the tests to proceed as expected.
**tests/unit_tests/commands/dashboard/update_test.py**
```
def _mock_dependencies(mocker: MockerFixture, existing_css: str) -> None:
model = mocker.MagicMock(id=1, tags=[], css=existing_css, is_managed_externally=False)
mocker.patch(
"superset.commands.dashboard.update.DashboardDAO.find_by_id",
return_value=model,
)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(dashboards): close CSS validation gaps in dashboard import and edits [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #43666:
URL: https://github.com/apache/superset/pull/43666#issuecomment-5635830511
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers an incremental AI Review.
- `/review full` - Manually triggers a full AI Review.
- `/pause` - Pauses automatic reviews on this pull request.
- `/resume` - Resumes automatic reviews.
- `/resolve` - Marks all Bito-posted review comments as resolved.
- `/abort` - Cancels all in-progress reviews.
Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(dashboards): close CSS validation gaps in dashboard import and edits [superset]
Posted by "sadpandajoe (via GitHub)" <gi...@apache.org>.
sadpandajoe commented on code in PR #43666:
URL: https://github.com/apache/superset/pull/43666#discussion_r4077090225
##########
superset/dashboards/schemas.py:
##########
@@ -596,7 +601,7 @@ class GetFavStarIdsSchema(Schema):
class ImportV1DashboardSchema(Schema):
dashboard_title = fields.String(required=True)
description = fields.String(allow_none=True)
- css = fields.String(allow_none=True)
+ css = fields.String(allow_none=True, validate=validate_css)
Review Comment:
@rusackas reviewed the prs again since your last commit and this still seems to be an issue.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(dashboards): close CSS validation gaps in dashboard import and edits [superset]
Posted by "sadpandajoe (via GitHub)" <gi...@apache.org>.
sadpandajoe commented on code in PR #43666:
URL: https://github.com/apache/superset/pull/43666#discussion_r4129232687
##########
superset/commands/dashboard/update.py:
##########
@@ -168,6 +169,24 @@ def validate(self) -> None:
except ValidationError as ex:
exceptions.append(ex)
+ # A dashboard PUT resends the full object on every save, so only
+ # validate css when it's actually changing -- otherwise a dashboard
+ # whose existing css predates this check (or was imported without
+ # going through it) becomes uneditable for unrelated changes like a
+ # rename or a chart move.
+ if "css" in self._properties:
+ new_css = self._properties["css"]
+ if new_css != self._model.css:
+ try:
+ validate_css(new_css)
+ except ValidationError as ex:
+ # Re-key under "css" -- validate_css() raises with the
+ # default "_schema" field_name, since it's also used as
+ # a marshmallow field validator elsewhere, where
+ # marshmallow assigns the field name itself regardless
+ # of what's set here.
+ exceptions.append(ValidationError(ex.messages, field_name="css"))
Review Comment:
This moves a rejected `css` value from the schema-level `ValidationError` path (`DashboardPutSchema.load()` failing, caught in the API view and returned as HTTP 400) to this command-level `DashboardInvalidError`, which the same view maps to HTTP 422 instead. A client or integration that branches on 400 vs. 422 for this PUT endpoint now gets a different status code for the same rejected `css` value than it did before this PR. Is that status change intentional, or should a rejected css value keep returning 400?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(dashboards): close CSS validation gaps in dashboard import and edits [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #43666:
URL: https://github.com/apache/superset/pull/43666#issuecomment-5703003077
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers an incremental AI Review.
- `/review full` - Manually triggers a full AI Review.
- `/pause` - Pauses automatic reviews on this pull request.
- `/resume` - Resumes automatic reviews.
- `/resolve` - Marks all Bito-posted review comments as resolved.
- `/abort` - Cancels all in-progress reviews.
Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(dashboards): close CSS validation gaps in dashboard import and edits [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #43666:
URL: https://github.com/apache/superset/pull/43666#issuecomment-5707065562
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers an incremental AI Review.
- `/review full` - Manually triggers a full AI Review.
- `/pause` - Pauses automatic reviews on this pull request.
- `/resume` - Resumes automatic reviews.
- `/resolve` - Marks all Bito-posted review comments as resolved.
- `/abort` - Cancels all in-progress reviews.
Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(dashboards): close CSS validation gaps in dashboard import and edits [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #43666:
URL: https://github.com/apache/superset/pull/43666#issuecomment-5459089078
<!-- Bito Reply -->
The flagged issue correctly identifies a potential race condition where a concurrent update could bypass CSS validation. To resolve this, you should perform the validation and the update within a database transaction that uses a row-level lock (e.g., `SELECT ... FOR UPDATE`).
In `superset/commands/dashboard/update.py`, you can modify the `run` method to lock the dashboard row before performing the validation and update:
```python
# Inside UpdateDashboardCommand.run()
from superset.extensions import db
# Lock the row for update
dashboard = db.session.query(Dashboard).with_for_update().get(self._model.id)
# Perform validation and update within the same transaction
self.validate()
DashboardDAO.update(dashboard, self._properties)
```
Would you like me to fetch all other comments on this PR to validate them and implement fixes for those as well?
**superset/commands/dashboard/update.py**
```
# Inside UpdateDashboardCommand.run()
from superset.extensions import db
# Lock the row for update
dashboard = db.session.query(Dashboard).with_for_update().get(self._model.id)
# Perform validation and update within the same transaction
self.validate()
DashboardDAO.update(dashboard, self._properties)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(dashboards): close CSS validation gaps in dashboard import and edits [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #43666:
URL: https://github.com/apache/superset/pull/43666#issuecomment-5459027714
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(dashboards): close CSS validation gaps in dashboard import and edits [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on code in PR #43666:
URL: https://github.com/apache/superset/pull/43666#discussion_r4081065732
##########
superset/dashboards/schemas.py:
##########
@@ -596,7 +601,7 @@ class GetFavStarIdsSchema(Schema):
class ImportV1DashboardSchema(Schema):
dashboard_title = fields.String(required=True)
description = fields.String(allow_none=True)
- css = fields.String(allow_none=True)
+ css = fields.String(allow_none=True, validate=validate_css)
Review Comment:
@sadpandajoe fair point on the round trip. Left it strict on purpose though: a bundle is not the same trust level as an existing row, could be from another instance or a stale/tampered export, so there is nothing safe to compare "unchanged" against. Added a comment in the schema spelling that out.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(dashboards): close CSS validation gaps in dashboard import and edits [superset]
Posted by "netlify[bot] (via GitHub)" <gi...@apache.org>.
netlify[bot] commented on PR #43666:
URL: https://github.com/apache/superset/pull/43666#issuecomment-5684625466
### <span aria-hidden="true">✅</span> Deploy Preview for *superset-docs-preview* ready!
| Name | Link |
|:-:|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | c99ebaf343a605f9d1c3d4f4b9162ed501da5055 |
|<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/projects/superset-docs-preview/deploys/6aa97a83f45e1b000848d947 |
|<span aria-hidden="true">😎</span> Deploy Preview | [https://deploy-preview-43666--superset-docs-preview.netlify.app](https://deploy-preview-43666--superset-docs-preview.netlify.app) |
|<span aria-hidden="true">📱</span> Preview on mobile | <details><summary> Toggle QR Code... </summary><br /><br /><br /><br />_Use your smartphone camera to open QR code link._</details> |
|<span aria-hidden="true">🤖</span> Make changes | [Run an agent on this branch](https://app.netlify.com/projects/superset-docs-preview/agent-runs#DctBDoQgDADAv_QskY2ouD_wGYViJFFKKNmsMf5dbnOZG3LhM1f4AnTgCia_N2_x3xPK7hgLKS-ifnhEwho5Kc9JotSQ_NUOhXzwtVJbE-Iyox02M4aP01pbY2kxMzwv) |
---
<!-- [superset-docs-preview Preview](https://deploy-preview-43666--superset-docs-preview.netlify.app) -->
_To edit notification comments on pull requests, go to your [Netlify project configuration](https://app.netlify.com/projects/superset-docs-preview/configuration/notifications#deploy-notifications)._
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(dashboards): close CSS validation gaps in dashboard import and edits [superset]
Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on code in PR #43666:
URL: https://github.com/apache/superset/pull/43666#discussion_r3884833357
##########
superset/commands/dashboard/update.py:
##########
@@ -130,6 +131,19 @@ def validate(self) -> None:
except ValidationError as ex:
exceptions.append(ex)
+ # A dashboard PUT resends the full object on every save, so only
+ # validate css when it's actually changing -- otherwise a dashboard
+ # whose existing css predates this check (or was imported without
+ # going through it) becomes uneditable for unrelated changes like a
+ # rename or a chart move.
+ if "css" in self._properties:
+ new_css = self._properties["css"]
+ if new_css != self._model.css:
+ try:
+ validate_css(new_css)
Review Comment:
**Suggestion:** The comparison and validation occur before `DashboardDAO.update` without locking or rechecking the row. If another request changes the stored CSS after this command reads `self._model.css` but before the update, an unrelated edit can skip validation and then write the stale, potentially dangerous `new_css` back over the concurrent safe value. Perform the comparison and write under a row lock or otherwise enforce the check atomically at update time. [race condition]
<details>
<summary><b>Severity Level:</b> Critical 🚨</summary>
```mdx
- ❌ Concurrent dashboard saves can restore dangerous persisted CSS.
- ❌ Custom CSS validation can be bypassed through stale full-object writes.
- ⚠️ Subsequent dashboard renders receive the reintroduced CSS.
```
</details>
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill) [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=918ae11c04c54e2584ca095e86b99d0c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=918ae11c04c54e2584ca095e86b99d0c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/commands/dashboard/update.py
**Line:** 139:143
**Comment:**
*Race Condition: The comparison and validation occur before `DashboardDAO.update` without locking or rechecking the row. If another request changes the stored CSS after this command reads `self._model.css` but before the update, an unrelated edit can skip validation and then write the stale, potentially dangerous `new_css` back over the concurrent safe value. Perform the comparison and write under a row lock or otherwise enforce the check atomically at update time.
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
```
</details>
<a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43666&comment_hash=6ef56a4c617eb680170cf7ba9d0f41f083750f07bfca851026a7f912279d5c1a&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43666&comment_hash=6ef56a4c617eb680170cf7ba9d0f41f083750f07bfca851026a7f912279d5c1a&reaction=dislike'>👎</a>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(dashboards): close CSS validation gaps in dashboard import and edits [superset]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #43666:
URL: https://github.com/apache/superset/pull/43666#issuecomment-5459057167
## [Codecov](https://app.codecov.io/gh/apache/superset/pull/43666?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `22.22222%` with `7 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 57.49%. Comparing base ([`30402b4`](https://app.codecov.io/gh/apache/superset/commit/30402b412c2c4f8a30b65419944d519143b3272b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`d89cc47`](https://app.codecov.io/gh/apache/superset/commit/d89cc476c918ab11504f6ab9a42980497fd208d5?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 1 commits behind head on master.
| [Files with missing lines](https://app.codecov.io/gh/apache/superset/pull/43666?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [superset/commands/dashboard/update.py](https://app.codecov.io/gh/apache/superset/pull/43666?src=pr&el=tree&filepath=superset%2Fcommands%2Fdashboard%2Fupdate.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvY29tbWFuZHMvZGFzaGJvYXJkL3VwZGF0ZS5weQ==) | 12.50% | [7 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/43666?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
> :exclamation: There is a different number of reports uploaded between BASE (30402b4) and HEAD (d89cc47). Click for more details.
>
> <details><summary>HEAD has 27 uploads less than BASE</summary>
>
>| Flag | BASE (30402b4) | HEAD (d89cc47) |
>|------|------|------|
>|python|24|2|
>|presto|4|1|
>|hive|3|1|
></details>
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #43666 +/- ##
===========================================
- Coverage 79.21% 57.49% -21.73%
===========================================
Files 2879 2879
Lines 166040 166048 +8
Branches 38405 38407 +2
===========================================
- Hits 131536 95466 -36070
- Misses 32025 69687 +37662
+ Partials 2479 895 -1584
```
| [Flag](https://app.codecov.io/gh/apache/superset/pull/43666/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [hive](https://app.codecov.io/gh/apache/superset/pull/43666/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `37.93% <22.22%> (-0.01%)` | :arrow_down: |
| [mysql](https://app.codecov.io/gh/apache/superset/pull/43666/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [postgres](https://app.codecov.io/gh/apache/superset/pull/43666/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [presto](https://app.codecov.io/gh/apache/superset/pull/43666/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `39.84% <22.22%> (-0.01%)` | :arrow_down: |
| [python](https://app.codecov.io/gh/apache/superset/pull/43666/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `39.89% <22.22%> (-43.85%)` | :arrow_down: |
| [sqlite](https://app.codecov.io/gh/apache/superset/pull/43666/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [unit](https://app.codecov.io/gh/apache/superset/pull/43666/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/superset/pull/43666?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(dashboards): close CSS validation gaps in dashboard import and edits [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on code in PR #43666:
URL: https://github.com/apache/superset/pull/43666#discussion_r3885180319
##########
superset/commands/dashboard/update.py:
##########
@@ -130,6 +131,19 @@ def validate(self) -> None:
except ValidationError as ex:
exceptions.append(ex)
+ # A dashboard PUT resends the full object on every save, so only
+ # validate css when it's actually changing -- otherwise a dashboard
+ # whose existing css predates this check (or was imported without
+ # going through it) becomes uneditable for unrelated changes like a
+ # rename or a chart move.
+ if "css" in self._properties:
+ new_css = self._properties["css"]
+ if new_css != self._model.css:
+ try:
+ validate_css(new_css)
Review Comment:
This read-then-write window exists for every field on this command, not just css, it's the general lost-update pattern for any PUT here. Row locking to close it would be a bigger change than this PR's scope (closing the css validation gap itself).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(dashboards): close CSS validation gaps in dashboard import and edits [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on code in PR #43666:
URL: https://github.com/apache/superset/pull/43666#discussion_r3897728600
##########
superset/commands/dashboard/update.py:
##########
@@ -130,6 +131,19 @@ def validate(self) -> None:
except ValidationError as ex:
exceptions.append(ex)
+ # A dashboard PUT resends the full object on every save, so only
+ # validate css when it's actually changing -- otherwise a dashboard
+ # whose existing css predates this check (or was imported without
+ # going through it) becomes uneditable for unrelated changes like a
+ # rename or a chart move.
+ if "css" in self._properties:
+ new_css = self._properties["css"]
Review Comment:
Same as codeant's thread above: `self._model` is already read at the top of this transaction, right before the write, so there isn't a later value to condition on without an explicit row lock. Felt like more than this PR's scope to add here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(dashboards): close CSS validation gaps in dashboard import and edits [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on code in PR #43666:
URL: https://github.com/apache/superset/pull/43666#discussion_r4118809560
##########
superset/commands/dashboard/update.py:
##########
@@ -130,6 +131,19 @@ def validate(self) -> None:
except ValidationError as ex:
exceptions.append(ex)
+ # A dashboard PUT resends the full object on every save, so only
+ # validate css when it's actually changing -- otherwise a dashboard
+ # whose existing css predates this check (or was imported without
+ # going through it) becomes uneditable for unrelated changes like a
+ # rename or a chart move.
+ if "css" in self._properties:
+ new_css = self._properties["css"]
Review Comment:
Fair, this is sharper than the general lost-update point and I didn't engage with it properly the first time. Traced through it again.
The race is real: A reads unchanged unsafe css (skips validation), B concurrently writes safe css, A's write lands after and clobbers B's fix. But I don't think it grants a new capability, it only affects whether an admin's concurrent cleanup can get silently undone. The css has to already be sitting in the DB as unsafe for there to be anything to restore, same exposure that exists right now for any grandfathered row with no race involved at all.
A real fix means either a row lock or a compare-and-swap on the actual UPDATE (`WHERE css = :expected`), and `DashboardDAO.update` is generic across every field this command touches, not css-specific, so either approach reaches well past this PR into how updates work here in general. Still think that's its own piece of work rather than something to bolt on to closing the validation gap. Want to see it tracked as a follow-up if you agree, rather than block this on it, that concurrent-write integrity question keeps surfacing and probably deserves its own look regardless of css.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org