Skip to content

feat: log unsafe queries to Slack for better monitoring#1651

Merged
Artuomka merged 1 commit intomainfrom
backend_unsafe_query_logging
Mar 6, 2026
Merged

feat: log unsafe queries to Slack for better monitoring#1651
Artuomka merged 1 commit intomainfrom
backend_unsafe_query_logging

Conversation

@Artuomka
Copy link
Collaborator

@Artuomka Artuomka commented Mar 6, 2026

No description provided.

Copilot AI review requested due to automatic review settings March 6, 2026 10:48
@Artuomka Artuomka enabled auto-merge March 6, 2026 10:49
@Artuomka Artuomka disabled auto-merge March 6, 2026 10:51
@Artuomka Artuomka enabled auto-merge March 6, 2026 10:51
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds Slack notifications when validateQuerySafety rejects a query, to improve monitoring of unsafe/read-write query attempts across panel creation/execution and AI-generated panels.

Changes:

  • Import and invoke slackPostMessage when a query is deemed unsafe.
  • Include query text, rejection reason, and connection type in the Slack message.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -1,5 +1,6 @@
import { BadRequestException } from '@nestjs/common';
import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js';
import { slackPostMessage } from '../../../../helpers/index.js';
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

Importing slackPostMessage into this low-level query-safety utility introduces a network/IO side effect and a dependency on the Slack helper into code that otherwise acts like a pure validator. This makes the function harder to reuse/test and also prevents callers from attaching context (e.g., userId/connectionId) or choosing different reporting behavior. Consider keeping validateQuerySafety side-effect free and moving the Slack notification to the use-cases/controllers (or injecting an optional reporter callback).

Suggested change
import { slackPostMessage } from '../../../../helpers/index.js';

Copilot uses AI. Check for mistakes.
Comment on lines +247 to 248
slackPostMessage(`Unsafe query: ${query}\nReason: ${result.reason}\nConnection Type: ${connectionType}`);
throw new BadRequestException(`Unsafe query: ${result.reason}. Only read-only queries are allowed.`);
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

This posts the full raw query text to Slack. Since queries can contain sensitive information (table/column names, tenant identifiers, literal values, etc.) and are user-controlled, this can cause unintended data exposure and may violate privacy/compliance expectations. Prefer logging a redacted/truncated form (e.g., remove string/numeric literals, cap length) and/or a hash + metadata, and consider a dedicated Slack channel or feature-flagging this behavior.

Copilot uses AI. Check for mistakes.
Comment on lines +247 to 248
slackPostMessage(`Unsafe query: ${query}\nReason: ${result.reason}\nConnection Type: ${connectionType}`);
throw new BadRequestException(`Unsafe query: ${result.reason}. Only read-only queries are allowed.`);
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

Posting a Slack message for every rejected query can be very noisy and can be abused to generate high Slack volume (and outbound HTTP traffic) by repeatedly submitting unsafe queries. Consider adding throttling/sampling, limiting to certain request sources (e.g., AI-generated queries only), or guarding with an environment flag so it can be enabled for monitoring without impacting normal operation.

Copilot uses AI. Check for mistakes.
@Artuomka Artuomka disabled auto-merge March 6, 2026 11:00
@Artuomka Artuomka merged commit 18d0a31 into main Mar 6, 2026
21 of 23 checks passed
@Artuomka Artuomka deleted the backend_unsafe_query_logging branch March 6, 2026 11:00
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