-
-
Notifications
You must be signed in to change notification settings - Fork 18
feat: log unsafe queries to Slack for better monitoring #1651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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'; | ||
|
|
||
| const FORBIDDEN_SQL_KEYWORDS = [ | ||
| 'INSERT', | ||
|
|
@@ -243,6 +244,7 @@ export function validateQuerySafety(query: string, connectionType: ConnectionTyp | |
| const result = checker(query); | ||
|
|
||
| if (!result.isSafe) { | ||
| slackPostMessage(`Unsafe query: ${query}\nReason: ${result.reason}\nConnection Type: ${connectionType}`); | ||
| throw new BadRequestException(`Unsafe query: ${result.reason}. Only read-only queries are allowed.`); | ||
|
Comment on lines
+247
to
248
|
||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Importing
slackPostMessageinto 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 keepingvalidateQuerySafetyside-effect free and moving the Slack notification to the use-cases/controllers (or injecting an optional reporter callback).