Fix #20420: Prevent double decoding of file URL parameter

This commit is contained in:
Uzair-Ahmed-Shah 2025-12-08 22:37:52 +05:30
parent 615965f3d9
commit a25448502d
2 changed files with 35 additions and 1 deletions

View File

@ -1260,6 +1260,40 @@ describe("PDF viewer", () => {
}); });
}); });
describe("File param with encoded characters (issue 20420)", () => {
let pages;
beforeEach(async () => {
const baseURL = new URL(global.integrationBaseUrl);
const url = `${baseURL.origin}/build/generic/web/compressed.tracemonkey-pldi-09.pdf?token=%2Ffoo`;
pages = await loadAndWait(
encodeURIComponent(url),
".textLayer .endOfContent"
);
});
afterEach(async () => {
await closePages(pages);
});
it("must not double-decode the file param", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
const pdfUrl = await page.evaluate(
() => window.PDFViewerApplication.url
);
expect(pdfUrl)
.withContext(`In ${browserName}`)
.toContain("token=%2Ffoo");
expect(pdfUrl)
.withContext(`In ${browserName}`)
.not.toContain("token=/foo");
})
);
});
});
describe("Keyboard scrolling on startup (bug 843653)", () => { describe("Keyboard scrolling on startup (bug 843653)", () => {
let pages; let pages;

View File

@ -789,7 +789,7 @@ const PDFViewerApplication = {
const params = parseQueryString(queryString); const params = parseQueryString(queryString);
file = params.get("file") ?? AppOptions.get("defaultUrl"); file = params.get("file") ?? AppOptions.get("defaultUrl");
try { try {
file = new URL(decodeURIComponent(file)).href; file = new URL(file).href;
} catch { } catch {
file = encodeURIComponent(file).replaceAll("%2F", "/"); file = encodeURIComponent(file).replaceAll("%2F", "/");
} }