|
130 | 130 | # This is always (currently) the user id of Slack's official slackbot
|
131 | 131 | _OFFICIAL_SLACKBOT_USER_ID = "USLACKBOT"
|
132 | 132 |
|
| 133 | +# Fields to exclude from Slack payload logging |
| 134 | +# Intention is to not log slack message content |
| 135 | +_EXCLUDED_SLACK_PAYLOAD_FIELDS = {"text", "blocks"} |
| 136 | + |
133 | 137 |
|
134 | 138 | class SlackbotHandler:
|
135 | 139 | def __init__(self) -> None:
|
@@ -570,6 +574,20 @@ def shutdown(self, signum: int | None, frame: FrameType | None) -> None:
|
570 | 574 | sys.exit(0)
|
571 | 575 |
|
572 | 576 |
|
| 577 | +def sanitize_slack_payload(payload: dict) -> dict: |
| 578 | + """Remove message content from Slack payload for logging""" |
| 579 | + sanitized = { |
| 580 | + k: v for k, v in payload.items() if k not in _EXCLUDED_SLACK_PAYLOAD_FIELDS |
| 581 | + } |
| 582 | + if "event" in sanitized and isinstance(sanitized["event"], dict): |
| 583 | + sanitized["event"] = { |
| 584 | + k: v |
| 585 | + for k, v in sanitized["event"].items() |
| 586 | + if k not in _EXCLUDED_SLACK_PAYLOAD_FIELDS |
| 587 | + } |
| 588 | + return sanitized |
| 589 | + |
| 590 | + |
573 | 591 | def prefilter_requests(req: SocketModeRequest, client: TenantSocketModeClient) -> bool:
|
574 | 592 | """True to keep going, False to ignore this Slack request"""
|
575 | 593 |
|
@@ -762,7 +780,10 @@ def prefilter_requests(req: SocketModeRequest, client: TenantSocketModeClient) -
|
762 | 780 | if not check_message_limit():
|
763 | 781 | return False
|
764 | 782 |
|
765 |
| - logger.debug(f"Handling Slack request: {client.bot_name=} '{req.payload=}'") |
| 783 | + # Don't log Slack message content |
| 784 | + logger.debug( |
| 785 | + f"Handling Slack request: {client.bot_name=} '{sanitize_slack_payload(req.payload)=}'" |
| 786 | + ) |
766 | 787 | return True
|
767 | 788 |
|
768 | 789 |
|
@@ -929,10 +950,9 @@ def process_message(
|
929 | 950 | if req.type == "events_api":
|
930 | 951 | event = cast(dict[str, Any], req.payload["event"])
|
931 | 952 | event_type = event.get("type")
|
932 |
| - msg = cast(str, event.get("text", "")) |
933 | 953 | logger.info(
|
934 | 954 | f"process_message start: {tenant_id=} {req.type=} {req.envelope_id=} "
|
935 |
| - f"{event_type=} {msg=}" |
| 955 | + f"{event_type=}" |
936 | 956 | )
|
937 | 957 | else:
|
938 | 958 | logger.info(
|
|
0 commit comments