Skip to content

Commit 2863e5c

Browse files
KarimTantaweyroot
andauthored
Merge commit from fork
Move module-level variables (text, jsNamesObj, jsJsObj) inside addJS function scope to prevent data leakage when multiple jsPDF instances call addJS() before save(). Fixes shared state vulnerability where docA.save() would contain docB's script if docB.addJS() was called after docA.addJS(). Co-authored-by: root <root@DESKTOP-PC8VOAS.localdomain>
1 parent efe54bf commit 2863e5c

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/modules/javascript.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,19 @@ import { jsPDF } from "../jspdf.js";
3434
*/
3535
(function(jsPDFAPI) {
3636
"use strict";
37-
var jsNamesObj, jsJsObj, text;
3837
/**
3938
* @name addJS
4039
* @function
4140
* @param {string} javascript The javascript to be embedded into the PDF-file.
4241
* @returns {jsPDF}
4342
*/
4443
jsPDFAPI.addJS = function(javascript) {
45-
text = javascript;
44+
// FIX: Move variables inside function scope to prevent shared state
45+
// between multiple jsPDF instances
46+
var jsNamesObj;
47+
var jsJsObj;
48+
var text = javascript;
49+
4650
this.internal.events.subscribe("postPutResources", function() {
4751
jsNamesObj = this.internal.newObject();
4852
this.internal.out("<<");

0 commit comments

Comments
 (0)