Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ In a PR that changes something users will notice, add a line under **Unreleased*

## Unreleased

### Fixed

- MessageLogger only saves image previews hosted by Slack, so a message can no longer reveal your connection to external hosts.

## Build 160

### Fixed
Expand Down
31 changes: 19 additions & 12 deletions src/plugins/MessageLogger/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,26 @@ const MAX_DOWNLOAD_BYTES = 2 * 1024 * 1024;
const MAX_ARCHIVED = 128;
const MAX_RECENT = 64;
const RASTER = /^image\/(png|jpeg|gif|webp)$/i;
const SLACK_FILE_HOSTS = ['files.slack.com', 'files-origin.slack.com', 'files.slack-edge.com'];

export function isSlackFileUrl(value: unknown): value is string {
if (typeof value !== 'string') return false;
try {
const url = new URL(value);
return (
url.protocol === 'https:' &&
!url.username &&
!url.password &&
!url.port &&
SLACK_FILE_HOSTS.includes(url.hostname)
);
} catch {
return false;
}
}

function urls(values: unknown[]): string[] {
return [
...new Set(
values.filter((value): value is string => {
if (typeof value !== 'string') return false;
try {
return new URL(value).protocol === 'https:';
} catch {
return false;
}
}),
),
];
return [...new Set(values.filter(isSlackFileUrl))];
}

/** Prefer a Slack preview: originals can be huge, and private URLs need session cookies. */
Expand Down Expand Up @@ -72,6 +78,7 @@ function dataURL(blob: Blob): Promise<string> {
}

export async function downloadImage(url: string, signal: AbortSignal): Promise<string | null> {
if (!isSlackFileUrl(url)) return null;
const response = await fetch(url, {
credentials: 'include',
signal: AbortSignal.any([signal, AbortSignal.timeout(10_000)]),
Expand Down
Loading