A tool for parsing traffic on the jetstream and applying a moderation workstream based on regexp based rules

feat: Add global allowlist for DIDs

This adds a global allowlist to bypass moderation checks for specified
DIDs. This is to allow certain accounts to bypass checks for testing and
other use cases.

The allowlist is checked in checkHandles, checkPosts, checkProfiles, and
checkDisplayName functions.

+132 -10
+10
src/checkHandles.ts
··· 5 5 createAccountComment, 6 6 createAccountLabel, 7 7 } from "./moderation.js"; 8 + import { GLOBAL_ALLOW } from "./constants.js"; 8 9 9 10 export const checkHandle = async ( 10 11 did: string, 11 12 handle: string, 12 13 time: number, 13 14 ) => { 15 + // Check if DID is whitelisted 16 + if (!GLOBAL_ALLOW.includes(did)) { 17 + logger.warn( 18 + { process: "CHECKHANDLE", did, handle, time }, 19 + "Global AllowListed DID", 20 + ); 21 + return; 22 + } 23 + 14 24 // iterate through the checks 15 25 HANDLE_CHECKS.forEach((checkList) => { 16 26 if (checkList.ignoredDIDs) {
+9
src/checkPosts.ts
··· 9 9 createPostReport, 10 10 } from "./moderation.js"; 11 11 import { getFinalUrl, getLanguage } from "./utils.js"; 12 + import { GLOBAL_ALLOW } from "./constants.js"; 12 13 13 14 export const checkPosts = async (post: Post[]) => { 15 + if (!GLOBAL_ALLOW.includes(post[0].did)) { 16 + logger.warn( 17 + { process: "CHECKPOSTS", did: post[0].did, atURI: post[0].atURI }, 18 + "Global AllowListed DID", 19 + ); 20 + return; 21 + } 22 + 14 23 const urlRegex = /https?:\/\/[^\s]+/g; 15 24 16 25 // Check for link shorteners
+113 -10
src/checkProfiles.ts
··· 6 6 createAccountComment, 7 7 } from "./moderation.js"; 8 8 import { getLanguage } from "./utils.js"; 9 + import { GLOBAL_ALLOW } from "./constants.js"; 9 10 10 11 export const checkDescription = async ( 11 12 did: string, ··· 15 16 ) => { 16 17 const lang = await getLanguage(description); 17 18 19 + // Check if DID is whitelisted 20 + if (!GLOBAL_ALLOW.includes(did)) { 21 + logger.warn( 22 + { process: "CHECKDESCRIPTION", did, time, displayName, description }, 23 + "Global AllowListed DID", 24 + ); 25 + return; 26 + } 27 + 18 28 // iterate through the checks 19 29 PROFILE_CHECKS.forEach((checkProfiles) => { 20 30 if (checkProfiles.language) { ··· 26 36 // Check if DID is whitelisted 27 37 if (checkProfiles.ignoredDIDs) { 28 38 if (checkProfiles.ignoredDIDs.includes(did)) { 29 - logger.debug({ process: "CHECKDESCRIPTION", did, time, displayName, description }, "Whitelisted DID"); 39 + logger.debug( 40 + { process: "CHECKDESCRIPTION", did, time, displayName, description }, 41 + "Whitelisted DID", 42 + ); 30 43 return; 31 44 } 32 45 } ··· 37 50 // Check if description is whitelisted 38 51 if (checkProfiles.whitelist) { 39 52 if (checkProfiles.whitelist.test(description)) { 40 - logger.debug({ process: "CHECKDESCRIPTION", did, time, displayName, description }, "Whitelisted phrase found"); 53 + logger.debug( 54 + { 55 + process: "CHECKDESCRIPTION", 56 + did, 57 + time, 58 + displayName, 59 + description, 60 + }, 61 + "Whitelisted phrase found", 62 + ); 41 63 return; 42 64 } 43 65 } ··· 48 70 `${checkProfiles.label}`, 49 71 `${time}: ${checkProfiles.comment} - ${displayName} - ${description}`, 50 72 ); 51 - logger.info({ process: "CHECKDESCRIPTION", did, time, displayName, description, label: checkProfiles.label }, "Labeling account"); 73 + logger.info( 74 + { 75 + process: "CHECKDESCRIPTION", 76 + did, 77 + time, 78 + displayName, 79 + description, 80 + label: checkProfiles.label, 81 + }, 82 + "Labeling account", 83 + ); 52 84 } 53 85 54 86 if (checkProfiles.reportAcct === true) { ··· 56 88 did, 57 89 `${time}: ${checkProfiles.comment} - ${displayName} - ${description}`, 58 90 ); 59 - logger.info({ process: "CHECKDESCRIPTION", did, time, displayName, description, label: checkProfiles.label }, "Reporting account"); 91 + logger.info( 92 + { 93 + process: "CHECKDESCRIPTION", 94 + did, 95 + time, 96 + displayName, 97 + description, 98 + label: checkProfiles.label, 99 + }, 100 + "Reporting account", 101 + ); 60 102 } 61 103 62 104 if (checkProfiles.commentAcct === true) { ··· 64 106 did, 65 107 `${time}: ${checkProfiles.comment} - ${displayName} - ${description}`, 66 108 ); 67 - logger.info({ process: "CHECKDESCRIPTION", did, time, displayName, description, label: checkProfiles.label }, "Commenting on account"); 109 + logger.info( 110 + { 111 + process: "CHECKDESCRIPTION", 112 + did, 113 + time, 114 + displayName, 115 + description, 116 + label: checkProfiles.label, 117 + }, 118 + "Commenting on account", 119 + ); 68 120 } 69 121 } 70 122 } ··· 78 130 displayName: string, 79 131 description: string, 80 132 ) => { 133 + // Check if DID is whitelisted 134 + if (!GLOBAL_ALLOW.includes(did)) { 135 + logger.warn( 136 + { process: "CHECKDISPLAYNAME", did, time, displayName, description }, 137 + "Global AllowListed DID", 138 + ); 139 + return; 140 + } 141 + 81 142 const lang = await getLanguage(description); 82 143 83 144 // iterate through the checks ··· 91 152 // Check if DID is whitelisted 92 153 if (checkProfiles.ignoredDIDs) { 93 154 if (checkProfiles.ignoredDIDs.includes(did)) { 94 - logger.debug({ process: "CHECKDISPLAYNAME", did, time, displayName, description }, "Whitelisted DID"); 155 + logger.debug( 156 + { process: "CHECKDISPLAYNAME", did, time, displayName, description }, 157 + "Whitelisted DID", 158 + ); 95 159 return; 96 160 } 97 161 } ··· 102 166 // Check if displayName is whitelisted 103 167 if (checkProfiles.whitelist) { 104 168 if (checkProfiles.whitelist.test(displayName)) { 105 - logger.debug({ process: "CHECKDISPLAYNAME", did, time, displayName, description }, "Whitelisted phrase found"); 169 + logger.debug( 170 + { 171 + process: "CHECKDISPLAYNAME", 172 + did, 173 + time, 174 + displayName, 175 + description, 176 + }, 177 + "Whitelisted phrase found", 178 + ); 106 179 return; 107 180 } 108 181 } ··· 113 186 `${checkProfiles.label}`, 114 187 `${time}: ${checkProfiles.comment} - ${displayName} - ${description}`, 115 188 ); 116 - logger.info({ process: "CHECKDISPLAYNAME", did, time, displayName, description, label: checkProfiles.label }, "Labeling account"); 189 + logger.info( 190 + { 191 + process: "CHECKDISPLAYNAME", 192 + did, 193 + time, 194 + displayName, 195 + description, 196 + label: checkProfiles.label, 197 + }, 198 + "Labeling account", 199 + ); 117 200 } 118 201 119 202 if (checkProfiles.reportAcct === true) { ··· 121 204 did, 122 205 `${time}: ${checkProfiles.comment} - ${displayName} - ${description}`, 123 206 ); 124 - logger.info({ process: "CHECKDISPLAYNAME", did, time, displayName, description, label: checkProfiles.label }, "Reporting account"); 207 + logger.info( 208 + { 209 + process: "CHECKDISPLAYNAME", 210 + did, 211 + time, 212 + displayName, 213 + description, 214 + label: checkProfiles.label, 215 + }, 216 + "Reporting account", 217 + ); 125 218 } 126 219 127 220 if (checkProfiles.commentAcct === true) { ··· 129 222 did, 130 223 `${time}: ${checkProfiles.comment} - ${displayName} - ${description}`, 131 224 ); 132 - logger.info({ process: "CHECKDISPLAYNAME", did, time, displayName, description, label: checkProfiles.label }, "Commenting on account"); 225 + logger.info( 226 + { 227 + process: "CHECKDISPLAYNAME", 228 + did, 229 + time, 230 + displayName, 231 + description, 232 + label: checkProfiles.label, 233 + }, 234 + "Commenting on account", 235 + ); 133 236 } 134 237 } 135 238 }