Require permissions on assistant endpoints and validate sampled table names - #710
Merged
Merged
Conversation
… names AssistantHelpView and AssistantHistoryApiView had no permission check, and table names from the request's selected_tables were interpolated directly into the row-sampling SQL. - Both assistant API views now require change_permission, matching the playground where the assistant is used. - build_prompt only samples tables that exist in the connection's schema (respecting include/exclude prefixes), using the introspected name. - sample_rows_from_table quotes the table name via connection.ops.quote_name. Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a reported security issue in the AI assistant endpoints.
AssistantHelpView(/assistant/) andAssistantHistoryApiView(/assistant/history/) were plainViews with no permission check, unlike every other Explorer view. The routes are registered even when noEXPLORER_AI_API_KEYis configured. Both now usePermissionRequiredMixinwithchange_permission, matching the playground, which is where the assistant is used.selected_tableswere put intoSELECT * FROM {table_name} ...via an f-string.table_schema()returnedNonefor unknown tables, but nothing checked that result before sampling rows.build_promptnow resolves each requested table through a newfind_table()helper against the connection's schema (which honors the include/exclude prefixes). It skips tables that aren't found and uses the introspected table name.sample_rows_from_tablealso quotes the name withconnection.ops.quote_nameas defense in depth.Tests
run_assistantis never called for them.build_promptskips table names that aren't in the schema.sample_rows_from_tablequotes the identifier.masterand pass with this change.build_prompttests to patchfind_table, and fixed mocks that assignedMagicMock(the class) instead ofMagicMock()(an instance).explorer.tests.settings.test_assistantalso passes undersettings_base.🤖 Generated with Claude Code