Bug 1675965, do not store file name in preference value for save to pdf printers r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D113413
This commit is contained in:
Emma Malysz 2021-04-29 17:42:54 +00:00
parent 16727033d9
commit d2b69538dd
3 changed files with 22 additions and 1 deletions

View File

@ -840,7 +840,9 @@ nsresult nsPrintJob::Print(Document* aSourceDoc,
nsCOMPtr<nsIPrintSettingsService> printSettingsService =
do_GetService("@mozilla.org/gfx/printsettings-service;1");
printSettingsService->SavePrintSettingsToPrefs(
aPrintSettings, true, nsIPrintSettings::kInitSaveAll);
aPrintSettings, true,
nsIPrintSettings::kInitSaveAll &
~nsIPrintSettings::kInitSaveToFileName);
printSettingsService->SavePrintSettingsToPrefs(
aPrintSettings, false, nsIPrintSettings::kInitSavePrinterName);
}

View File

@ -423,6 +423,16 @@ var PrintEventHandler = {
Cu.reportError(e);
}
if (settings.printerName == PrintUtils.SAVE_TO_PDF_PRINTER) {
// Clear the file name from the preference value since it may potentially
// contain sensitive information from the page title (Bug 1675965)
let prefName =
"print.printer_" +
settings.printerName.replace(/ /g, "_") +
".print_to_filename";
Services.prefs.clearUserPref(prefName);
}
window.close();
return true;
},

View File

@ -110,6 +110,15 @@ add_task(async function testPDFFile() {
EventUtils.sendKey("return", helper.win);
});
try {
Services.prefs.getStringPref(
"print.printer_Mozilla_Save_to_PDF.print_to_filename"
);
ok(false, "Should have cleared the filename pref");
} catch (ex) {
ok(true, "Cleared the filename pref");
}
is(await IOUtils.exists(filePath), true, "Saved pdf file exists");
ok(await IOUtils.read(filePath), "Saved pdf file is not empty");
});