fix: add URL encoding and remove unused import

- Add encodeURIComponent() for project, version, and filename parameters in downloadUrl to prevent XSS and URL breakage
- Remove unused formatDateTime import

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-03-04 01:59:53 +08:00
parent 0d1ba31175
commit 91c94bde88

View File

@@ -1,6 +1,6 @@
// app/api/apks/route.ts // app/api/apks/route.ts
import { NextResponse } from 'next/server'; import { NextResponse } from 'next/server';
import { getApks, formatDateTime } from '@/lib/fs-utils'; import { getApks } from '@/lib/fs-utils';
export async function GET(request: Request) { export async function GET(request: Request) {
const { searchParams } = new URL(request.url); const { searchParams } = new URL(request.url);
@@ -20,7 +20,7 @@ export async function GET(request: Request) {
const apksWithUrls = apks.map(apk => ({ const apksWithUrls = apks.map(apk => ({
...apk, ...apk,
modifiedAt: apk.modifiedAt.toISOString(), modifiedAt: apk.modifiedAt.toISOString(),
downloadUrl: `/api/download?project=${project}&version=${version}&filename=${apk.name}`, downloadUrl: `/api/download?project=${encodeURIComponent(project)}&version=${encodeURIComponent(version)}&filename=${encodeURIComponent(apk.name)}`,
})); }));
return NextResponse.json(apksWithUrls); return NextResponse.json(apksWithUrls);
} catch (error) { } catch (error) {