@acepaste/ingress 0.9.1 → 0.9.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/dist/src/adapters.d.ts +9 -0
- package/dist/src/adapters.js +76 -6
- package/dist/src/agent-hooks.d.ts +112 -0
- package/dist/src/agent-hooks.js +533 -0
- package/dist/src/approvers.d.ts +16 -0
- package/dist/src/approvers.js +50 -0
- package/dist/src/audio.d.ts +70 -0
- package/dist/src/audio.js +224 -0
- package/dist/src/audit-changes.d.ts +46 -0
- package/dist/src/audit-changes.js +110 -0
- package/dist/src/audit-local.d.ts +57 -0
- package/dist/src/audit-local.js +231 -0
- package/dist/src/audit-parsers.d.ts +1 -1
- package/dist/src/audit.js +48 -0
- package/dist/src/broker.d.ts +92 -1
- package/dist/src/broker.js +222 -3
- package/dist/src/calendar.d.ts +36 -0
- package/dist/src/calendar.js +227 -0
- package/dist/src/captions.d.ts +44 -0
- package/dist/src/captions.js +209 -0
- package/dist/src/changes.d.ts +105 -0
- package/dist/src/changes.js +174 -0
- package/dist/src/character.js +19 -3
- package/dist/src/classifier-model.d.ts +53 -0
- package/dist/src/classifier-model.js +3 -0
- package/dist/src/classifier.d.ts +41 -0
- package/dist/src/classifier.js +213 -0
- package/dist/src/cli.js +501 -1
- package/dist/src/codepass.d.ts +8 -0
- package/dist/src/codepass.js +39 -1
- package/dist/src/egress.d.ts +71 -0
- package/dist/src/egress.js +242 -0
- package/dist/src/email.d.ts +42 -0
- package/dist/src/email.js +424 -0
- package/dist/src/engine.d.ts +35 -12
- package/dist/src/engine.js +172 -45
- package/dist/src/image-meta.d.ts +33 -0
- package/dist/src/image-meta.js +433 -0
- package/dist/src/image.d.ts +104 -0
- package/dist/src/image.js +347 -0
- package/dist/src/index.d.ts +50 -5
- package/dist/src/index.js +28 -3
- package/dist/src/localguard.d.ts +33 -0
- package/dist/src/localguard.js +61 -0
- package/dist/src/meaning.d.ts +2 -0
- package/dist/src/meaning.js +348 -25
- package/dist/src/messages.d.ts +79 -0
- package/dist/src/messages.js +431 -0
- package/dist/src/multilingual.d.ts +3 -0
- package/dist/src/multilingual.js +117 -5
- package/dist/src/nearby.d.ts +52 -0
- package/dist/src/nearby.js +186 -0
- package/dist/src/netpolicy.js +50 -19
- package/dist/src/normalize.d.ts +36 -1
- package/dist/src/normalize.js +186 -4
- package/dist/src/provenance.d.ts +56 -0
- package/dist/src/provenance.js +114 -0
- package/dist/src/qr.d.ts +25 -0
- package/dist/src/qr.js +113 -0
- package/dist/src/safeguards.d.ts +61 -0
- package/dist/src/safeguards.js +199 -0
- package/dist/src/served.d.ts +20 -0
- package/dist/src/served.js +53 -0
- package/dist/src/shell-commands.d.ts +39 -0
- package/dist/src/shell-commands.js +291 -0
- package/dist/src/shortcuts.d.ts +45 -0
- package/dist/src/shortcuts.js +220 -0
- package/dist/src/stream.d.ts +88 -0
- package/dist/src/stream.js +119 -0
- package/dist/src/terminal.d.ts +29 -0
- package/dist/src/terminal.js +313 -0
- package/dist/src/tooldefs.d.ts +84 -0
- package/dist/src/tooldefs.js +122 -0
- package/dist/src/types.d.ts +50 -6
- package/dist/src/types.js +15 -2
- package/dist/src/visibility.d.ts +23 -3
- package/dist/src/visibility.js +285 -78
- package/native/ingress-presence.swift +48 -0
- package/native/ingress-vision.swift +417 -0
- package/package.json +4 -2
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Messages and notifications: chat, text messages, and the banners an operating system shows.
|
|
3
|
+
*
|
|
4
|
+
* These are the channels where anyone can write to you. In a group chat or a shared channel one participant's
|
|
5
|
+
* message is, to an assistant reading the conversation, as present as everyone else's. A text message comes
|
|
6
|
+
* from a number. A notification says who it is from, and the claim costs nothing to make.
|
|
7
|
+
*
|
|
8
|
+
* The adapters turn each message into segments and check what the channel's own structure gives away:
|
|
9
|
+
*
|
|
10
|
+
* what the app shows vs. what an API consumer reads Slack renders `blocks` and keeps `text` for
|
|
11
|
+
* notifications; Teams has a `summary` beside the body. Words in the unseen one are concealed text.
|
|
12
|
+
* link previews written by the linked site, not the sender; a preview's plain-text fallback is
|
|
13
|
+
* shown nowhere
|
|
14
|
+
* sender names a display name is free text: "System", "IT Support", "[ADMIN]" from a bot, a
|
|
15
|
+
* webhook or an outsider is a costume
|
|
16
|
+
* scam shape an unknown sender, a link that hides where it goes, and pressure or a request for
|
|
17
|
+
* a code, a password or a payment
|
|
18
|
+
* verification codes noted: a code in a message is for the person. The action broker refuses to let
|
|
19
|
+
* one be sent to a destination that came from content (see egress.ts)
|
|
20
|
+
* notifications an alarm in the system's or a brand's voice, delivered by a web browser
|
|
21
|
+
*
|
|
22
|
+
* Trust is per scan. A caller that knows a conversation is with a known contact says so with `source.trust`;
|
|
23
|
+
* a group chat or channel is an open channel (5), an unknown number a stranger (4).
|
|
24
|
+
*
|
|
25
|
+
* Not inspected, and said so: voice messages, stickers, files. Pictures go through scanImage when the caller
|
|
26
|
+
* has their bytes.
|
|
27
|
+
*/
|
|
28
|
+
import { decodeEntities } from "./adapters.js";
|
|
29
|
+
import { analyzeHtml } from "./visibility.js";
|
|
30
|
+
import { passagesOnlyIn } from "./served.js";
|
|
31
|
+
import { oneTimeCodes } from "./egress.js";
|
|
32
|
+
const str = (v) => (typeof v === "string" ? v : "");
|
|
33
|
+
const obj = (v) => (v && typeof v === "object" && !Array.isArray(v) ? v : undefined);
|
|
34
|
+
const arr = (v) => (Array.isArray(v) ? v : []);
|
|
35
|
+
const MAX_ITEMS = 500;
|
|
36
|
+
/** text of Slack's block kit: what the app renders when blocks are present */
|
|
37
|
+
function blockText(blocks, out = [], depth = 0) {
|
|
38
|
+
if (depth > 8)
|
|
39
|
+
return out;
|
|
40
|
+
for (const b of arr(blocks)) {
|
|
41
|
+
const o = obj(b);
|
|
42
|
+
if (!o)
|
|
43
|
+
continue;
|
|
44
|
+
const t = o.text;
|
|
45
|
+
if (typeof t === "string")
|
|
46
|
+
out.push(t);
|
|
47
|
+
else if (obj(t) && typeof obj(t).text === "string")
|
|
48
|
+
out.push(obj(t).text);
|
|
49
|
+
for (const k of ["fields", "elements", "accessory", "title", "label", "description", "placeholder", "alt_text"]) {
|
|
50
|
+
const v = o[k];
|
|
51
|
+
if (typeof v === "string")
|
|
52
|
+
out.push(v);
|
|
53
|
+
else if (Array.isArray(v))
|
|
54
|
+
blockText(v, out, depth + 1);
|
|
55
|
+
else if (obj(v))
|
|
56
|
+
blockText([v], out, depth + 1);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
function one(m) {
|
|
62
|
+
// Telegram wraps each update
|
|
63
|
+
const top = obj(m);
|
|
64
|
+
if (!top)
|
|
65
|
+
return undefined;
|
|
66
|
+
const o = obj(top.message) && (typeof top.update_id === "number" || !("text" in top)) ? obj(top.message) : top;
|
|
67
|
+
const msg = { shown: "", html: false, unseen: [], sender: "", automated: false, outside: false, self: false, service: "", previews: [], files: [], unread: [] };
|
|
68
|
+
const author = obj(o.author), from = obj(o.from), profile = obj(o.user_profile), body = obj(o.body);
|
|
69
|
+
// sender, as the channel names them
|
|
70
|
+
msg.sender = str(profile?.display_name) || str(profile?.real_name) || str(o.username) || str(author?.global_name) || str(author?.username) || str(author?.name)
|
|
71
|
+
|| str(obj(from?.user)?.displayName) || str(obj(from?.application)?.displayName) || [str(from?.first_name), str(from?.last_name)].filter(Boolean).join(" ") || str(from?.username) || str(from?.name) || str(from?.displayName)
|
|
72
|
+
|| str(o.sender_name) || str(o.senderName) || str(o.sender) || str(o.from) || str(o.handle) || str(o.author) || str(o.user_name) || str(o.user);
|
|
73
|
+
msg.automated = !!(o.bot_id || o.webhook_id || o.app_id || author?.bot || from?.is_bot || obj(from?.application) || o.subtype === "bot_message" || o.via_bot || o.is_bot);
|
|
74
|
+
msg.outside = !!(o.is_ext_shared || o.forward_from || o.forward_origin || o.forward_from_chat || o.forwarded || o.is_forwarded || o.external || (typeof o.user_team === "string" && typeof o.team === "string" && o.user_team !== o.team));
|
|
75
|
+
msg.self = o.is_from_me === true || o.is_from_me === 1 || o.fromMe === true || o.outgoing === true;
|
|
76
|
+
msg.service = str(o.service) || (typeof o.is_from_me !== "undefined" ? "SMS" : "") || str(o.channel_type) || str(o.platform);
|
|
77
|
+
// the words
|
|
78
|
+
const blocks = blockText(o.blocks);
|
|
79
|
+
const text = str(o.text) || str(obj(o.text)?.body) || str(o.content) || str(o.caption) || (typeof o.body === "string" ? o.body : "") || (typeof o.message === "string" ? o.message : "") || str(o.snippet);
|
|
80
|
+
if (body && typeof body.content === "string") {
|
|
81
|
+
msg.shown = body.content;
|
|
82
|
+
msg.html = /html/i.test(str(body.contentType));
|
|
83
|
+
}
|
|
84
|
+
else if (typeof o.formatted_body === "string" && /html/i.test(str(o.format))) {
|
|
85
|
+
msg.shown = o.formatted_body;
|
|
86
|
+
msg.html = true;
|
|
87
|
+
if (text)
|
|
88
|
+
msg.unseen.push({ field: "body", text });
|
|
89
|
+
}
|
|
90
|
+
else if (blocks.length) {
|
|
91
|
+
msg.shown = blocks.join("\n");
|
|
92
|
+
if (text)
|
|
93
|
+
msg.unseen.push({ field: "text", text });
|
|
94
|
+
}
|
|
95
|
+
else
|
|
96
|
+
msg.shown = text;
|
|
97
|
+
for (const k of ["summary", "notification_text", "fallback", "preview_text"])
|
|
98
|
+
if (typeof o[k] === "string" && o[k])
|
|
99
|
+
msg.unseen.push({ field: k, text: o[k] });
|
|
100
|
+
if (typeof o.subject === "string" && o.subject)
|
|
101
|
+
msg.shown = `${o.subject}\n${msg.shown}`;
|
|
102
|
+
// previews, embeds and cards: written by whoever controls the link
|
|
103
|
+
for (const a of [...arr(o.attachments), ...arr(o.embeds), ...arr(o.link_previews)].slice(0, 20)) {
|
|
104
|
+
const p = obj(a);
|
|
105
|
+
if (!p)
|
|
106
|
+
continue;
|
|
107
|
+
const fields = arr(p.fields).map((f) => `${str(obj(f)?.title) || str(obj(f)?.name)} ${str(obj(f)?.value)}`.trim());
|
|
108
|
+
const shown = [str(p.pretext), str(obj(p.author)?.name) || str(p.author_name), str(p.title), str(p.text) || str(p.description), ...fields, str(obj(p.footer)?.text) || (typeof p.footer === "string" ? p.footer : ""), ...blockText(p.blocks)].filter(Boolean).join("\n");
|
|
109
|
+
const url = str(p.title_link) || str(p.url) || str(p.original_url) || str(p.from_url);
|
|
110
|
+
if (typeof p.content === "string" && p.content.length > 2)
|
|
111
|
+
msg.unread.push("a card");
|
|
112
|
+
if (shown || p.fallback)
|
|
113
|
+
msg.previews.push({ shown, fallback: str(p.fallback), url });
|
|
114
|
+
if (str(p.filename) || (str(p.name) && (p.url || p.contentUrl)))
|
|
115
|
+
msg.files.push(str(p.filename) || str(p.name));
|
|
116
|
+
}
|
|
117
|
+
for (const f of arr(o.files).slice(0, 20)) {
|
|
118
|
+
const n = str(obj(f)?.title) || str(obj(f)?.name);
|
|
119
|
+
if (n)
|
|
120
|
+
msg.files.push(n);
|
|
121
|
+
}
|
|
122
|
+
for (const k of ["voice", "audio", "video", "sticker", "animation", "document", "photo"])
|
|
123
|
+
if (o[k])
|
|
124
|
+
msg.unread.push(k === "photo" ? "a picture" : `a ${k} part`);
|
|
125
|
+
if (typeof o.type === "string" && /^(audio|voice|ptt|video|sticker|image|document)$/.test(o.type))
|
|
126
|
+
msg.unread.push(`a ${o.type} part`);
|
|
127
|
+
if (!msg.shown && !msg.unseen.length && !msg.previews.length && !msg.files.length && !msg.unread.length)
|
|
128
|
+
return undefined;
|
|
129
|
+
return msg;
|
|
130
|
+
}
|
|
131
|
+
const LISTS = ["messages", "value", "items", "result", "results", "data", "history", "chats", "events"];
|
|
132
|
+
/** Messages in a chat API's JSON, in order. Lenient: used when the caller has said this is a conversation. */
|
|
133
|
+
export function parseMessages(doc) {
|
|
134
|
+
const d = obj(doc);
|
|
135
|
+
const list = Array.isArray(doc) ? doc : LISTS.map((k) => d?.[k]).find(Array.isArray) ?? (d ? [d] : []);
|
|
136
|
+
return list.slice(0, MAX_ITEMS).map(one).filter((m) => !!m);
|
|
137
|
+
}
|
|
138
|
+
/** Is this JSON plainly a chat export or a chat API's reply? Strict: decides how unlabelled JSON is read. */
|
|
139
|
+
export function looksLikeMessagesJson(doc) {
|
|
140
|
+
const is = (m) => {
|
|
141
|
+
const t = obj(m);
|
|
142
|
+
if (!t)
|
|
143
|
+
return false;
|
|
144
|
+
const o = obj(t.message) && typeof t.update_id === "number" ? obj(t.message) : t;
|
|
145
|
+
if ("subject" in o && ("from" in o || "sender" in o))
|
|
146
|
+
return false; // mail
|
|
147
|
+
if (typeof o.ts === "string" && /^\d{9,}\.\d+$/.test(o.ts) && ("text" in o || "blocks" in o) && ("user" in o || "bot_id" in o || "username" in o))
|
|
148
|
+
return true; // Slack
|
|
149
|
+
if (obj(o.author) && typeof obj(o.author).username === "string" && "content" in o && ("channel_id" in o || "timestamp" in o))
|
|
150
|
+
return true; // Discord
|
|
151
|
+
if (typeof o.message_id === "number" && obj(o.chat) && (obj(o.from) || "sender_chat" in o))
|
|
152
|
+
return true; // Telegram
|
|
153
|
+
if (obj(o.body) && typeof obj(o.body).content === "string" && obj(o.from) && ("createdDateTime" in o || "messageType" in o))
|
|
154
|
+
return true; // Teams
|
|
155
|
+
if ("is_from_me" in o && ("text" in o || "body" in o))
|
|
156
|
+
return true; // Messages / SMS exports
|
|
157
|
+
if (typeof o.type === "string" && typeof o.from === "string" && obj(o.text) && typeof obj(o.text).body === "string")
|
|
158
|
+
return true; // WhatsApp Cloud API
|
|
159
|
+
if (typeof o.sender === "string" && typeof o.event_id === "string" && obj(o.content))
|
|
160
|
+
return false; // Matrix events: nested content, read as JSON
|
|
161
|
+
return false;
|
|
162
|
+
};
|
|
163
|
+
const d = obj(doc);
|
|
164
|
+
const list = Array.isArray(doc) ? doc : LISTS.map((k) => d?.[k]).find(Array.isArray);
|
|
165
|
+
if (list)
|
|
166
|
+
return list.length > 0 && list.slice(0, 50).every(is);
|
|
167
|
+
return is(doc);
|
|
168
|
+
}
|
|
169
|
+
// ---------- checks ----------
|
|
170
|
+
const AUTHORITY_NAME = /^\W*(?:system|sys ?admin|admin(?:istrator)?|root|security(?: team| alert)?|it(?: support| help ?desk| department)?|help ?desk|tech(?:nical)? support|support(?: team)?|moderator|mod team|compliance|human resources|hr(?: team)?|payroll|legal|the (?:ceo|cfo|cto|boss|management)|ceo|slack ?bot|workspace admin|claude|chatgpt|gemini|copilot|assistant|ai assistant|anthropic|openai|microsoft(?: support| security)?|apple(?: support| security)?|google(?: support| security)?|your bank|bank security|fraud (?:team|department|prevention))\W*$/i;
|
|
171
|
+
const ROLE_IN_NAME = /\[(?:system|admin|assistant|developer|instruction)[^\]]{0,20}\]|^\s*(?:system|assistant|developer)\s*:|<\|[^|]{1,24}\|>|#{3,}/i;
|
|
172
|
+
const PRESSURE = /\b(?:urgent(?:ly)?|immediately|right away|within \d+ ?(?:h|hrs?|hours?|min(?:ute)?s?)|final (?:notice|warning|reminder)|last (?:chance|warning)|act now|expires? (?:today|soon|in)|suspend(?:ed)?|locked|restricted|unusual (?:activity|sign-?in)|unauthori[sz]ed|overdue|unpaid|past due|penalt(?:y|ies)|legal action|arrest|failed delivery|could not be delivered|held at|customs fee|redelivery|toll|refund (?:is )?(?:pending|available)|you(?:'ve| have) won|prize|claim (?:your|it)|verify (?:your|now)|confirm (?:your|now)|update (?:your )?(?:payment|billing|details))\b/i;
|
|
173
|
+
const ASKS = /\b(?:(?:send|share|give|tell|text|reply with|forward|enter|provide|confirm)\b[^.\n]{0,40}\b(?:code|otp|pin|password|passcode|card (?:number|details)|cvv|ssn|social security|bank details|gift cards?|seed phrase|recovery phrase)|gift cards?|wire (?:the )?(?:money|funds|transfer)|bitcoin|crypto wallet|western union|zelle|cash ?app)\b/i;
|
|
174
|
+
const CLAIMS = /\b(?:(?:your |the )?bank|fraud (?:team|department|prevention)|security (?:team|department)|(?:customer|technical|tech) (?:service|support|care)|support team|help ?desk|your (?:provider|carrier|network)|tax office|revenue service|police|court|amazon|paypal|apple|microsoft|google|netflix|irs|hmrc|usps|fedex|dhl|ups)\b/i;
|
|
175
|
+
const LINK = /\bhttps?:\/\/[^\s<>"')\]]+|\b(?:[a-z0-9-]+\.)+(?:com|net|org|io|co|me|info|biz|xyz|top|site|online|link|click|ly|gl|gd|cc|to|app|page|shop|live|icu|vip|cfd|sbs)(?:\/[^\s<>"')\]]*)?/gi;
|
|
176
|
+
const SHORTENER = /^(?:bit\.ly|t\.co|tinyurl\.com|goo\.gl|is\.gd|ow\.ly|buff\.ly|rebrand\.ly|cutt\.ly|rb\.gy|t\.ly|shorturl\.at|s\.id|tiny\.cc|lnkd\.in|v\.gd|qr\.ae|shorte\.st|bl\.ink|x\.co)$/i;
|
|
177
|
+
/** How a link hides where it goes, or undefined when it does not. */
|
|
178
|
+
export function linkTrick(link) {
|
|
179
|
+
let u;
|
|
180
|
+
try {
|
|
181
|
+
u = new URL(/^https?:\/\//i.test(link) ? link : `https://${link}`);
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
return "an address that does not parse";
|
|
185
|
+
}
|
|
186
|
+
const h = u.hostname.toLowerCase();
|
|
187
|
+
if (u.username || u.password)
|
|
188
|
+
return "a name before the @ that is not the destination";
|
|
189
|
+
if (/^\d{1,3}(?:\.\d{1,3}){3}$/.test(h))
|
|
190
|
+
return "a bare network address";
|
|
191
|
+
if (/^xn--|\.xn--/.test(h))
|
|
192
|
+
return "an international name that may imitate another";
|
|
193
|
+
if (SHORTENER.test(h))
|
|
194
|
+
return "a shortener";
|
|
195
|
+
if (/\.(?:top|xyz|icu|vip|cfd|sbs|click|link|live|shop|online|site)$/.test(h) && /(?:secure|verify|login|account|update|support|billing|pay|refund|parcel|post|track|bank|apple|paypal|amazon|microsoft|netflix|usps|fedex|dhl|ups|gov|irs|tax)/.test(h))
|
|
196
|
+
return "a brand or a service name on an unrelated domain";
|
|
197
|
+
if (h.split(".").length >= 5)
|
|
198
|
+
return "a long chain of subdomains";
|
|
199
|
+
return undefined;
|
|
200
|
+
}
|
|
201
|
+
/** plain text with its entities decoded, noting any that decode to characters nobody sees */
|
|
202
|
+
function plain(text, where, findings) {
|
|
203
|
+
const dec = decodeEntities(text);
|
|
204
|
+
if (dec.suspicious > 0)
|
|
205
|
+
findings.push({ pass: "character", kind: "unicode.entity_smuggling", confidence: Math.min(0.95, 0.6 + dec.suspicious * 0.05), severity: 0.7, message: `${dec.suspicious} HTML entities decoding to invisible or format characters`, excerpt: dec.sample, location: where, action: "neutralized" });
|
|
206
|
+
return dec.text;
|
|
207
|
+
}
|
|
208
|
+
const senderIsNumber = (s) => /^\+?[\d\s().-]{4,}$/.test(s) || /^\d{3,6}$/.test(s.trim());
|
|
209
|
+
export function adaptMessages(raw) {
|
|
210
|
+
const segments = [];
|
|
211
|
+
const findings = [];
|
|
212
|
+
let doc;
|
|
213
|
+
try {
|
|
214
|
+
doc = JSON.parse(raw);
|
|
215
|
+
}
|
|
216
|
+
catch {
|
|
217
|
+
doc = undefined;
|
|
218
|
+
}
|
|
219
|
+
const add = (f) => findings.push({ pass: "channel", action: "none", ...f });
|
|
220
|
+
// not JSON: a transcript or a single message as plain text
|
|
221
|
+
if (doc === undefined || (typeof doc !== "object")) {
|
|
222
|
+
const text = plain(typeof doc === "string" ? doc : raw, "message/text", findings);
|
|
223
|
+
segments.push({ text, visibility: "visible", path: "message/text" });
|
|
224
|
+
scamShape(text, "", "", "message", add);
|
|
225
|
+
for (const c of oneTimeCodes(text).slice(0, 1))
|
|
226
|
+
add({ kind: "message.verification_code", confidence: 0.02, severity: 0.1, message: `a verification code (ending ${c.slice(-2)}) in this message: a code is for the person` });
|
|
227
|
+
return { segments, findings };
|
|
228
|
+
}
|
|
229
|
+
const msgs = parseMessages(doc);
|
|
230
|
+
const unread = new Map();
|
|
231
|
+
const codes = new Set();
|
|
232
|
+
msgs.forEach((m, i) => {
|
|
233
|
+
const path = `message[${i}]`;
|
|
234
|
+
if (m.sender)
|
|
235
|
+
segments.push({ text: m.sender, visibility: "visible", path: `${path}/sender` });
|
|
236
|
+
let shownText = m.shown;
|
|
237
|
+
if (m.html) {
|
|
238
|
+
const v = analyzeHtml(m.shown);
|
|
239
|
+
for (const s of v.segments)
|
|
240
|
+
segments.push({ ...s, path: `${path}/html/${s.path}` });
|
|
241
|
+
findings.push(...v.findings.map((f) => ({ ...f, location: `${path}/html${f.location ? `/${f.location}` : ""}` })));
|
|
242
|
+
shownText = v.segments.map((s) => s.text).join(" ");
|
|
243
|
+
}
|
|
244
|
+
else if (m.shown.trim()) {
|
|
245
|
+
// chat APIs escape a few characters as entities; decode them here, and notice ones that decode to nothing visible
|
|
246
|
+
shownText = plain(m.shown, `${path}/text`, findings);
|
|
247
|
+
segments.push({ text: shownText, visibility: "visible", path: `${path}/text` });
|
|
248
|
+
}
|
|
249
|
+
// words the app does not show
|
|
250
|
+
const seen = [shownText, ...m.previews.map((p) => p.shown)].join(" ");
|
|
251
|
+
for (const u of m.unseen) {
|
|
252
|
+
const only = passagesOnlyIn(u.text, seen);
|
|
253
|
+
if (!only.length)
|
|
254
|
+
continue;
|
|
255
|
+
add({ kind: "message.text_divergence", confidence: 0.45, severity: 0.7, message: `the "${u.field}" field says ${only.length} thing(s) the message as shown does not: an app displays one, a program reading the conversation gets both`, excerpt: only[0].slice(0, 160), location: `${path}/${u.field}`, inHidden: true });
|
|
256
|
+
only.forEach((t, j) => segments.push({ text: t, visibility: "concealed", path: `${path}/${u.field}~unseen[${j}]` }));
|
|
257
|
+
}
|
|
258
|
+
m.previews.forEach((p, j) => {
|
|
259
|
+
if (p.shown.trim())
|
|
260
|
+
segments.push({ text: p.shown, visibility: "visible", path: `${path}/preview[${j}]` });
|
|
261
|
+
const only = p.fallback ? passagesOnlyIn(p.fallback, `${p.shown} ${shownText}`) : [];
|
|
262
|
+
only.forEach((t, k) => segments.push({ text: t, visibility: "concealed", path: `${path}/preview[${j}]/fallback[${k}]` }));
|
|
263
|
+
if (only.length)
|
|
264
|
+
add({ kind: "message.text_divergence", confidence: 0.4, severity: 0.65, message: "a link preview's plain-text fallback says something the preview as shown does not", excerpt: only[0].slice(0, 160), location: `${path}/preview[${j}]`, inHidden: true });
|
|
265
|
+
});
|
|
266
|
+
if (m.files.length)
|
|
267
|
+
segments.push({ text: m.files.join("\n"), visibility: "visible", path: `${path}/files` });
|
|
268
|
+
for (const u of m.unread)
|
|
269
|
+
unread.set(u, (unread.get(u) ?? 0) + 1);
|
|
270
|
+
// who it says it is from
|
|
271
|
+
if (m.sender && !m.self) {
|
|
272
|
+
if (ROLE_IN_NAME.test(m.sender))
|
|
273
|
+
add({ kind: "message.sender_impersonation", confidence: 0.5, severity: 0.7, message: `a sender's display name is shaped like a system or role marker ("${m.sender.slice(0, 40)}")`, location: `${path}/sender` });
|
|
274
|
+
else if (AUTHORITY_NAME.test(m.sender) && (m.automated || m.outside))
|
|
275
|
+
add({ kind: "message.sender_impersonation", confidence: 0.4, severity: 0.6, message: `"${m.sender.slice(0, 40)}" is a display name chosen by ${m.automated ? "a bot or webhook" : "someone outside the workspace"}: a name is not an identity`, location: `${path}/sender` });
|
|
276
|
+
}
|
|
277
|
+
if (!m.self)
|
|
278
|
+
scamShape([shownText, ...m.previews.map((p) => p.shown)].join("\n"), m.sender, m.service, path, add);
|
|
279
|
+
for (const c of oneTimeCodes(shownText))
|
|
280
|
+
codes.add(c);
|
|
281
|
+
});
|
|
282
|
+
if (codes.size)
|
|
283
|
+
add({ kind: "message.verification_code", confidence: 0.02, severity: 0.1, message: `${codes.size} verification code(s) in these messages: a code is for the person. An action that carries one to a destination that came from content is refused by the action broker` });
|
|
284
|
+
if (unread.size)
|
|
285
|
+
add({ kind: "message.uninspected_part", confidence: 0.02, severity: 0.1, message: `not inspected: ${[...unread].map(([k, n]) => `${n} × ${k}`).join(", ")}` });
|
|
286
|
+
return { segments, findings };
|
|
287
|
+
}
|
|
288
|
+
/** An unknown sender, a link that hides where it goes, and pressure or a request for a secret or money. */
|
|
289
|
+
function scamShape(text, sender, service, path, add) {
|
|
290
|
+
if (text.length < 20)
|
|
291
|
+
return;
|
|
292
|
+
const links = [...text.matchAll(LINK)].map((m) => m[0]).slice(0, 10);
|
|
293
|
+
const tricks = links.map(linkTrick).filter((t) => !!t);
|
|
294
|
+
const pressure = PRESSURE.test(text), asks = ASKS.test(text);
|
|
295
|
+
const stranger = senderIsNumber(sender) || /sms|mms|rcs/i.test(service) || /^[^@\s]+@[^@\s]+$/.test(sender);
|
|
296
|
+
// a hidden destination with pressure is the shape, whoever sent it; a plain link needs both pressure and a stranger
|
|
297
|
+
const why = [];
|
|
298
|
+
if (tricks.length)
|
|
299
|
+
why.push(`a link that is ${tricks[0]}`);
|
|
300
|
+
if (pressure)
|
|
301
|
+
why.push("pressure to act now");
|
|
302
|
+
if (asks)
|
|
303
|
+
why.push("a request for a code, a password or a payment");
|
|
304
|
+
// A scam text is short: it has one job. Long messages mention deadlines, links and payments all the time
|
|
305
|
+
// (ordinary business mail read as if it were a text from a stranger tripped this 236 times in 3,000 before
|
|
306
|
+
// the length limits).
|
|
307
|
+
const words = text.trim().split(/\s+/).length;
|
|
308
|
+
const strong = words <= 120 && ((tricks.length > 0 && (pressure || asks)) || (asks && pressure && links.length > 0));
|
|
309
|
+
// "can you send me the door code again?" is how friends text; a stranger asking for a code in an institution's
|
|
310
|
+
// name, or with a deadline, is the scam
|
|
311
|
+
const claims = CLAIMS.test(text);
|
|
312
|
+
if (claims && asks)
|
|
313
|
+
why.push("in the name of an institution");
|
|
314
|
+
const medium = !strong && words <= 60 && stranger && ((links.length > 0 && pressure) || (asks && (pressure || claims)));
|
|
315
|
+
if (!strong && !medium)
|
|
316
|
+
return;
|
|
317
|
+
add({ kind: "message.scam_shape", confidence: strong ? 0.5 : 0.35, severity: 0.65, message: `shaped like a scam message${stranger ? " from an unknown sender" : ""}: ${why.join(", ")}`, location: `${path}/text` });
|
|
318
|
+
}
|
|
319
|
+
const APP_KEYS = ["app", "appName", "app_name", "application", "packageName", "package", "bundleId", "bundle_id", "bundleIdentifier", "source"];
|
|
320
|
+
function oneNote(n) {
|
|
321
|
+
const o = obj(n);
|
|
322
|
+
if (!o)
|
|
323
|
+
return undefined;
|
|
324
|
+
const extras = obj(o.extras) ?? {};
|
|
325
|
+
const note = {
|
|
326
|
+
app: APP_KEYS.map((k) => str(o[k])).find(Boolean) ?? "",
|
|
327
|
+
origin: str(o.origin) || (/^https?:\/\//.test(str(o.url)) ? str(o.url) : "") || str(o.scope),
|
|
328
|
+
title: str(o.title) || str(extras["android.title"]) || str(o.heading),
|
|
329
|
+
subtitle: str(o.subtitle) || str(o.subText) || str(extras["android.subText"]),
|
|
330
|
+
body: str(o.body) || str(o.bigText) || str(extras["android.bigText"]) || str(o.text) || str(extras["android.text"]) || str(o.message) || str(o.content),
|
|
331
|
+
sender: str(o.sender) || str(o.from) || str(extras["android.conversationTitle"]),
|
|
332
|
+
actions: arr(o.actions).map((a) => (typeof a === "string" ? a : str(obj(a)?.title) || str(obj(a)?.label) || str(obj(a)?.action))).filter(Boolean).slice(0, 10),
|
|
333
|
+
payload: [],
|
|
334
|
+
};
|
|
335
|
+
// fields a banner does not show: the ticker line, and whatever the sender attached for the app
|
|
336
|
+
if (str(o.tickerText))
|
|
337
|
+
note.payload.push({ field: "tickerText", text: str(o.tickerText) });
|
|
338
|
+
for (const k of ["data", "userInfo", "payload", "custom"]) {
|
|
339
|
+
const walk = (v, p, depth) => {
|
|
340
|
+
if (depth > 4 || note.payload.length > 40)
|
|
341
|
+
return;
|
|
342
|
+
if (typeof v === "string") {
|
|
343
|
+
if (v.length >= 12 && /\s/.test(v))
|
|
344
|
+
note.payload.push({ field: p, text: v });
|
|
345
|
+
}
|
|
346
|
+
else if (Array.isArray(v))
|
|
347
|
+
v.slice(0, 20).forEach((x, i) => walk(x, `${p}[${i}]`, depth + 1));
|
|
348
|
+
else if (obj(v))
|
|
349
|
+
for (const [kk, x] of Object.entries(v).slice(0, 40))
|
|
350
|
+
walk(x, `${p}.${kk}`, depth + 1);
|
|
351
|
+
};
|
|
352
|
+
walk(o[k], k, 0);
|
|
353
|
+
}
|
|
354
|
+
return note.title || note.body ? note : undefined;
|
|
355
|
+
}
|
|
356
|
+
export function parseNotifications(doc) {
|
|
357
|
+
const d = obj(doc);
|
|
358
|
+
const list = Array.isArray(doc) ? doc : ["notifications", "items", "value", "results"].map((k) => d?.[k]).find(Array.isArray) ?? (d ? [d] : []);
|
|
359
|
+
return list.slice(0, MAX_ITEMS).map(oneNote).filter((n) => !!n);
|
|
360
|
+
}
|
|
361
|
+
export function looksLikeNotificationJson(doc) {
|
|
362
|
+
const is = (n) => {
|
|
363
|
+
const o = obj(n);
|
|
364
|
+
if (!o || "subject" in o)
|
|
365
|
+
return false;
|
|
366
|
+
const hasApp = APP_KEYS.slice(0, 9).some((k) => typeof o[k] === "string") || obj(o.extras) !== undefined || (typeof o.origin === "string" && "tag" in o);
|
|
367
|
+
return hasApp && (typeof o.title === "string" || obj(o.extras) !== undefined) && ("body" in o || "text" in o || "bigText" in o || "subtitle" in o || obj(o.extras) !== undefined);
|
|
368
|
+
};
|
|
369
|
+
const d = obj(doc);
|
|
370
|
+
const list = Array.isArray(doc) ? doc : ["notifications", "items"].map((k) => d?.[k]).find(Array.isArray);
|
|
371
|
+
if (list)
|
|
372
|
+
return list.length > 0 && list.slice(0, 50).every(is);
|
|
373
|
+
return is(doc);
|
|
374
|
+
}
|
|
375
|
+
const BROWSER = /\b(?:chrome|chromium|safari|firefox|edge|msedge|brave|opera|vivaldi|arc|duckduckgo|samsung internet|sbrowser)\b|^(?:com\.android\.chrome|com\.apple\.safari|org\.mozilla\.\w+|com\.microsoft\.(?:edge|emmx)|com\.brave\.\w+|com\.opera\.\w+)/i;
|
|
376
|
+
const SYSTEM_VOICE = /\b(?:virus(?:es)?|infected|malware|trojan|spyware|system (?:alert|warning|error|update|scan)|security (?:alert|warning|scan)|critical (?:alert|warning|error)|your (?:mac|pc|iphone|ipad|android|computer|device|phone|system|battery|storage|icloud|account) (?:is|has been|may be|was|will be)|(?:\d+|several|multiple) (?:threats?|virus(?:es)?|issues?) (?:found|detected)|scan now|clean now|protection (?:expired|has expired|disabled)|subscription (?:expired|has expired)|license (?:expired|has expired)|mcafee|norton|avast|kaspersky|windows defender|apple ?care|macos update)\b/i;
|
|
377
|
+
const BRANDS = ["apple", "icloud", "microsoft", "windows", "google", "gmail", "paypal", "amazon", "netflix", "facebook", "instagram", "whatsapp", "coinbase", "binance", "chase", "wells fargo", "bank of america", "citibank", "hsbc", "barclays", "usps", "fedex", "dhl", "ups", "irs", "hmrc"];
|
|
378
|
+
export function adaptNotifications(raw) {
|
|
379
|
+
const segments = [];
|
|
380
|
+
const findings = [];
|
|
381
|
+
const add = (f) => findings.push({ pass: "channel", action: "none", ...f });
|
|
382
|
+
let doc;
|
|
383
|
+
try {
|
|
384
|
+
doc = JSON.parse(raw);
|
|
385
|
+
}
|
|
386
|
+
catch {
|
|
387
|
+
doc = undefined;
|
|
388
|
+
}
|
|
389
|
+
if (doc === undefined || typeof doc !== "object") {
|
|
390
|
+
segments.push({ text: plain(typeof doc === "string" ? doc : raw, "notification/text", findings), visibility: "visible", path: "notification/text" });
|
|
391
|
+
return { segments, findings };
|
|
392
|
+
}
|
|
393
|
+
const codes = new Set();
|
|
394
|
+
parseNotifications(doc).forEach((n, i) => {
|
|
395
|
+
const path = `notification[${i}]`;
|
|
396
|
+
const shown = [n.title, n.subtitle, n.body].filter(Boolean).join("\n");
|
|
397
|
+
if (n.sender)
|
|
398
|
+
segments.push({ text: n.sender, visibility: "visible", path: `${path}/sender` });
|
|
399
|
+
if (shown)
|
|
400
|
+
segments.push({ text: shown, visibility: "visible", path: `${path}/text` });
|
|
401
|
+
if (n.actions.length)
|
|
402
|
+
segments.push({ text: n.actions.join("\n"), visibility: "visible", path: `${path}/actions` });
|
|
403
|
+
for (const p of n.payload)
|
|
404
|
+
for (const [j, t] of passagesOnlyIn(p.text, shown, 6).entries())
|
|
405
|
+
segments.push({ text: t, visibility: "concealed", path: `${path}/${p.field}[${j}]` });
|
|
406
|
+
// an alarm in the system's voice, or a brand's, delivered by a web browser: any site a person once allowed can send it
|
|
407
|
+
const viaWeb = !!n.origin || BROWSER.test(n.app);
|
|
408
|
+
let host = "";
|
|
409
|
+
try {
|
|
410
|
+
host = n.origin ? new URL(n.origin).hostname.toLowerCase() : "";
|
|
411
|
+
}
|
|
412
|
+
catch { /* no host */ }
|
|
413
|
+
if (viaWeb && SYSTEM_VOICE.test(shown)) {
|
|
414
|
+
add({ kind: "notification.source_mismatch", confidence: 0.55, severity: 0.65, message: `a notification speaking as the system or a security product was sent by a website${host ? ` (${host})` : ""} through the browser: the operating system does not announce itself that way`, location: `${path}/text` });
|
|
415
|
+
}
|
|
416
|
+
else if (viaWeb) {
|
|
417
|
+
const brand = BRANDS.find((b) => new RegExp(`\\b${b}\\b`, "i").test(`${n.title} ${n.sender}`));
|
|
418
|
+
if (brand && host && !host.replace(/[^a-z]/g, "").includes(brand.replace(/[^a-z]/g, "")) && (PRESSURE.test(shown) || ASKS.test(shown))) {
|
|
419
|
+
add({ kind: "notification.source_mismatch", confidence: 0.45, severity: 0.6, message: `a notification in the name of ${brand} was sent by ${host}, with pressure to act`, location: `${path}/text` });
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
if (ROLE_IN_NAME.test(n.sender) || ROLE_IN_NAME.test(n.title))
|
|
423
|
+
add({ kind: "message.sender_impersonation", confidence: 0.5, severity: 0.7, message: "a notification's title or sender is shaped like a system or role marker", location: `${path}/sender` });
|
|
424
|
+
scamShape(shown, n.sender, "", path, add);
|
|
425
|
+
for (const c of oneTimeCodes(shown))
|
|
426
|
+
codes.add(c);
|
|
427
|
+
});
|
|
428
|
+
if (codes.size)
|
|
429
|
+
add({ kind: "message.verification_code", confidence: 0.02, severity: 0.1, message: `${codes.size} verification code(s) in these notifications: a code is for the person, and the action broker refuses to let one be sent to a destination that came from content` });
|
|
430
|
+
return { segments, findings };
|
|
431
|
+
}
|
package/dist/src/multilingual.js
CHANGED
|
@@ -16,8 +16,11 @@
|
|
|
16
16
|
* set id says so on every finding. Paraphrases, transliteration and most languages are
|
|
17
17
|
* not covered; the coverage line on each finding states what ran.
|
|
18
18
|
*/
|
|
19
|
+
import { composeHangul, despaceCJK, foldArabicScript, foldIndic, hangulInitials, latinKeysToPersian, stripLatinAccents } from "./normalize.js";
|
|
19
20
|
export const MULTILINGUAL_RULESET = "multilingual-seed-v1 (unreviewed)";
|
|
20
21
|
const R = (id, lang, kind, re) => ({ id, lang, kind, re });
|
|
22
|
+
/** a rule matched only against the initial-consonant view (초성 shorthand) */
|
|
23
|
+
const RI = (id, kind, re) => ({ id, lang: "ko", kind, re, initialsOnly: true });
|
|
21
24
|
export const MULTILINGUAL_RULES = [
|
|
22
25
|
// Spanish
|
|
23
26
|
R("override.es", "es", "override", /\b(?:ignora|ignore|olvida|olvide|descarta)\s+(?:todas\s+)?las\s+instrucciones\s+(?:anteriores|previas)\b/iu),
|
|
@@ -53,7 +56,89 @@ export const MULTILINGUAL_RULES = [
|
|
|
53
56
|
R("override.ko", "ko", "override", /이전\s*(?:의\s*)?(?:모든\s*)?(?:지시|지침|명령)(?:사항)?(?:을|를)?\s*(?:모두\s*)?무시/u),
|
|
54
57
|
// Hindi
|
|
55
58
|
R("override.hi", "hi", "override", /पिछले\s+(?:सभी\s+)?निर्देशों\s+को\s+(?:अनदेखा|नज़रअंदाज़|नजरअंदाज)\s+कर/u),
|
|
59
|
+
// added 2026-11-17 (AgentShield misses): word-order and pronoun variants, and system-prompt extraction
|
|
60
|
+
R("override.es2", "es", "override", /\b(?:ignora|olvida|descarta|olvide)\s+(?:todas\s+)?(?:tus|sus|las)\s+instrucciones\s+(?:anteriores|previas)\b/iu),
|
|
61
|
+
R("override.de2", "de", "override", /\b(?:ignorieren|vergessen)\s+sie\s+(?:alle\s+)?(?:vorherigen|bisherigen|früheren)\s+(?:anweisungen|instruktionen)\b/iu),
|
|
62
|
+
R("override.tr2", "tr", "override", /(?:tüm\s+)?önceki\s+(?:tüm\s+)?talimatları\s+(?:unutun|unut|yok\s+sayın|görmezden\s+gelin)/iu),
|
|
63
|
+
R("override.ja2", "ja", "override", /(?:以前|前|これまで)の(?:すべて|全て)の指示を無視/u),
|
|
64
|
+
R("extract.ru", "ru", "extract", /(?:выведи|покажи|раскрой|выведите|покажите)[^.\n]{0,30}(?:системн\S*\s+(?:промпт|подсказк|инструкци))/iu),
|
|
65
|
+
R("extract.fr", "fr", "extract", /\b(?:affiche[rz]?|montre[rz]?|révèle[rz]?)\b[^.\n]{0,30}\b(?:prompt|invite|message)\s+(?:système|systeme)/iu),
|
|
66
|
+
R("extract.ja", "ja", "extract", /システムプロンプト(?:を|全体を)?(?:完全に)?(?:出力|表示|教え)/u),
|
|
67
|
+
R("extract.ko", "ko", "extract", /시스템\s*프롬프트(?:를|을)?\s*(?:출력|보여|공개)/u),
|
|
68
|
+
R("extract.ar", "ar", "extract", /(?:اعرض|أظهر|اكشف)\s+(?:رسالة|تعليمات)\s+النظام/u),
|
|
69
|
+
R("unrestricted.multi", "multi", "override", /(?:sans\s+aucune\s+restriction|sin\s+restricciones|ohne\s+einschränkungen|без\s+ограничений|制限のない|没有任何限制|بدون\s+أي\s+قيود|kısıtlaması\s+olmayan|mode\s+développeur|modo\s+desarrollador|entwicklermodus|وضع\s+المطور)/iu),
|
|
70
|
+
// added 2026-11-18 (0.9.3). Persian, written in the folded view's letters (ی ک, no ZWNJ): it also matches Arabic-keyboard spellings.
|
|
71
|
+
R("override.fa", "fa", "override", /(?:همه\s*(?:ی\s*)?)?(?:دستورالعمل|دستور|دستورات|راهنمایی|آموزه)(?:ها|های)?\s*(?:ی\s*)?(?:قبلی|پیشین|قبل|بالا)\s*(?:را\s*)?(?:نادیده\s*(?:بگیر|بگیرید|گرفته)|فراموش\s*(?:کن|کنید)|کنار\s*(?:بگذار|بگذارید))/u),
|
|
72
|
+
R("conceal.fa", "fa", "conceal", /به\s*کاربر\s*(?:چیزی\s*|هیچ\s*چیز\s*)?(?:نگو|نگویید|اطلاع\s*نده|اطلاع\s*ندهید)/u),
|
|
73
|
+
R("extract.fa", "fa", "extract", /(?:پرامپت|دستور|دستورالعمل|پیام)(?:ها|های)?\s*(?:ی\s*)?سیستم(?:ی)?\s*(?:خود\s*|ات\s*)?(?:را\s*)?(?:نشان\s*(?:بده|دهید)|فاش\s*(?:کن|کنید)|بنویس|چاپ\s*(?:کن|کنید)|بازگو\s*کن)/u),
|
|
74
|
+
// Korean initial-consonant shorthand (초성): 이전 지시 무시 -> ㅇㅈ ㅈㅅ ㅁㅅ; 시스템 프롬프트 -> ㅅㅅㅌ ㅍㄹㅍㅌ
|
|
75
|
+
RI("override.ko.initials", "override", /ㅇㅈ\s*(?:ㅇ\s*)?(?:ㅁㄷ\s*)?(?:ㅈㅅ|ㅈㅊ|ㅁㄹ)(?:ㅅㅎ)?\s*(?:ㄹ|ㅇ)?\s*(?:ㅁㄷ\s*)?ㅁㅅ/u),
|
|
76
|
+
RI("extract.ko.initials", "extract", /ㅅㅅㅌ\s*ㅍㄹㅍㅌ\s*(?:ㄹ|ㅇ)?\s*(?:ㅊㄹ|ㅂㅇ|ㄱㄱ)/u),
|
|
77
|
+
// fake notices in CJK brackets (【システム】, 【系统】, 【시스템】) that go on to give an order. A bracket alone is an
|
|
78
|
+
// ordinary announcement header on Japanese and Chinese sites ("【システム】メンテナンスのお知らせ").
|
|
79
|
+
R("header.cjk", "multi", "override", /[【[〔〖]\s*(?:システム(?:通知|メッセージ)?|管理者|運営|系统(?:通知|消息)?|系統|管理员|管理員|시스템|관리자|운영자)\s*[】]〕〗][^\n]{0,120}?(?:指示|命令|無視|従って|従え|忽略|无视|指令|遵守|服从|무시|지시|따르|따라)/u),
|
|
80
|
+
// ---- added 2026-11-18 (0.9.5). Seed rules, unreviewed by native speakers like the rest. ----
|
|
81
|
+
// Turkish: the word endings that change with case and possession (talimatları / talimatlarını / yönergeleri ...)
|
|
82
|
+
R("override.tr3", "tr", "override", /(?:önceki|daha\s+önceki|yukarıdaki|eski)\s+(?:tüm\s+|bütün\s+)?(?:talimat|yönerge|komut|kural|direktif|yönlendirme)(?:lar|ler)?(?:ı|i|ını|ini|ları|leri|larını|lerini|ın|in)?\s+(?:yok\s+say|görmezden\s+gel|unut|dikkate\s+alma|boş\s*ver|geçersiz\s+say|iptal\s+et|umursama)/iu),
|
|
83
|
+
// the target must be the reader's own prompt, as in English ("your system prompt"): "istemini" is ambiguous between
|
|
84
|
+
// "your" and "its", so this needs senin / kendi or the formal possessive (-inizi). A bare "show the system prompt"
|
|
85
|
+
// in a Turkish chat about prompt writing is a question, and it refused 7 benign chats in the first version.
|
|
86
|
+
R("extract.tr", "tr", "extract", /(?:senin|kendi|sizin)\s+sistem\s+(?:istem|komut|talimat|prompt|mesaj|yönerge)\S*\s+(?:göster|yaz|söyle|paylaş|açıkla|ver|ifşa\s+et|dök)|sistem\s+(?:istem|komut|talimat|prompt|mesaj|yönerge)(?:in|ın|un|ün|ler|lar)?(?:iniz|ınız|unuz|ünüz)(?:i|ı|u|ü)\s+(?:göster|yaz|söyle|paylaş|açıkla|ver|ifşa\s+et|dök)/iu),
|
|
87
|
+
// Dutch, Swedish, Danish/Norwegian, Polish, Romanian, Ukrainian, Czech/Slovak, Serbian, Indonesian/Malay
|
|
88
|
+
R("override.nl", "nl", "override", /\b(?:negeer|vergeet)\s+(?:alle\s+)?(?:vorige|eerdere|voorgaande)\s+(?:instructies|aanwijzingen|opdrachten)\b/iu),
|
|
89
|
+
R("extract.nl", "nl", "extract", /\b(?:toon|geef|laat)\s+(?:me\s+)?(?:je|jouw|de)\s+systeem(?:prompt|instructies)\b/iu),
|
|
90
|
+
R("override.sv", "sv", "override", /\b(?:ignorera|glöm)\s+(?:alla\s+)?(?:tidigare|föregående)\s+(?:instruktioner|anvisningar)\b/iu),
|
|
91
|
+
R("override.da-no", "da", "override", /\b(?:ignorer|glem)\s+(?:alle\s+)?(?:tidligere|forrige|foregående)\s+(?:instruktioner|instruksjoner|instrukser|anvisninger)\b/iu),
|
|
92
|
+
R("override.pl", "pl", "override", /\b(?:zignoruj|ignoruj|zapomnij(?:\s+o)?)\s+(?:wszystkie\s+|wszystkich\s+)?(?:poprzednie|poprzednich|wcześniejsze|wcześniejszych)\s+(?:instrukcje|instrukcjach|polecenia|poleceniach)\b/iu),
|
|
93
|
+
R("override.ro", "ro", "override", /\b(?:ignoră|ignora|uită)\s+(?:toate\s+)?instrucțiunile\s+(?:anterioare|precedente)\b/iu),
|
|
94
|
+
R("override.uk", "uk", "override", /(?:ігноруй(?:те)?|забудь(?:те)?)\s+(?:всі\s+|усі\s+)?попередні\s+(?:інструкції|вказівки)/iu),
|
|
95
|
+
R("override.cs-sk", "cs", "override", /\b(?:ignoruj(?:te)?|zapomeň(?:te)?|zabudni)\s+(?:na\s+)?(?:všechny\s+|všetky\s+)?(?:předchozí|predchádzajúce|predošlé)\s+(?:instrukce|pokyny|inštrukcie)\b/iu),
|
|
96
|
+
R("override.sr", "sr", "override", /\b(?:ignoriši|zaboravi)\s+(?:sve\s+)?prethodne\s+(?:instrukcije|uputstva|naredbe)\b|(?:игнориши|заборави)\s+(?:све\s+)?претходне\s+(?:инструкције|упутства|наредбе)/iu),
|
|
97
|
+
R("override.id", "id", "override", /\b(?:abaikan|lupakan|acuhkan)\s+(?:semua\s+|seluruh\s+)?(?:instruksi|perintah|petunjuk|arahan)\s+(?:sebelumnya|terdahulu|sebelum\s+ini|di\s+atas)\b/iu),
|
|
98
|
+
R("extract.id", "id", "extract", /\b(?:tunjukkan|tampilkan|beritahu|bocorkan)\s+(?:prompt|instruksi|pesan)\s+sistem(?:mu|\s+anda)?\b/iu),
|
|
99
|
+
// Vietnamese, written without accents: it is matched on the accent-stripped view, so "bỏ qua" and "bo qua" both hit
|
|
100
|
+
R("override.vi", "vi", "override", /\b(?:bo\s+qua|lo\s+di|quen\s+(?:di\s+)?|khong\s+can\s+quan\s+tam(?:\s+den)?|ko\s+can\s+quan\s+tam(?:\s+den)?)\s+(?:het\s+|tat\s+ca\s+|moi\s+|toan\s+bo\s+)?(?:cac\s+|nhung\s+)?(?:huong\s+dan|chi\s+dan|chi\s+thi|lenh|yeu\s+cau|quy\s+tac)\s+(?:truoc(?:\s+do|\s+day)?|o\s+tren|ban\s+dau)\b/iu),
|
|
101
|
+
R("extract.vi", "vi", "extract", /\b(?:hien\s+thi|in\s+ra|cho\s+(?:toi|minh)\s+xem|tiet\s+lo)\s+(?:loi\s+nhac|prompt|chi\s+dan|huong\s+dan)\s+(?:he\s+thong|system)\b/iu),
|
|
102
|
+
// Thai has no spaces between words, so no word boundaries here
|
|
103
|
+
R("override.th", "th", "override", /(?:ละเว้น|เพิกเฉย(?:ต่อ)?|ไม่ต้องสนใจ|ลืม|ข้าม)\s*(?:คำสั่ง|คำแนะนำ|ข้อกำหนด)(?:ทั้งหมด)?\s*(?:ที่ผ่านมา|ก่อนหน้า(?:นี้)?|ข้างต้น|เดิม)/u),
|
|
104
|
+
R("extract.th", "th", "extract", /(?:แสดง|บอก|เปิดเผย)\s*(?:พรอมต์|คำสั่ง)\s*(?:ของ)?\s*ระบบ/u),
|
|
105
|
+
// Tagalog, Finnish, Hungarian, Hebrew, Greek
|
|
106
|
+
R("override.tl", "tl", "override", /\b(?:huwag\s+(?:pansinin|sundin|intindihin)|kalimutan|balewalain)\s+(?:ang\s+)?(?:lahat\s+ng\s+)?(?:mga\s+)?(?:naunang|nakaraang|dating)\s+(?:tagubilin|utos|instruksyon|instruksiyon|panuto)\b/iu),
|
|
107
|
+
R("override.fi", "fi", "override", /\b(?:ohita|unohda|sivuuta)\s+(?:kaikki\s+)?(?:aiemmat|edelliset|aikaisemmat)\s+(?:ohjeet|käskyt|ohjeesi)\b/iu),
|
|
108
|
+
R("override.hu", "hu", "override", /\b(?:hagyd\s+figyelmen\s+kívül|felejtsd\s+el|ne\s+vedd\s+figyelembe)\s+(?:az\s+)?(?:összes\s+)?(?:korábbi|előző|eddigi)\s+(?:utasítást|utasításokat|utasítás)\b/iu),
|
|
109
|
+
R("override.he", "he", "override", /(?:התעלם|תתעלם|התעלמו|שכח|תשכח)\s+(?:מ)?(?:כל\s+)?(?:ה)?(?:הוראות|הנחיות)\s+(?:ה)?קודמות/u),
|
|
110
|
+
R("override.el", "el", "override", /(?:αγνόησε|αγνοήστε|ξέχασε|ξεχάστε)\s+(?:όλες\s+)?(?:τις\s+)?προηγούμενες\s+(?:οδηγίες|εντολές)/iu),
|
|
111
|
+
// Hindi: more word orders, and English written in Devanagari (इग्नोर ... इंस्ट्रक्शंस). Matched on the Indic fold, which
|
|
112
|
+
// drops the nukta, so these are written without it.
|
|
113
|
+
R("override.hi2", "hi", "override", /(?:सभी\s*|सारे\s*)?(?:पिछले|पिछली|पहले\s*के|पुराने)\s*(?:सभी\s*|सारे\s*)?(?:निर्देश|निर्देशों|आदेश|आदेशों|इंस्ट्रक्श\S*|इन्स्ट्रक्श\S*)\s*(?:को\s*)?(?:भूल\s*जा\S*|इग्नोर\s*कर\S*|अनदेखा\s*कर\S*|नजरअंदाज\s*कर\S*)/u),
|
|
114
|
+
R("override.hi-translit", "hi", "override", /इग्नोर\s*(?:कर\S*\s*)?(?:ऑल|सभी|सारे|सब)?\s*(?:प्रीवियस|पिछले|पिछली|पहले\s*के|पुराने)\s*(?:इंस्ट्रक्श\S*|इन्स्ट्रक्श\S*|निर्देश\S*|आदेश\S*)/u),
|
|
115
|
+
R("extract.hi", "hi", "extract", /(?:सिस्टम\s*प्रॉम्प्ट|सिस्टम\s*प्रोम्प्ट|सिस्टम\s*निर्देश)\s*(?:को\s*)?(?:दिखाओ|दिखाइए|दिखा\s*दो|बताओ|बताइए|बता\s*दो|लिखो|प्रकट\s*कर\S*)/u),
|
|
116
|
+
// Hinglish (Hindi in Latin letters), both word orders
|
|
117
|
+
R("override.hinglish", "hi-Latn", "override", /\b(?:pichl[ea]|pichhl[ea]|pehl[ea]\s+(?:ke|wale)|purane|upar\s+(?:ke|wale))\s+(?:sab(?:hi)?\s+|saar[ea]\s+)?(?:instructions?|nirdesh|hidayat(?:ein|en)?|rules)\s+(?:ko\s+)?(?:ignore|bhool|bhul|nazarandaz|andekha)\s*(?:karo|kar\s*do|kariye|karein|jao|ja|jaao)\b|\b(?:ignore|bhool|bhul)\s+(?:karo|kar\s*do|jao)\s+(?:sab(?:hi)?\s+|saar[ea]\s+)?(?:pichl[ea]|pichhl[ea]|pehl[ea]\s+ke|purane)\s+(?:instructions?|nirdesh|rules)\b/iu),
|
|
118
|
+
R("extract.hinglish", "hi-Latn", "extract", /\b(?:system\s+prompt|apn[ea]\s+(?:instructions|nirdesh))\s+(?:ko\s+)?(?:dikhao|batao|likho|bata\s+do|dikha\s+do)\b/iu),
|
|
119
|
+
// Finglish (Persian in Latin letters) and Arabizi (Arabic chat-speak with 3 7 5 2 for sounds)
|
|
120
|
+
R("override.finglish", "fa-Latn", "override", /\b(?:dastur|dastoor)(?:at|olamal|ol[ae]mal|ha(?:ye?)?)?\s*(?:e\s*)?(?:ghabli|qabli|ghabl|pishin)\s*(?:ro|ra)?\s*(?:nadide|nadideh|faramush|faramoosh)\s*(?:begir|begirid|kon|konid)\b/iu),
|
|
121
|
+
R("extract.finglish", "fa-Latn", "extract", /\b(?:prompt|payam|dastur(?:at)?)\s*(?:e\s*)?system(?:i)?\s*(?:et|eto|ro|ra)?\s*(?:neshun|neshoon|neshan)\s*(?:bede|bedid|bedin)\b/iu),
|
|
122
|
+
R("override.arabizi", "ar-Latn", "override", /\b(?:t[ae]?[jg]a?h[ae]l|t2[ae]hal|insa|ensa|9arf\s+nazar\s+3n)\s+(?:kol|kul|kel|gami3|jami3)?\s*(?:el|al|l)[- ]?(?:ta3l[ie]?ma?t|t3limat|awamer|2awamer)\s+(?:el|al|l)?[- ]?(?:sab[2']?[ae]?|sab9a|2adeema|qadima|adima|ola)\b/iu),
|
|
123
|
+
// Japanese politeness hides the order ("これまでのご指示はお忘れください"); Korean polite and alternative verbs
|
|
124
|
+
R("override.ja-polite", "ja", "override", /(?:これまで|以前|先ほど|前|上記)の(?:ご)?(?:指示|命令|設定|指図)(?:内容)?(?:は|を)(?:すべて|全て|一旦|いったん)?(?:お忘れ(?:ください|いただ|になって)|ご放念|破棄|取り消|無かったことに|なかったことに|リセット)/u),
|
|
125
|
+
R("extract.ja-polite", "ja", "extract", /(?:システムプロンプト|初期設定|内部の?指示)(?:の内容)?を(?:お教え|ご教示|開示|教えて|表示して)/u),
|
|
126
|
+
R("override.ko2", "ko", "override", /(?:이전|앞선|위의|기존)\s*(?:의\s*)?(?:모든\s*)?(?:지시|지침|명령|설정|규칙)(?:사항)?(?:은|는|을|를)?\s*(?:모두\s*|전부\s*)?(?:잊어|무효|따르지\s*마|폐기|취소)/u),
|
|
56
127
|
];
|
|
128
|
+
/** JavaScript's \b is ASCII-only even with /u: it never fires beside é, ş, Cyrillic or Thai. A Unicode-aware boundary. */
|
|
129
|
+
const UNICODE_BOUNDARY = String.raw `(?:(?<=[\p{L}\p{N}\p{M}_])(?![\p{L}\p{N}\p{M}_])|(?<![\p{L}\p{N}\p{M}_])(?=[\p{L}\p{N}\p{M}_]))`;
|
|
130
|
+
const compile = (src, flags) => new RegExp(src.replace(/\\b/g, UNICODE_BOUNDARY), flags.includes("u") ? flags : flags + "u");
|
|
131
|
+
const scriptFold = (s) => foldIndic(foldArabicScript(s));
|
|
132
|
+
for (const r of MULTILINGUAL_RULES) {
|
|
133
|
+
const src = r.re.source;
|
|
134
|
+
r.re = compile(src, r.re.flags);
|
|
135
|
+
const f = scriptFold(src);
|
|
136
|
+
if (f !== src)
|
|
137
|
+
r.folded = compile(f, r.re.flags);
|
|
138
|
+
const p = stripLatinAccents(src);
|
|
139
|
+
if (p !== src)
|
|
140
|
+
r.plain = compile(p, r.re.flags);
|
|
141
|
+
}
|
|
57
142
|
const KIND_LABEL = {
|
|
58
143
|
override: "instruction to drop prior instructions",
|
|
59
144
|
conceal: "instruction to hide something from the user",
|
|
@@ -70,17 +155,44 @@ export function scanMultilingual(text, hidden, where) {
|
|
|
70
155
|
const nf = text.normalize("NFKC");
|
|
71
156
|
if (nf !== text)
|
|
72
157
|
views.push(["nfkc", nf]);
|
|
158
|
+
// matching-only views (0.9.3): script fold (Arabic, and Devanagari since 0.9.5), rejoined CJK spacing, composed Hangul
|
|
159
|
+
const folded = foldIndic(foldArabicScript(nf));
|
|
160
|
+
if (folded !== nf)
|
|
161
|
+
views.push(["script-fold", folded]);
|
|
162
|
+
// 0.9.5: accents off Latin letters (Vietnamese, Romanian, Turkish typed without them); Turkish casing, where İ
|
|
163
|
+
// lowercases to i and I to ı (JavaScript's /i never folds İ to i); Persian typed on a Latin keyboard layout
|
|
164
|
+
const plain = stripLatinAccents(nf);
|
|
165
|
+
if (plain !== nf)
|
|
166
|
+
views.push(["no-accents", plain]);
|
|
167
|
+
if (/[İıĞŞ]/.test(nf))
|
|
168
|
+
views.push(["turkish-case", nf.toLocaleLowerCase("tr-TR")]);
|
|
169
|
+
if (!/[-ۿ]/.test(nf)) {
|
|
170
|
+
const fa = latinKeysToPersian(nf);
|
|
171
|
+
if (fa !== nf)
|
|
172
|
+
views.push(["persian-keyboard", foldArabicScript(fa)]);
|
|
173
|
+
}
|
|
174
|
+
// compose before NFKC: NFKC turns loose Hangul letters into conjoining initials, which no longer compose
|
|
175
|
+
const composed = composeHangul(despaceCJK(text));
|
|
176
|
+
const joined = composed.normalize("NFKC");
|
|
177
|
+
if (joined !== nf)
|
|
178
|
+
views.push(["cjk-rejoin", joined]);
|
|
179
|
+
// initials are compatibility letters (ㅇㅈ): taken before NFKC, which would turn them into conjoining jamo
|
|
180
|
+
const initials = /[가-힣ㄱ-ㅎ]/.test(composed) ? hangulInitials(composed) : "";
|
|
73
181
|
const out = [];
|
|
74
182
|
for (const rule of MULTILINGUAL_RULES) {
|
|
75
|
-
for (const [view, t] of views) {
|
|
76
|
-
const
|
|
183
|
+
for (const [view, t] of rule.initialsOnly ? (initials ? [["hangul-initials", initials]] : []) : views) {
|
|
184
|
+
const re = (view === "script-fold" || view === "persian-keyboard") && rule.folded ? rule.folded : view === "no-accents" && rule.plain ? rule.plain : rule.re;
|
|
185
|
+
const m = t.match(re);
|
|
77
186
|
if (!m)
|
|
78
187
|
continue;
|
|
188
|
+
// two rules on the same words are one instruction
|
|
189
|
+
if (out.some((f) => f.excerpt && (f.excerpt.includes(m[0].slice(0, 120)) || m[0].includes(f.excerpt))))
|
|
190
|
+
break;
|
|
79
191
|
out.push({
|
|
80
192
|
pass: "meaning", kind: rule.kind === "extract" ? "meaning.system_prompt_imitation" : "meaning.instruction_shaped",
|
|
81
|
-
confidence: hidden ? 0.85 : 0.
|
|
82
|
-
message: `${KIND_LABEL[rule.kind]} (${rule.lang}, rule ${rule.id}, ${view} view; ${MULTILINGUAL_RULESET})${hidden ? ", in text a human would not see" : ", visible:
|
|
83
|
-
excerpt: m[0].slice(0, 120), location: where, inHidden: hidden, action: hidden ? "quarantined" : "
|
|
193
|
+
confidence: hidden ? 0.85 : 0.675, severity: hidden ? 0.9 : 0.6,
|
|
194
|
+
message: `${KIND_LABEL[rule.kind]} (${rule.lang}, rule ${rule.id}, ${view} view; ${MULTILINGUAL_RULESET})${hidden ? ", in text a human would not see" : ", visible: same weight as the English shape"}`,
|
|
195
|
+
excerpt: m[0].slice(0, 120), location: where, inHidden: hidden, action: hidden ? "quarantined" : "neutralized",
|
|
84
196
|
});
|
|
85
197
|
break;
|
|
86
198
|
}
|