audit follow-up: burn down lint hotspots and dedupe channel gating flows

This commit is contained in:
William Valentin
2026-02-15 22:44:04 -08:00
parent 06ff94e197
commit 1a075e62b0
10 changed files with 518 additions and 281 deletions
+34 -36
View File
@@ -15,7 +15,14 @@ import type {
ChannelAdapter,
ChannelStatus,
} from '../types.js';
import { buildResetInboundMessage, normalizeResetCommandText, splitMessage } from '../utils.js';
import {
allowTrustedOrPairedSender,
buildResetInboundMessage,
isAllowedByAllowlist,
normalizeResetCommandText,
shouldIgnoreForMissingMention,
splitMessage,
} from '../utils.js';
import type { PairingManager } from '../pairing.js';
/** Configuration for the Slack channel adapter. */
@@ -295,46 +302,37 @@ export class SlackAdapter implements ChannelAdapter {
if (!channelId) {return;}
// Check allowed channel IDs
if (
this.config.allowedChannelIds &&
this.config.allowedChannelIds.length > 0 &&
!this.config.allowedChannelIds.includes(channelId)
) {
// Pairing fallback — check if the Slack user is approved or sending a valid code
const pm = this.config.pairingManager;
const userId = message.user;
if (pm?.enabled && userId) {
if (pm.isApproved('slack', userId)) {
// Approved — fall through to normal message handling
} else {
const text = (message.text ?? '').trim();
if (text && pm.validateCode('slack', userId, text)) {
// Code validated — send confirmation via Slack
if (this.app) {
const threadTs = message.thread_ts ?? message.ts ?? '';
try {
await this.app.client.chat.postMessage({
channel: channelId,
text: 'Pairing successful! You can now chat with Flynn.',
thread_ts: threadTs || undefined,
});
} catch { /* ignore send errors */ }
}
}
return;
}
} else {
if (!isAllowedByAllowlist(channelId, this.config.allowedChannelIds)) {
const senderId = message.user ?? '';
const allowed = await allowTrustedOrPairedSender({
pairingManager: this.config.pairingManager,
channel: 'slack',
senderId,
text: message.text ?? '',
isTrusted: false,
onPaired: async () => {
if (!this.app) {return;}
const threadTs = message.thread_ts ?? message.ts ?? '';
await this.app.client.chat.postMessage({
channel: channelId,
text: 'Pairing successful! You can now chat with Flynn.',
thread_ts: threadTs || undefined,
});
},
});
if (!allowed) {
return;
}
}
// Mention requirement
const requireMention = this.config.requireMention ?? false;
if (requireMention && this.botUserId) {
const mentionPattern = `<@${this.botUserId}>`;
if (!(message.text ?? '').includes(mentionPattern)) {
return;
}
const mentionPattern = this.botUserId ? `<@${this.botUserId}>` : undefined;
if (shouldIgnoreForMissingMention({
requireMention: mentionPattern ? this.config.requireMention : false,
defaultRequireMention: false,
mentionsBot: mentionPattern ? (message.text ?? '').includes(mentionPattern) : false,
})) {
return;
}
// Note: Slack doesn't expose a typing indicator API for bots