Merge pull request #20482 from Uzair-Ahmed-Shah/fix-issue-20420

Fix #20420: Prevent double decoding of file URL parameter
This commit is contained in:
Tim van der Meij 2025-12-13 14:22:47 +01:00 committed by GitHub
commit 8b4fae0a84
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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)", () => {
let pages;

View File

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