Compare commits

..

No commits in common. "main" and "3.3.2" have entirely different histories.
main ... 3.3.2

21 changed files with 985 additions and 898 deletions

View file

@ -20,13 +20,11 @@ build-all:
- turbo build - turbo build
.docker-build: .docker-build:
image: registry.gitlab.com/digiresilience/link/link-stack/buildx:main image: registry.gitlab.com/digiresilience/link/link-stack/buildx:${CI_COMMIT_REF_NAME}
services: services:
- docker:dind - docker:dind
stage: docker-build stage: docker-build
variables: variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
DOCKER_TAG: ${CI_COMMIT_SHORT_SHA} DOCKER_TAG: ${CI_COMMIT_SHORT_SHA}
BUILD_CONTEXT: . BUILD_CONTEXT: .
only: only:
@ -39,13 +37,11 @@ build-all:
- docker push ${DOCKER_NS}:${DOCKER_TAG} - docker push ${DOCKER_NS}:${DOCKER_TAG}
.docker-release: .docker-release:
image: registry.gitlab.com/digiresilience/link/link-stack/buildx:main image: registry.gitlab.com/digiresilience/link/link-stack/buildx:${CI_COMMIT_REF_NAME}
services: services:
- docker:dind - docker:dind
stage: docker-release stage: docker-release
variables: variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
DOCKER_TAG: ${CI_COMMIT_SHORT_SHA} DOCKER_TAG: ${CI_COMMIT_SHORT_SHA}
DOCKER_TAG_NEW: ${CI_COMMIT_REF_NAME} DOCKER_TAG_NEW: ${CI_COMMIT_REF_NAME}
only: only:
@ -199,8 +195,8 @@ zammad-docker-build:
PNPM_HOME: "/pnpm" PNPM_HOME: "/pnpm"
before_script: before_script:
- export PATH="$PNPM_HOME:$PATH" - export PATH="$PNPM_HOME:$PATH"
- corepack enable && corepack prepare pnpm@9.15.4 --activate
script: script:
- corepack enable && corepack prepare pnpm@9.15.4 --activate
- pnpm add -g turbo - pnpm add -g turbo
- pnpm install --frozen-lockfile - pnpm install --frozen-lockfile
- turbo build --force --filter @link-stack/zammad-addon-* - turbo build --force --filter @link-stack/zammad-addon-*
@ -222,8 +218,8 @@ zammad-standalone-docker-build:
PNPM_HOME: "/pnpm" PNPM_HOME: "/pnpm"
before_script: before_script:
- export PATH="$PNPM_HOME:$PATH" - export PATH="$PNPM_HOME:$PATH"
- corepack enable && corepack prepare pnpm@9.15.4 --activate
script: script:
- corepack enable && corepack prepare pnpm@9.15.4 --activate
- pnpm add -g turbo - pnpm add -g turbo
- pnpm install --frozen-lockfile - pnpm install --frozen-lockfile
- turbo build --force --filter @link-stack/zammad-addon-* - turbo build --force --filter @link-stack/zammad-addon-*

View file

