@patrickdk77/script-defuse 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/plugins.js +6 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,6 +35,8 @@ const result = await disarmPdf(bytes, { scriptPlugins: [formScriptPlugin()] });
|
|
|
35
35
|
|
|
36
36
|
pdf-defuse removes every script unless a plugin keeps it. This plugin keeps the form scripts and removes the rest. From pdf-defuse 0.2.4 the plugin's findings go into the PDF's report at each script's location.
|
|
37
37
|
|
|
38
|
+
The plugin's answer is final, and its findings are what the script scores. Each finding's `weight` is what it adds to that script's score from `inspectScript`: a finding that strips weighs what `scoreWeights` or the table gives it, and one that only describes the script weighs 0. A form script the plugin keeps therefore adds nothing to the PDF's score from pdf-defuse 0.3.0 and office-defuse 0.3.0. Earlier versions scored a kept script at their own weight for it.
|
|
39
|
+
|
|
38
40
|
Make one plugin per PDF. pdf-defuse hands it the document-level scripts first, and the plugin remembers the globals of the ones it kept, so a field script may call a helper they define. A field script that calls a helper from a document script the plugin removed is removed too.
|
|
39
41
|
|
|
40
42
|
With [file-defuse](https://github.com/patrickdk77/file-defuse) 0.1.4 or later, every PDF and Office file already gets one.
|
package/dist/plugins.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.formScriptPlugin = formScriptPlugin;
|
|
4
4
|
const engine_1 = require("./engine");
|
|
5
|
+
const score_1 = require("./score");
|
|
5
6
|
/**
|
|
6
7
|
* A plugin that keeps a script only when inspectScript calls it a form script, and removes every other one.
|
|
7
8
|
*
|
|
@@ -22,8 +23,11 @@ function formScriptPlugin(options = {}) {
|
|
|
22
23
|
if (result === 'passed')
|
|
23
24
|
for (const name of r.definedGlobals)
|
|
24
25
|
known.add(name);
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
// The container scores the script by these weights alone, so they are the ones this script's score counted:
|
|
27
|
+
// a finding that strips, at the caller's weight, and nothing for one that only describes the script.
|
|
28
|
+
const findings = r.findings.map(f => ({ ...f, weight: f.action === 'strip' ? (0, score_1.weightOf)(f, options) : 0 }));
|
|
29
|
+
decisions.push({ script, result, findings });
|
|
30
|
+
return { result, findings };
|
|
27
31
|
},
|
|
28
32
|
};
|
|
29
33
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patrickdk77/script-defuse",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Inspect document scripts: PDF form scripts in JavaScript and FormCalc, from AcroForm and XFA forms, and the VBA modules of Office documents. Keeps a form script only when every call and property it uses formats, checks or calculates form fields, and a macro only when it calls nothing that reaches outside its document. Reports external access, dynamic code and obfuscation. Includes a script plugin for pdf-defuse and office-defuse.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "patrickdk77",
|