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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "trackarr",
"version": "0.5.3",
"version": "0.5.4",
"type": "module",
"private": true,
"scripts": {
Expand Down
10 changes: 5 additions & 5 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -726,11 +726,11 @@ main() {
echo -e "${GREEN}${BOLD}"
echo " ┌──────────────────────────────────────────────────────────────────────────┐"
echo " │ │"
echo " │ ____ ____ _____ _ _ _____ ____ _ ____ _ _______ ____ │"
echo " │ / __ \| _ \| ____| \ | |_ _| _ \ / \ / ___| |/ / ____| _ \ │"
echo " │ | | | | |_) | _| | \| | | | | |_) | / _ \| | | ' /| _| | |_) | │"
echo " │ | |__| | __/| |___| |\ | | | | _ < / ___ \ |___| . \| |___| _ < │"
echo " │ \____/|_| |_____|_| \_| |_| |_| \_/_/ \_\____|_|\_\_____|_| \_\ │"
echo " │ _____ ____ _ ____ _ __ _ ____ ____ │"
echo " │ |_ _| _ \ / \ / ___| |/ / / \ | _ \| _ \ │"
echo " │ | | | |_) | / _ \| | | ' / / _ \ | |_) | |_) | │"
echo " │ | | | _ < / ___ \ |___| . \ / ___ \| _ <| _ < │"
echo " │ |_| |_| \_\/_/ \_\____|_|\_\/_/ \_\_| \_\_| \_\ │"
echo " │ │"
echo " │ Production Server Installation Script │"
echo " │ │"
Expand Down
29 changes: 16 additions & 13 deletions server/api/torznab/download.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,31 @@ export default defineEventHandler(async (event) => {
const enabled = await getTorznabEnabled();
if (!enabled) {
setHeader(event, 'Content-Type', 'application/xml; charset=utf-8');
throw createError({
statusCode: 503,
message: 'Torznab API is currently disabled',
data: buildErrorXml({
code: 900,
description: 'Torznab API is currently disabled',
}),
return buildErrorXml({
code: 900,
description: 'Torznab API is currently disabled',
});
}

// Authenticate via passkey
const user = await authenticateTorznab(event);
let user: Awaited<ReturnType<typeof authenticateTorznab>>;
try {
user = await authenticateTorznab(event);
} catch (error: any) {
// If it's a Torznab error, return the XML directly
if (error.isTorznab && error.data) {
setHeader(event, 'Content-Type', 'application/xml; charset=utf-8');
setResponseStatus(event, error.statusCode || 400);
return error.data;
}
throw error;
}

// Check if user is blocked from Torznab API
const blockStatus = await isTorznabUserBlocked(user.passkey);
if (blockStatus.blocked) {
setHeader(event, 'Content-Type', 'application/xml; charset=utf-8');
throw createError({
statusCode: 403,
message: blockStatus.reason || 'Access denied',
data: buildErrorXml(TORZNAB_ERRORS.ACCOUNT_SUSPENDED),
});
return buildErrorXml(TORZNAB_ERRORS.ACCOUNT_SUSPENDED);
}

// Apply dynamic rate limiting
Expand Down
14 changes: 13 additions & 1 deletion server/api/torznab/index.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,19 @@ export default defineEventHandler(async (event) => {
}

// All other functions require authentication
const user = await authenticateTorznab(event);
// Wrap in try/catch to handle Torznab XML errors properly
let user: { passkey: string };
try {
user = await authenticateTorznab(event);
} catch (error: any) {
// If it's a Torznab error, return the XML directly
if (error.isTorznab && error.data) {
setHeader(event, 'Content-Type', 'application/xml; charset=utf-8');
setResponseStatus(event, error.statusCode || 400);
return error.data;
}
throw error;
}

// Check if user is blocked from Torznab API
const blockStatus = await isTorznabUserBlocked(user.passkey);
Expand Down
27 changes: 16 additions & 11 deletions server/api/torznab/utils/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ export async function authenticateTorznab(
);
}

// Validate passkey format (40 hex chars)
if (!/^[a-f0-9]{40}$/i.test(apikey)) {
// Validate passkey format (32 or 40 hex chars - supports legacy and new passkeys)
if (!/^[a-f0-9]{32}$/i.test(apikey) && !/^[a-f0-9]{40}$/i.test(apikey)) {
throw createTorznabError(
event,
TORZNAB_ERRORS.INCORRECT_CREDENTIALS,
`Invalid API key format. Expected 40 hex characters (your passkey), got ${apikey.length} characters`
`Invalid API key format. Expected 32 or 40 hex characters (your passkey), got ${apikey.length} characters`
);
}

Expand Down Expand Up @@ -73,24 +73,29 @@ export async function authenticateTorznab(

/**
* Create a Torznab-compliant error response
* The error contains XML in the 'data' field which should be extracted by the caller
*/
export function createTorznabError(
event: H3Event,
error: { code: number; description: string },
customMessage?: string
): Error {
setHeader(event, 'Content-Type', 'application/xml; charset=utf-8');

): never {
const httpStatus = error.code === 100 || error.code === 101 ? 401 : 400;
const xml = buildErrorXml({
code: error.code,
description: customMessage ?? error.description,
});

throw createError({
const err = createError({
statusCode: httpStatus,
statusMessage: 'Torznab Error',
message: customMessage ?? error.description,
data: buildErrorXml({
code: error.code,
description: customMessage ?? error.description,
}),
data: xml,
});
// Mark this as a Torznab error so we can handle it specially
(err as any).isTorznab = true;

throw err;
}

/**
Expand Down