@ -20,4 +20,3 @@ We use [Turborepo](https://turbo.build) to manage development and building of th
To run a single package: To run a single package:
- `turbo dev --filter @link-stack/link` - `turbo dev --filter @link-stack/link`

View file

@ -1,6 +1,6 @@
{ {
"name": "@link-stack/bridge-frontend", "name": "@link-stack/bridge-frontend",
"version": "3.3.5", "version": "3.3.2",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "next dev", "dev": "next dev",
@ -20,7 +20,7 @@
"@mui/x-license": "^7", "@mui/x-license": "^7",
"@link-stack/bridge-common": "workspace:*", "@link-stack/bridge-common": "workspace:*",
"@link-stack/bridge-ui": "workspace:*", "@link-stack/bridge-ui": "workspace:*",
"next": "15.5.9", "next": "15.5.4",
"next-auth": "^4.24.11", "next-auth": "^4.24.11",
"react": "19.2.0", "react": "19.2.0",
"react-dom": "19.2.0", "react-dom": "19.2.0",

View file

@ -1,6 +1,6 @@
{ {
"name": "@link-stack/bridge-migrations", "name": "@link-stack/bridge-migrations",
"version": "3.3.5", "version": "3.3.2",
"type": "module", "type": "module",
"scripts": { "scripts": {
"migrate:up:all": "tsx migrate.ts up:all", "migrate:up:all": "tsx migrate.ts up:all",

View file

@ -1,6 +1,6 @@
{ {
"name": "@link-stack/bridge-whatsapp", "name": "@link-stack/bridge-whatsapp",
"version": "3.3.5", "version": "3.3.2",
"main": "build/main/index.js", "main": "build/main/index.js",
"author": "Darren Clarke <darren@redaranj.com>", "author": "Darren Clarke <darren@redaranj.com>",
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
@ -11,7 +11,7 @@
"@hapipal/toys": "^4.0.0", "@hapipal/toys": "^4.0.0",
"@link-stack/bridge-common": "workspace:*", "@link-stack/bridge-common": "workspace:*",
"@link-stack/logger": "workspace:*", "@link-stack/logger": "workspace:*",
"@whiskeysockets/baileys": "6.7.21", "@whiskeysockets/baileys": "^6.7.21",
"hapi-pino": "^13.0.0", "hapi-pino": "^13.0.0",
"link-preview-js": "^3.1.0" "link-preview-js": "^3.1.0"
}, },

View file

@ -26,7 +26,11 @@ export default class WhatsappService extends Service {
connections: { [key: string]: any } = {}; connections: { [key: string]: any } = {};
loginConnections: { [key: string]: any } = {}; loginConnections: { [key: string]: any } = {};
static browserDescription: [string, string, string] = ["Bridge", "Chrome", "2.0"]; static browserDescription: [string, string, string] = [
"Bridge",
"Chrome",
"2.0",
];
constructor(server: Server, options: never) { constructor(server: Server, options: never) {
super(server, options); super(server, options);
@ -43,7 +47,7 @@ export default class WhatsappService extends Service {
} }
// Prevent path traversal by checking for suspicious patterns // Prevent path traversal by checking for suspicious patterns
if (id.includes("..") || id.includes("/") || id.includes("\\")) { if (id.includes('..') || id.includes('/') || id.includes('\\')) {
throw new Error(`Path traversal detected in bot ID: ${id}`); throw new Error(`Path traversal detected in bot ID: ${id}`);
} }
@ -98,14 +102,20 @@ export default class WhatsappService extends Service {
auth: state, auth: state,
generateHighQualityLinkPreview: false, generateHighQualityLinkPreview: false,
msgRetryCounterMap, msgRetryCounterMap,
shouldIgnoreJid: (jid) => isJidBroadcast(jid) || isJidStatusBroadcast(jid), shouldIgnoreJid: (jid) =>
isJidBroadcast(jid) || isJidStatusBroadcast(jid),
}); });
let pause = 5000; let pause = 5000;
socket.ev.process(async (events) => { socket.ev.process(async (events) => {
if (events["connection.update"]) { if (events["connection.update"]) {
const update = events["connection.update"]; const update = events["connection.update"];
const { connection: connectionState, lastDisconnect, qr, isNewLogin } = update; const {
connection: connectionState,
lastDisconnect,
qr,
isNewLogin,
} = update;
if (qr) { if (qr) {
logger.info("got qr code"); logger.info("got qr code");
const botDirectory = this.getBotDirectory(botID); const botDirectory = this.getBotDirectory(botID);
@ -120,7 +130,8 @@ export default class WhatsappService extends Service {
logger.info("opened connection"); logger.info("opened connection");
} else if (connectionState === "close") { } else if (connectionState === "close") {
logger.info({ lastDisconnect }, "connection closed"); logger.info({ lastDisconnect }, "connection closed");
const disconnectStatusCode = (lastDisconnect?.error as any)?.output?.statusCode; const disconnectStatusCode = (lastDisconnect?.error as any)?.output
?.statusCode;
if (disconnectStatusCode === DisconnectReason.restartRequired) { if (disconnectStatusCode === DisconnectReason.restartRequired) {
logger.info("reconnecting after got new login"); logger.info("reconnecting after got new login");
await this.createConnection(botID, server, options); await this.createConnection(botID, server, options);
@ -163,7 +174,10 @@ export default class WhatsappService extends Service {
const verifiedFile = `${directory}/verified`; const verifiedFile = `${directory}/verified`;
if (fs.existsSync(verifiedFile)) { if (fs.existsSync(verifiedFile)) {
const { version, isLatest } = await fetchLatestBaileysVersion(); const { version, isLatest } = await fetchLatestBaileysVersion();
logger.info({ version: version.join("."), isLatest }, "using WA version"); logger.info(
{ version: version.join("."), isLatest },
"using WA version",
);
await this.createConnection(botID, this.server, { await this.createConnection(botID, this.server, {
browser: WhatsappService.browserDescription, browser: WhatsappService.browserDescription,
@ -174,7 +188,10 @@ export default class WhatsappService extends Service {
} }
} }
private async queueMessage(botID: string, webMessageInfo: proto.IWebMessageInfo) { private async queueMessage(
botID: string,
webMessageInfo: proto.IWebMessageInfo,
) {
const { const {
key: { id, fromMe, remoteJid }, key: { id, fromMe, remoteJid },
message, message,
@ -187,9 +204,11 @@ export default class WhatsappService extends Service {
"Message field", "Message field",
); );
} }
const isValidMessage = message && remoteJid !== "status@broadcast" && !fromMe; const isValidMessage =
message && remoteJid !== "status@broadcast" && !fromMe;
if (isValidMessage) { if (isValidMessage) {
const { audioMessage, documentMessage, imageMessage, videoMessage } = message; const { audioMessage, documentMessage, imageMessage, videoMessage } =
message;
const isMediaMessage = const isMediaMessage =
audioMessage || documentMessage || imageMessage || videoMessage; audioMessage || documentMessage || imageMessage || videoMessage;
@ -269,7 +288,10 @@ export default class WhatsappService extends Service {
} }
} }
private async queueUnreadMessages(botID: string, messages: proto.IWebMessageInfo[]) { private async queueUnreadMessages(
botID: string,
messages: proto.IWebMessageInfo[],
) {
for await (const message of messages) { for await (const message of messages) {
await this.queueMessage(botID, message); await this.queueMessage(botID, message);
} }
@ -312,7 +334,10 @@ export default class WhatsappService extends Service {
} }
} }
async register(botID: string, callback?: AuthCompleteCallback): Promise<void> { async register(
botID: string,
callback?: AuthCompleteCallback,
): Promise<void> {
const { version } = await fetchLatestBaileysVersion(); const { version } = await fetchLatestBaileysVersion();
await this.createConnection( await this.createConnection(
botID, botID,
@ -330,10 +355,7 @@ export default class WhatsappService extends Service {
attachments?: Array<{ data: string; filename: string; mime_type: string }>, attachments?: Array<{ data: string; filename: string; mime_type: string }>,
): Promise<void> { ): Promise<void> {
const connection = this.connections[botID]?.socket; const connection = this.connections[botID]?.socket;
const digits = phoneNumber.replace(/\D+/g, ""); const recipient = `${phoneNumber.replace(/\D+/g, "")}@s.whatsapp.net`;
// LIDs are 15+ digits, phone numbers with country code are typically 10-14 digits
const suffix = digits.length > 14 ? "@lid" : "@s.whatsapp.net";
const recipient = `${digits}${suffix}`;
// Send text message if provided // Send text message if provided
if (message) { if (message) {
@ -346,9 +368,7 @@ export default class WhatsappService extends Service {
const MAX_TOTAL_SIZE = getMaxTotalAttachmentSize(); const MAX_TOTAL_SIZE = getMaxTotalAttachmentSize();
if (attachments.length > MAX_ATTACHMENTS) { if (attachments.length > MAX_ATTACHMENTS) {
throw new Error( throw new Error(`Too many attachments: ${attachments.length} (max ${MAX_ATTACHMENTS})`);
`Too many attachments: ${attachments.length} (max ${MAX_ATTACHMENTS})`,
);
} }
let totalSize = 0; let totalSize = 0;
@ -358,26 +378,20 @@ export default class WhatsappService extends Service {
const estimatedSize = (attachment.data.length * 3) / 4; const estimatedSize = (attachment.data.length * 3) / 4;
if (estimatedSize > MAX_ATTACHMENT_SIZE) { if (estimatedSize > MAX_ATTACHMENT_SIZE) {
logger.warn( logger.warn({
{
filename: attachment.filename, filename: attachment.filename,
size: estimatedSize, size: estimatedSize,
maxSize: MAX_ATTACHMENT_SIZE, maxSize: MAX_ATTACHMENT_SIZE
}, }, 'Attachment exceeds size limit, skipping');
"Attachment exceeds size limit, skipping",
);
continue; continue;
} }
totalSize += estimatedSize; totalSize += estimatedSize;
if (totalSize > MAX_TOTAL_SIZE) { if (totalSize > MAX_TOTAL_SIZE) {
logger.warn( logger.warn({
{
totalSize, totalSize,
maxTotalSize: MAX_TOTAL_SIZE, maxTotalSize: MAX_TOTAL_SIZE
}, }, 'Total attachment size exceeds limit, skipping remaining');
"Total attachment size exceeds limit, skipping remaining",
);
break; break;
} }

View file

@ -1,6 +1,6 @@
{ {
"name": "@link-stack/bridge-worker", "name": "@link-stack/bridge-worker",
"version": "3.3.5", "version": "3.3.2",
"type": "module", "type": "module",
"main": "build/main/index.js", "main": "build/main/index.js",
"author": "Darren Clarke <darren@redaranj.com>", "author": "Darren Clarke <darren@redaranj.com>",

View file

@ -1,6 +1,6 @@
{ {
"name": "@link-stack/link", "name": "@link-stack/link",
"version": "3.3.5", "version": "3.3.2",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "next dev -H 0.0.0.0", "dev": "next dev -H 0.0.0.0",
@ -31,7 +31,7 @@
"graphql-request": "^7.2.0", "graphql-request": "^7.2.0",
"ioredis": "^5.8.1", "ioredis": "^5.8.1",
"mui-chips-input": "^6.0.0", "mui-chips-input": "^6.0.0",
"next": "15.5.9", "next": "15.5.4",
"next-auth": "^4.24.11", "next-auth": "^4.24.11",
"react": "19.2.0", "react": "19.2.0",
"react-cookie": "^8.0.1", "react-cookie": "^8.0.1",

View file

@ -1,6 +1,6 @@
{ {
"name": "@link-stack", "name": "@link-stack",
"version": "3.3.5", "version": "3.3.2",
"description": "Link from the Center for Digital Resilience", "description": "Link from the Center for Digital Resilience",
"scripts": { "scripts": {
"dev": "dotenv -- turbo dev", "dev": "dotenv -- turbo dev",

View file

@ -1,6 +1,6 @@
{ {
"name": "@link-stack/bridge-common", "name": "@link-stack/bridge-common",
"version": "3.3.5", "version": "3.3.2",
"main": "build/main/index.js", "main": "build/main/index.js",
"type": "module", "type": "module",
"author": "Darren Clarke <darren@redaranj.com>", "author": "Darren Clarke <darren@redaranj.com>",

View file

@ -1,6 +1,6 @@
{ {
"name": "@link-stack/bridge-ui", "name": "@link-stack/bridge-ui",
"version": "3.3.5", "version": "3.3.2",
"scripts": { "scripts": {
"build": "tsc -p tsconfig.json" "build": "tsc -p tsconfig.json"
}, },
@ -11,7 +11,7 @@
"@mui/material": "^6", "@mui/material": "^6",
"@mui/x-data-grid-pro": "^7", "@mui/x-data-grid-pro": "^7",
"kysely": "0.27.5", "kysely": "0.27.5",
"next": "15.5.9", "next": "15.5.4",
"react": "19.2.0", "react": "19.2.0",
"react-dom": "19.2.0", "react-dom": "19.2.0",
"react-qr-code": "^2.0.18" "react-qr-code": "^2.0.18"

View file

@ -1,6 +1,6 @@
{ {
"name": "@link-stack/eslint-config", "name": "@link-stack/eslint-config",
"version": "3.3.5", "version": "3.3.2",
"description": "amigo's eslint config", "description": "amigo's eslint config",
"main": "index.js", "main": "index.js",
"author": "Abel Luck <abel@guardianproject.info>", "author": "Abel Luck <abel@guardianproject.info>",

View file

@ -1,6 +1,6 @@
{ {
"name": "@link-stack/jest-config", "name": "@link-stack/jest-config",
"version": "3.3.5", "version": "3.3.2",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"author": "Abel Luck <abel@guardianproject.info>", "author": "Abel Luck <abel@guardianproject.info>",

View file

@ -1,6 +1,6 @@
{ {
"name": "@link-stack/logger", "name": "@link-stack/logger",
"version": "3.3.5", "version": "3.3.2",
"description": "Shared logging utility for Link Stack monorepo", "description": "Shared logging utility for Link Stack monorepo",
"main": "./dist/index.js", "main": "./dist/index.js",
"module": "./dist/index.mjs", "module": "./dist/index.mjs",

View file

@ -1,6 +1,6 @@
{ {
"name": "@link-stack/signal-api", "name": "@link-stack/signal-api",
"version": "3.3.5", "version": "3.3.2",
"type": "module", "type": "module",
"main": "build/index.js", "main": "build/index.js",
"exports": { "exports": {

View file

@ -1,6 +1,6 @@
{ {
"name": "@link-stack/typescript-config", "name": "@link-stack/typescript-config",
"version": "3.3.5", "version": "3.3.2",
"description": "Shared TypeScript config", "description": "Shared TypeScript config",
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
"author": "Abel Luck <abel@guardianproject.info>", "author": "Abel Luck <abel@guardianproject.info>",

View file

@ -1,6 +1,6 @@
{ {
"name": "@link-stack/ui", "name": "@link-stack/ui",
"version": "3.3.5", "version": "3.3.2",
"description": "", "description": "",
"scripts": { "scripts": {
"build": "tsc -p tsconfig.json" "build": "tsc -p tsconfig.json"
@ -11,7 +11,7 @@
"@mui/material": "^6", "@mui/material": "^6",
"@mui/x-data-grid-pro": "^7", "@mui/x-data-grid-pro": "^7",
"@mui/x-license": "^7", "@mui/x-license": "^7",
"next": "15.5.9", "next": "15.5.4",
"react": "19.2.0", "react": "19.2.0",
"react-dom": "19.2.0" "react-dom": "19.2.0"
}, },

View file

@ -1,7 +1,7 @@
{ {
"name": "@link-stack/zammad-addon-bridge", "name": "@link-stack/zammad-addon-bridge",
"displayName": "Bridge", "displayName": "Bridge",
"version": "3.3.5", "version": "3.3.2",
"description": "An addon that adds CDR Bridge channels to Zammad.", "description": "An addon that adds CDR Bridge channels to Zammad.",
"scripts": { "scripts": {
"build": "node '../zammad-addon-common/dist/build.js'", "build": "node '../zammad-addon-common/dist/build.js'",

View file

@ -1,6 +1,6 @@
{ {
"name": "@link-stack/zammad-addon-common", "name": "@link-stack/zammad-addon-common",
"version": "3.3.5", "version": "3.3.2",
"description": "", "description": "",
"bin": { "bin": {
"zpm-build": "./dist/build.js", "zpm-build": "./dist/build.js",

View file

@ -1,7 +1,7 @@
{ {
"name": "@link-stack/zammad-addon-hardening", "name": "@link-stack/zammad-addon-hardening",
"displayName": "Hardening", "displayName": "Hardening",
"version": "3.3.5", "version": "3.3.2",
"description": "A Zammad addon that hardens a Zammad instance according to CDR's needs.", "description": "A Zammad addon that hardens a Zammad instance according to CDR's needs.",
"scripts": { "scripts": {
"build": "node '../zammad-addon-common/dist/build.js'", "build": "node '../zammad-addon-common/dist/build.js'",

1746
pnpm-lock.yaml generated

File diff suppressed because it is too large Load diff