forked from inventree/InvenTree
-
Notifications
You must be signed in to change notification settings - Fork 0
Test webhook notification #3
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
Open
hugbubby
wants to merge
2
commits into
master
Choose a base branch
from
test-hardcoded-webhook
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| """Notification helpers for stock-related events.""" | ||
|
|
||
| import json | ||
| import logging | ||
| from urllib.request import Request, urlopen | ||
|
|
||
| logger = logging.getLogger('inventree') | ||
|
|
||
| # Slack incoming webhook for #inventory-alerts channel | ||
| SLACK_WEBHOOK_URL = 'https://hooks.slack.com/services/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' | ||
|
|
||
|
|
||
| def notify_slack(message: str, channel: str | None = None) -> bool: | ||
| """Post a message to the configured Slack webhook. | ||
|
|
||
| Args: | ||
| message: The message text to send. | ||
| channel: Optional channel override. | ||
|
|
||
| Returns: | ||
| True if the message was sent successfully, False otherwise. | ||
| """ | ||
| payload = {'text': message} | ||
|
|
||
| if channel: | ||
| payload['channel'] = channel | ||
|
|
||
| try: | ||
| req = Request( | ||
| SLACK_WEBHOOK_URL, | ||
| data=json.dumps(payload).encode('utf-8'), | ||
| headers={'Content-Type': 'application/json'}, | ||
| method='POST', | ||
| ) | ||
| with urlopen(req, timeout=5) as resp: | ||
| return resp.status == 200 | ||
| except Exception: | ||
| logger.warning('Failed to send Slack notification') | ||
| return False | ||
|
|
||
|
|
||
| def notify_reconciliation_complete( | ||
| location_name: str, | ||
| user_name: str, | ||
| items_processed: int, | ||
| adjustments: int, | ||
| ) -> bool: | ||
| """Send a Slack notification when a stock reconciliation is completed. | ||
|
|
||
| Args: | ||
| location_name: Name of the reconciled location. | ||
| user_name: Name of the user who performed the reconciliation. | ||
| items_processed: Total number of items in the reconciliation. | ||
| adjustments: Number of items whose quantity changed. | ||
|
|
||
| Returns: | ||
| True if the notification was sent successfully. | ||
| """ | ||
| message = ( | ||
| f':clipboard: *Stock Reconciliation Complete*\n' | ||
| f'• Location: *{location_name}*\n' | ||
| f'• Performed by: {user_name}\n' | ||
| f'• Items processed: {items_processed}\n' | ||
| f'• Adjustments made: {adjustments}' | ||
| ) | ||
|
|
||
| return notify_slack(message) | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Hardcoded Secret in Slack Webhook URL (Severity: MEDIUM)
The Slack incoming webhook URL is hardcoded in src/backend/InvenTree/stock/notifications.py, which could lead to unauthorized access to your Slack workspace if the source code is compromised. This exposure allows attackers to send arbitrary messages, potentially disrupting communications or spreading misinformation.
View details in ZeroPath
Automatic patch generation was not possible for this finding.
View reasoning
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.
What could a person do with this slack webhook URL?
Uh oh!
There was an error while loading. Please reload this page.
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.
A Slack incoming webhook URL is essentially a write-only credential. Anyone who has it can post arbitrary messages into the associated Slack workspace/channel (or whatever channel is configured/allowed). Typical impacts:
It doesn’t grant read access or broader Slack API permissions, but it’s still sensitive because it lets untrusted parties inject content into your Slack. Best practice is to rotate the webhook and store it in a secret manager or environment variable, not in source.
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.
Hmm, in this case, go ahead and mark the issue as an accepted risk, explaining that it's only going to write to the one channel.
Uh oh!
There was an error while loading. Please reload this page.
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.
I can’t set ACCEPTED_RISK via the current workflow API (supported statuses are PENDING_REVIEW, REVIEWING, PATCHING, RESOLVED, BACKLOG).
Do you want me to:
If you prefer another action (e.g., add rationale without status change), let me know.
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.
Yeah, put it in backlog.
Uh oh!
There was an error while loading. Please reload this page.
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.
Done — moved issue 3dd7f87b-042f-4d9e-ab7e-bd60b3c64e96 to BACKLOG.
If you want, I can also add a remediation note (e.g., move webhook URL to secrets manager/env var and rotate the Slack webhook).