@patrickdk77/office-defuse 0.1.1 → 0.2.1
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 +211 -43
- package/dist/cfb-writer.d.ts +25 -0
- package/dist/cfb-writer.js +314 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +357 -0
- package/dist/contained.d.ts +46 -0
- package/dist/contained.js +152 -0
- package/dist/context.d.ts +107 -12
- package/dist/context.js +101 -24
- package/dist/detect.d.ts +13 -0
- package/dist/detect.js +83 -0
- package/dist/engine.d.ts +66 -1
- package/dist/engine.js +290 -35
- package/dist/errors.d.ts +17 -0
- package/dist/errors.js +27 -1
- package/dist/fields.d.ts +20 -13
- package/dist/fields.js +65 -23
- package/dist/findings.d.ts +2 -1
- package/dist/findings.js +17 -1
- package/dist/flat.d.ts +33 -0
- package/dist/flat.js +555 -0
- package/dist/formats.d.ts +9 -0
- package/dist/formats.js +7 -1
- package/dist/formulas.d.ts +27 -0
- package/dist/formulas.js +157 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +11 -1
- package/dist/index.mjs +1 -1
- package/dist/io.d.ts +62 -1
- package/dist/io.js +245 -1
- package/dist/links.d.ts +27 -0
- package/dist/links.js +106 -1
- package/dist/msg.d.ts +3 -2
- package/dist/msg.js +172 -18
- package/dist/objects.d.ts +8 -5
- package/dist/objects.js +90 -20
- package/dist/odf.d.ts +87 -1
- package/dist/odf.js +204 -76
- package/dist/offcrypto.d.ts +24 -1
- package/dist/offcrypto.js +308 -69
- package/dist/ole.d.ts +19 -2
- package/dist/ole.js +98 -58
- package/dist/oleobj.d.ts +11 -0
- package/dist/oleobj.js +20 -3
- package/dist/ooxml.d.ts +108 -2
- package/dist/ooxml.js +392 -109
- package/dist/package.d.ts +14 -0
- package/dist/package.js +23 -7
- package/dist/plan.d.ts +104 -0
- package/dist/plan.js +73 -0
- package/dist/plugins.d.ts +8 -0
- package/dist/plugins.js +35 -0
- package/dist/ppt.js +45 -5
- package/dist/rewrite-cfb.d.ts +14 -0
- package/dist/rewrite-cfb.js +52 -0
- package/dist/rewrite-rtf.d.ts +9 -0
- package/dist/rewrite-rtf.js +45 -0
- package/dist/rewrite-xml.d.ts +36 -0
- package/dist/rewrite-xml.js +341 -0
- package/dist/rewrite-zip.d.ts +8 -0
- package/dist/rewrite-zip.js +498 -0
- package/dist/rtf.js +216 -42
- package/dist/rtfcomp.d.ts +7 -0
- package/dist/rtfcomp.js +80 -0
- package/dist/score.js +1 -1
- package/dist/sniff.d.ts +5 -0
- package/dist/sniff.js +38 -0
- package/dist/types.d.ts +66 -6
- package/dist/types.js +14 -0
- package/dist/vsd.d.ts +13 -0
- package/dist/vsd.js +689 -0
- package/dist/word.d.ts +4 -4
- package/dist/word.js +70 -23
- package/dist/xls.d.ts +10 -4
- package/dist/xls.js +58 -10
- package/dist/xml.d.ts +30 -0
- package/dist/xml.js +45 -23
- package/dist/zip-writer.d.ts +4 -0
- package/dist/zip-writer.js +20 -7
- package/dist/zip.d.ts +11 -2
- package/dist/zip.js +67 -6
- package/package.json +4 -1
package/dist/types.d.ts
CHANGED
|
@@ -13,7 +13,8 @@ export declare enum OfficeCategory {
|
|
|
13
13
|
External = "EXTERNAL",
|
|
14
14
|
Link = "LINK",
|
|
15
15
|
Embedded = "EMBEDDED",
|
|
16
|
-
Control = "CONTROL"
|
|
16
|
+
Control = "CONTROL",
|
|
17
|
+
Processing = "PROCESSING"
|
|
17
18
|
}
|
|
18
19
|
/** Exact variant of a finding. Some details appear under more than one category. */
|
|
19
20
|
export declare enum OfficeDetail {
|
|
@@ -34,6 +35,7 @@ export declare enum OfficeDetail {
|
|
|
34
35
|
DataError = "DATA_ERROR",
|
|
35
36
|
LeadingBytes = "LEADING_BYTES",
|
|
36
37
|
HiddenData = "HIDDEN_DATA",
|
|
38
|
+
HiddenEntry = "HIDDEN_ENTRY",
|
|
37
39
|
TrailingBytes = "TRAILING_BYTES",
|
|
38
40
|
BadHeader = "BAD_HEADER",
|
|
39
41
|
BrokenChain = "BROKEN_CHAIN",
|
|
@@ -55,10 +57,12 @@ export declare enum OfficeDetail {
|
|
|
55
57
|
XmlEntityExpansions = "XML_ENTITY_EXPANSIONS",
|
|
56
58
|
XmlEntitySize = "XML_ENTITY_SIZE",
|
|
57
59
|
RtfDepth = "RTF_DEPTH",
|
|
60
|
+
NestingDepth = "NESTING_DEPTH",
|
|
58
61
|
Time = "TIME",
|
|
59
62
|
Unrecognized = "UNRECOGNIZED",
|
|
60
63
|
AmbiguousFormat = "AMBIGUOUS_FORMAT",
|
|
61
64
|
Unreadable = "UNREADABLE",
|
|
65
|
+
UnreadableBody = "UNREADABLE_BODY",
|
|
62
66
|
DuplicateEntry = "DUPLICATE_ENTRY",
|
|
63
67
|
UntypedPart = "UNTYPED_PART",
|
|
64
68
|
UnreferencedPart = "UNREFERENCED_PART",
|
|
@@ -73,6 +77,7 @@ export declare enum OfficeDetail {
|
|
|
73
77
|
Aes192 = "AES_192",
|
|
74
78
|
Aes256 = "AES_256",
|
|
75
79
|
UnsupportedAlgorithm = "UNSUPPORTED_ALGORITHM",
|
|
80
|
+
XorObfuscation = "XOR_OBFUSCATION",
|
|
76
81
|
VbaProject = "VBA_PROJECT",
|
|
77
82
|
XlmMacrosheet = "XLM_MACROSHEET",
|
|
78
83
|
WordBasic = "WORDBASIC",
|
|
@@ -86,6 +91,7 @@ export declare enum OfficeDetail {
|
|
|
86
91
|
Callback = "CALLBACK",
|
|
87
92
|
OdfConfiguration = "ODF_CONFIGURATION",
|
|
88
93
|
RunProgram = "RUN_PROGRAM",
|
|
94
|
+
SubmitForm = "SUBMIT_FORM",
|
|
89
95
|
OleVerb = "OLE_VERB",
|
|
90
96
|
ObjectUpdate = "OBJECT_UPDATE",
|
|
91
97
|
Field = "FIELD",
|
|
@@ -100,6 +106,7 @@ export declare enum OfficeDetail {
|
|
|
100
106
|
Workbook = "WORKBOOK",
|
|
101
107
|
Reload = "RELOAD",
|
|
102
108
|
Other = "OTHER",
|
|
109
|
+
DataConnection = "DATA_CONNECTION",
|
|
103
110
|
LocalFile = "LOCAL_FILE",
|
|
104
111
|
Safe = "SAFE",
|
|
105
112
|
FileUrl = "FILE_URL",
|
|
@@ -112,6 +119,7 @@ export declare enum OfficeDetail {
|
|
|
112
119
|
LookalikeHost = "LOOKALIKE_HOST",
|
|
113
120
|
EncodedHost = "ENCODED_HOST",
|
|
114
121
|
Relative = "RELATIVE",
|
|
122
|
+
TextMismatch = "TEXT_MISMATCH",
|
|
115
123
|
OleObject = "OLE_OBJECT",
|
|
116
124
|
Package = "PACKAGE",
|
|
117
125
|
OleFile = "OLE_FILE",
|
|
@@ -119,7 +127,12 @@ export declare enum OfficeDetail {
|
|
|
119
127
|
Plugin = "PLUGIN",
|
|
120
128
|
Equation = "EQUATION",
|
|
121
129
|
Attachment = "ATTACHMENT",
|
|
122
|
-
|
|
130
|
+
PluginPassed = "PLUGIN_PASSED",
|
|
131
|
+
PluginScrubbed = "PLUGIN_SCRUBBED",
|
|
132
|
+
PluginFailed = "PLUGIN_FAILED",
|
|
133
|
+
PluginRemoved = "PLUGIN_REMOVED",
|
|
134
|
+
ActiveX = "ACTIVEX",
|
|
135
|
+
VerificationFailed = "VERIFICATION_FAILED"
|
|
123
136
|
}
|
|
124
137
|
export type OfficeFindingAction = 'reject' | 'strip' | 'info';
|
|
125
138
|
/**
|
|
@@ -170,6 +183,15 @@ export interface OfficeInspection {
|
|
|
170
183
|
/** The MIME type of a file in that format. '' when not recognized. */
|
|
171
184
|
mimeType: string;
|
|
172
185
|
}
|
|
186
|
+
export interface OfficeDisarmResult {
|
|
187
|
+
status: 'clean' | 'defused' | 'rejected';
|
|
188
|
+
/** The uploaded file and its score. */
|
|
189
|
+
before: OfficeInspection;
|
|
190
|
+
/** The output and its remaining score. Absent when rejected. */
|
|
191
|
+
after?: OfficeInspection;
|
|
192
|
+
/** Findings whose content was removed. */
|
|
193
|
+
removed: DefuseFinding[];
|
|
194
|
+
}
|
|
173
195
|
/** Random-access input. A buffer, a local file and an S3 ranged GetObject all fit. */
|
|
174
196
|
export interface ByteSource {
|
|
175
197
|
size(): Promise<number>;
|
|
@@ -204,9 +226,37 @@ export interface OfficeLimits {
|
|
|
204
226
|
xmlEntitySize?: number;
|
|
205
227
|
/** Group nesting in an RTF file, and destinations open at once. Default 256. */
|
|
206
228
|
rtfDepth?: number;
|
|
229
|
+
/**
|
|
230
|
+
* The deepest a file may sit in the upload. The upload is at depth 0 and a file inside it at 1, and files of every
|
|
231
|
+
* format in between count. Not enforced unless set.
|
|
232
|
+
*/
|
|
233
|
+
nestingDepth?: number;
|
|
207
234
|
/** Milliseconds for the whole run. Not enforced unless set. */
|
|
208
235
|
timeMs?: number;
|
|
209
236
|
}
|
|
237
|
+
export interface FormatDetection {
|
|
238
|
+
/** The format's MIME type, such as application/vnd.openxmlformats-officedocument.wordprocessingml.document. */
|
|
239
|
+
mimeType: string;
|
|
240
|
+
/** The format's usual extension, lowercase and without the dot. */
|
|
241
|
+
extension: string;
|
|
242
|
+
/** Where the format starts in the file: 0, or the offset of its data when other data comes first. */
|
|
243
|
+
offset: number;
|
|
244
|
+
/** Set when the match rests on more than the content, and says what it rests on. */
|
|
245
|
+
heuristic?: string;
|
|
246
|
+
}
|
|
247
|
+
/** What a detect function may know of a file besides its content. */
|
|
248
|
+
export interface DetectOptions {
|
|
249
|
+
/** The file's name, as the upload or the container that holds it gives it. */
|
|
250
|
+
name?: string;
|
|
251
|
+
/** The MIME type the upload or the container declares. */
|
|
252
|
+
declaredType?: string;
|
|
253
|
+
/** The Date.now() value detection must finish by, as `PluginContext.deadline`. */
|
|
254
|
+
deadline?: number;
|
|
255
|
+
/** Folder for temporary files. Defaults to `os.tmpdir()`. */
|
|
256
|
+
tempDir?: string;
|
|
257
|
+
/** Bytes held in memory before a temporary file takes over. */
|
|
258
|
+
memoryThreshold?: number;
|
|
259
|
+
}
|
|
210
260
|
/** What a contained file plugin learns of the run, with nothing format-specific, so any package of the family can make one. */
|
|
211
261
|
export interface PluginContext {
|
|
212
262
|
/** The depth of the file itself: 0 for the upload, 1 for a file inside it, and so on, whatever the formats. */
|
|
@@ -262,13 +312,23 @@ export interface OfficeScoreBands {
|
|
|
262
312
|
}
|
|
263
313
|
export interface OfficeOptions {
|
|
264
314
|
/**
|
|
265
|
-
*
|
|
266
|
-
* the password Excel opens
|
|
267
|
-
* where other users can read
|
|
315
|
+
* One password or a list, tried in order on an encrypted file: an encrypted OOXML package, or an .xls workbook.
|
|
316
|
+
* VelvetSweatshop, the password Excel opens a workbook with by default, comes after them. Pass passwords in code,
|
|
317
|
+
* never on a command line, where other users can read them.
|
|
268
318
|
*/
|
|
269
|
-
password?: string;
|
|
319
|
+
password?: string | string[];
|
|
270
320
|
limits?: OfficeLimits;
|
|
271
321
|
actionOverrides?: OfficeActionOverride[];
|
|
272
322
|
scoreWeights?: OfficeScoreWeight[];
|
|
273
323
|
scoreBands?: OfficeScoreBands;
|
|
324
|
+
/** Plugins that decide about the files inside the file: embedded objects and packages, OLE parts and attachments. */
|
|
325
|
+
filePlugins?: ContainedFilePlugin[];
|
|
326
|
+
/** Directory for temporary files. Defaults to os.tmpdir(). */
|
|
327
|
+
tempDir?: string;
|
|
328
|
+
/**
|
|
329
|
+
* Default 8 MiB. disarmOfficeSource keeps its copy of the upload and its output in memory up to this size and in a
|
|
330
|
+
* temporary file above it. Each file inside that goes to a plugin does the same, and the copies plugins return,
|
|
331
|
+
* which wait for the output to be written, share this much memory.
|
|
332
|
+
*/
|
|
333
|
+
memoryThreshold?: number;
|
|
274
334
|
}
|
package/dist/types.js
CHANGED
|
@@ -18,6 +18,7 @@ var OfficeCategory;
|
|
|
18
18
|
OfficeCategory["Link"] = "LINK";
|
|
19
19
|
OfficeCategory["Embedded"] = "EMBEDDED";
|
|
20
20
|
OfficeCategory["Control"] = "CONTROL";
|
|
21
|
+
OfficeCategory["Processing"] = "PROCESSING";
|
|
21
22
|
})(OfficeCategory || (exports.OfficeCategory = OfficeCategory = {}));
|
|
22
23
|
/** Exact variant of a finding. Some details appear under more than one category. */
|
|
23
24
|
var OfficeDetail;
|
|
@@ -40,6 +41,7 @@ var OfficeDetail;
|
|
|
40
41
|
OfficeDetail["DataError"] = "DATA_ERROR";
|
|
41
42
|
OfficeDetail["LeadingBytes"] = "LEADING_BYTES";
|
|
42
43
|
OfficeDetail["HiddenData"] = "HIDDEN_DATA";
|
|
44
|
+
OfficeDetail["HiddenEntry"] = "HIDDEN_ENTRY";
|
|
43
45
|
OfficeDetail["TrailingBytes"] = "TRAILING_BYTES";
|
|
44
46
|
OfficeDetail["BadHeader"] = "BAD_HEADER";
|
|
45
47
|
OfficeDetail["BrokenChain"] = "BROKEN_CHAIN";
|
|
@@ -63,11 +65,13 @@ var OfficeDetail;
|
|
|
63
65
|
OfficeDetail["XmlEntityExpansions"] = "XML_ENTITY_EXPANSIONS";
|
|
64
66
|
OfficeDetail["XmlEntitySize"] = "XML_ENTITY_SIZE";
|
|
65
67
|
OfficeDetail["RtfDepth"] = "RTF_DEPTH";
|
|
68
|
+
OfficeDetail["NestingDepth"] = "NESTING_DEPTH";
|
|
66
69
|
OfficeDetail["Time"] = "TIME";
|
|
67
70
|
// PACKAGE
|
|
68
71
|
OfficeDetail["Unrecognized"] = "UNRECOGNIZED";
|
|
69
72
|
OfficeDetail["AmbiguousFormat"] = "AMBIGUOUS_FORMAT";
|
|
70
73
|
OfficeDetail["Unreadable"] = "UNREADABLE";
|
|
74
|
+
OfficeDetail["UnreadableBody"] = "UNREADABLE_BODY";
|
|
71
75
|
OfficeDetail["DuplicateEntry"] = "DUPLICATE_ENTRY";
|
|
72
76
|
OfficeDetail["UntypedPart"] = "UNTYPED_PART";
|
|
73
77
|
OfficeDetail["UnreferencedPart"] = "UNREFERENCED_PART";
|
|
@@ -83,6 +87,7 @@ var OfficeDetail;
|
|
|
83
87
|
OfficeDetail["Aes192"] = "AES_192";
|
|
84
88
|
OfficeDetail["Aes256"] = "AES_256";
|
|
85
89
|
OfficeDetail["UnsupportedAlgorithm"] = "UNSUPPORTED_ALGORITHM";
|
|
90
|
+
OfficeDetail["XorObfuscation"] = "XOR_OBFUSCATION";
|
|
86
91
|
// MACRO
|
|
87
92
|
OfficeDetail["VbaProject"] = "VBA_PROJECT";
|
|
88
93
|
OfficeDetail["XlmMacrosheet"] = "XLM_MACROSHEET";
|
|
@@ -99,6 +104,7 @@ var OfficeDetail;
|
|
|
99
104
|
OfficeDetail["OdfConfiguration"] = "ODF_CONFIGURATION";
|
|
100
105
|
// ACTION
|
|
101
106
|
OfficeDetail["RunProgram"] = "RUN_PROGRAM";
|
|
107
|
+
OfficeDetail["SubmitForm"] = "SUBMIT_FORM";
|
|
102
108
|
OfficeDetail["OleVerb"] = "OLE_VERB";
|
|
103
109
|
OfficeDetail["ObjectUpdate"] = "OBJECT_UPDATE";
|
|
104
110
|
// DDE
|
|
@@ -116,6 +122,7 @@ var OfficeDetail;
|
|
|
116
122
|
OfficeDetail["Workbook"] = "WORKBOOK";
|
|
117
123
|
OfficeDetail["Reload"] = "RELOAD";
|
|
118
124
|
OfficeDetail["Other"] = "OTHER";
|
|
125
|
+
OfficeDetail["DataConnection"] = "DATA_CONNECTION";
|
|
119
126
|
OfficeDetail["LocalFile"] = "LOCAL_FILE";
|
|
120
127
|
// LINK
|
|
121
128
|
OfficeDetail["Safe"] = "SAFE";
|
|
@@ -129,6 +136,7 @@ var OfficeDetail;
|
|
|
129
136
|
OfficeDetail["LookalikeHost"] = "LOOKALIKE_HOST";
|
|
130
137
|
OfficeDetail["EncodedHost"] = "ENCODED_HOST";
|
|
131
138
|
OfficeDetail["Relative"] = "RELATIVE";
|
|
139
|
+
OfficeDetail["TextMismatch"] = "TEXT_MISMATCH";
|
|
132
140
|
// EMBEDDED
|
|
133
141
|
OfficeDetail["OleObject"] = "OLE_OBJECT";
|
|
134
142
|
OfficeDetail["Package"] = "PACKAGE";
|
|
@@ -137,8 +145,14 @@ var OfficeDetail;
|
|
|
137
145
|
OfficeDetail["Plugin"] = "PLUGIN";
|
|
138
146
|
OfficeDetail["Equation"] = "EQUATION";
|
|
139
147
|
OfficeDetail["Attachment"] = "ATTACHMENT";
|
|
148
|
+
OfficeDetail["PluginPassed"] = "PLUGIN_PASSED";
|
|
149
|
+
OfficeDetail["PluginScrubbed"] = "PLUGIN_SCRUBBED";
|
|
150
|
+
OfficeDetail["PluginFailed"] = "PLUGIN_FAILED";
|
|
151
|
+
OfficeDetail["PluginRemoved"] = "PLUGIN_REMOVED";
|
|
140
152
|
// CONTROL
|
|
141
153
|
OfficeDetail["ActiveX"] = "ACTIVEX";
|
|
154
|
+
// PROCESSING
|
|
155
|
+
OfficeDetail["VerificationFailed"] = "VERIFICATION_FAILED";
|
|
142
156
|
})(OfficeDetail || (exports.OfficeDetail = OfficeDetail = {}));
|
|
143
157
|
var OfficeRisk;
|
|
144
158
|
(function (OfficeRisk) {
|
package/dist/vsd.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CfbEntry, CompoundFile } from './cfb';
|
|
2
|
+
import { type RunContext } from './context';
|
|
3
|
+
/**
|
|
4
|
+
* Reads the ShapeSheet cells of a Visio 2000 to 2010 drawing for formulas that call RUNADDON, RUNADDONWARGS,
|
|
5
|
+
* CALLTHIS, RUNMACRO, OPENFILE or DOOLEVERB. Other versions of the stream go unread. A stream whose structure does
|
|
6
|
+
* not read stops the run as PACKAGE/UNREADABLE.
|
|
7
|
+
*/
|
|
8
|
+
export declare function visioRules(ctx: RunContext, cfb: CompoundFile, stream: CfbEntry): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* The LZ77 compression of Visio streams (VSDInternalStream.cpp): a flag byte for each eight items, a set bit for a
|
|
11
|
+
* literal byte and a clear one for a 2-byte back reference into a 4,096-byte window. Output past `limit` stops the run.
|
|
12
|
+
*/
|
|
13
|
+
export declare function inflate(src: Uint8Array, limit: number): Uint8Array;
|