mirror of
https://github.com/calibrain/shelfmark.git
synced 2026-11-27 08:51:13 +00:00
fix: keep https:// for qBittorrent and hide release sources from non-admins (#1422)
qBittorrent over HTTPS (#1417) qbittorrent-api ignores the scheme in `host` and probes HTTP and HTTPS itself. When the HTTPS probe fails, for instance on a certificate Shelfmark doesn't trust, it falls back to plain HTTP against the TLS port, and a reverse proxy answers "400 The plain HTTP request was sent to HTTPS port". The download client and the Test Connection button now pass FORCE_SCHEME_FROM_HOST for https:// URLs, so the configured scheme is used as-is and a certificate problem is reported as one. http:// and bare host:port URLs keep the probe: normalization adds http:// to a bare host, and the probe follows a proxy's redirect to HTTPS. Release sources leaked to non-admins (#1418) A download queued from an approved request carries the release an admin picked, and the requester could read it from their own activity feed: the request's release_data (source_id, indexer, info URL, torrent attributes), the download's full server path, and the download id itself, which for Prowlarr is "<indexer id>:<guid>" and for a private tracker is a URL into it. That id keys every status payload, the /api/localdownload query and the cover proxy URL, so hiding release_data alone would not have closed the leak. For non-admin viewers: - request rows keep only the release fields the activity cards display - download_path is reduced to the file name, which the browser download reveals anyway - request-linked downloads are addressed by an opaque id (a keyed HMAC of the task id) in the snapshot, history, /api/status, queue order, active downloads, dismissed keys, cover URLs and the websocket status and progress events. Routes that take a download id translate it back, searching only the caller's own downloads. Downloads a user queued directly keep their real id: the user picked that release from search results that already showed it, and the release list matches its buttons to the queue by that id. Admin views are unchanged. The activity sidebar now links a fulfilled request to its download by request_id instead of release_data.source_id. Closes #1417 Closes #1418
This commit is contained in:
1 parent
fcdc2dfb69
commit
bac0b93566
18 files changed
+906
-54
No files matched your search
@@ -7,7 +7,7 @@ import type { RequestRecord, StatusData } from '../../types';
|
||||
import { Dropdown } from '../Dropdown';
|
||||
import { ActivityCard } from './ActivityCard';
|
||||
import type { DownloadStatusKey } from './activityMappers';
|
||||
import { downloadToActivityItem } from './activityMappers';
|
||||
import { downloadToActivityItem, linkedDownloadIdForRequest } from './activityMappers';
|
||||
import type { ActivityItem } from './activityTypes';
|
||||
|
||||
interface ActivitySidebarProps {
|
||||
@@ -146,25 +146,6 @@ const getActivityCategory = (item: ActivityItem): ActivityCategoryKey => {
|
||||
return 'in_progress';
|
||||
};
|
||||
|
||||
const getLinkedDownloadIdFromRequestItem = (item: ActivityItem): string | null => {
|
||||
if (item.kind !== 'request' || item.visualStatus !== 'fulfilled') {
|
||||
return null;
|
||||
}
|
||||
|
||||
const releaseData = item.requestRecord?.release_data;
|
||||
if (!releaseData || typeof releaseData !== 'object') {
|
||||
return null;
|
||||
}
|
||||
|
||||
const sourceId = releaseData.source_id;
|
||||
if (typeof sourceId !== 'string') {
|
||||
return null;
|
||||
}
|
||||
|
||||
const trimmed = sourceId.trim();
|
||||
return trimmed ? trimmed : null;
|
||||
};
|
||||
|
||||
const mergeRequestWithDownload = (
|
||||
requestItem: ActivityItem,
|
||||
downloadItem: ActivityItem,
|
||||
@@ -320,9 +301,17 @@ export const ActivitySidebar = ({
|
||||
|
||||
const { mergedRequestItems, mergedDownloadItems } = useMemo(() => {
|
||||
const downloadsById = new Map<string, ActivityItem>();
|
||||
// downloadItems is newest first, so a retried request keeps its latest download.
|
||||
const latestDownloadIdByRequestId = new Map<number, string>();
|
||||
downloadItems.forEach((item) => {
|
||||
if (item.downloadBookId) {
|
||||
downloadsById.set(item.downloadBookId, item);
|
||||
if (
|
||||
typeof item.requestId === 'number' &&
|
||||
!latestDownloadIdByRequestId.has(item.requestId)
|
||||
) {
|
||||
latestDownloadIdByRequestId.set(item.requestId, item.downloadBookId);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -345,7 +334,7 @@ export const ActivitySidebar = ({
|
||||
});
|
||||
|
||||
const nextRequestItems = visibleRequestItems.map((requestItem) => {
|
||||
const linkedDownloadId = getLinkedDownloadIdFromRequestItem(requestItem);
|
||||
const linkedDownloadId = linkedDownloadIdForRequest(requestItem, latestDownloadIdByRequestId);
|
||||
if (!linkedDownloadId) {
|
||||
return requestItem;
|
||||
}
|
||||
|
||||
@@ -188,3 +188,25 @@ export const requestToActivityItem = (
|
||||
requestRecord: record,
|
||||
};
|
||||
};
|
||||
|
||||
/** The id of the download a fulfilled request item was delivered through, if listed. */
|
||||
export const linkedDownloadIdForRequest = (
|
||||
item: ActivityItem,
|
||||
latestDownloadIdByRequestId: Map<number, string>,
|
||||
): string | null => {
|
||||
if (item.kind !== 'request' || item.visualStatus !== 'fulfilled') {
|
||||
return null;
|
||||
}
|
||||
|
||||
const sourceId = item.requestRecord?.release_data?.source_id;
|
||||
if (typeof sourceId === 'string' && sourceId.trim()) {
|
||||
return sourceId.trim();
|
||||
}
|
||||
|
||||
// Non-admins don't receive the release's source_id (#1418), so their request is
|
||||
// matched to the download queued for it instead.
|
||||
if (typeof item.requestId !== 'number') {
|
||||
return null;
|
||||
}
|
||||
return latestDownloadIdByRequestId.get(item.requestId) ?? null;
|
||||
};
|
||||
@@ -2,6 +2,7 @@ import { describe, it, expect } from 'vitest';
|
||||
|
||||
import {
|
||||
downloadToActivityItem,
|
||||
linkedDownloadIdForRequest,
|
||||
requestToActivityItem,
|
||||
} from '../components/activity/activityMappers';
|
||||
import type { Book, RequestRecord } from '../types/index';
|
||||
@@ -191,3 +192,32 @@ describe('activityMappers.requestToActivityItem', () => {
|
||||
expect(item.metaLine).toBe('EPUB · 2 MB · Prowlarr');
|
||||
});
|
||||
});
|
||||
|
||||
const fulfilled = (releaseData: Record<string, unknown> | null) =>
|
||||
requestToActivityItem(
|
||||
makeRequest({ status: 'fulfilled', request_level: 'book', release_data: releaseData }),
|
||||
'user',
|
||||
);
|
||||
|
||||
describe('activityMappers.linkedDownloadIdForRequest', () => {
|
||||
it("links through the release's source_id when the viewer has it", () => {
|
||||
const item = fulfilled({ source_id: '21:https://tracker.example/t/1', format: 'epub' });
|
||||
|
||||
expect(linkedDownloadIdForRequest(item, new Map([[42, 'dl_other']]))).toBe(
|
||||
'21:https://tracker.example/t/1',
|
||||
);
|
||||
});
|
||||
|
||||
it('falls back to the download queued for the request when source_id is withheld', () => {
|
||||
const item = fulfilled({ format: 'epub', size: '2 MB' });
|
||||
|
||||
expect(linkedDownloadIdForRequest(item, new Map([[42, 'dl_abc']]))).toBe('dl_abc');
|
||||
expect(linkedDownloadIdForRequest(item, new Map())).toBeNull();
|
||||
});
|
||||
|
||||
it('does not link a request that has not been fulfilled', () => {
|
||||
const item = requestToActivityItem(makeRequest({ status: 'pending' }), 'user');
|
||||
|
||||
expect(linkedDownloadIdForRequest(item, new Map([[42, 'dl_abc']]))).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user