Skip to content

Commit c54aaeb

Browse files
committed
Disable external file access by default
1 parent c6f5169 commit c54aaeb

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

NEWS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
* Ignore style definitions using a style ID that has already been used.
44

5-
* Support disabling external file accesses using the externalFileAccess option.
5+
* Disable external file accesses by default. External file access can be enabled
6+
using the externalFileAccess option.
67

78
* Handle numbering levels defined without an index.
89

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,9 @@ Converts the source document to HTML.
377377
set `options.includeDefaultStyleMap` to `false`.
378378

379379
* `externalFileAccess`: Source documents may reference files outside of the source document.
380-
To disable access to any such external files during the conversion process,
381-
set `options.externalFileAccess` to `false`.
382-
This is highly recommended when converting untrusted user input.
380+
Access to any such external files is disabled by default.
381+
To enable access when converting trusted source documents,
382+
set `options.externalFileAccess` to `true`.
383383

384384
* `convertImage`: by default, images are converted to `<img>` elements with the source included inline in the `src` attribute.
385385
Set this option to an [image converter](#image-converters) to override the default behaviour.
@@ -541,8 +541,9 @@ For instance:
541541
and embed the HTML into your website,
542542
this may allow arbitrary files on the server to be read and exfiltrated.
543543

544-
To disable access to any such external files during the conversion process,
545-
set `options.externalFileAccess` to `false`.
544+
To avoid this issue, access to any such external files is disabled by default.
545+
To enable access when converting trusted source documents,
546+
set `options.externalFileAccess` to `true`.
546547

547548
### Document transforms
548549

lib/options-reader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ var defaultStyleMap = exports._defaultStyleMap = [
6363
];
6464

6565
var standardOptions = exports._standardOptions = {
66-
externalFileAccess: true,
66+
externalFileAccess: false,
6767
transformDocument: identity,
6868
includeDefaultStyleMap: true,
6969
includeEmbeddedStyleMap: true

test/mammoth.tests.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,27 +309,27 @@ test('src of inline images can be changed using readAsBuffer()', function() {
309309
});
310310
});
311311

312-
test('images stored outside of document are included in output', function() {
312+
test('when external file access is enabled then images stored outside of document are included in output', function() {
313313
var docxPath = path.join(__dirname, "test-data/external-picture.docx");
314-
return mammoth.convertToHtml({path: docxPath}).then(function(result) {
314+
return mammoth.convertToHtml({path: docxPath}, {externalFileAccess: true}).then(function(result) {
315315
assert.equal(result.value, '<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAOvgAADr4B6kKxwAAAABNJREFUKFNj/M+ADzDhlWUYqdIAQSwBE8U+X40AAAAASUVORK5CYII=" /></p>');
316316
assert.deepEqual(result.messages, []);
317317
});
318318
});
319319

320-
test('error if images stored outside of document are specified when passing file without path', function() {
320+
test('when external file access is enabled then error if images stored outside of document are specified when passing file without path', function() {
321321
var docxPath = path.join(__dirname, "test-data/external-picture.docx");
322322
var buffer = fs.readFileSync(docxPath);
323-
return mammoth.convertToHtml({buffer: buffer}).then(function(result) {
323+
return mammoth.convertToHtml({buffer: buffer}, {externalFileAccess: true}).then(function(result) {
324324
assert.equal(result.value, '');
325325
assert.equal(result.messages[0].message, "could not find external image 'tiny-picture.png', path of input document is unknown");
326326
assert.equal(result.messages[0].type, "error");
327327
});
328328
});
329329

330-
test('error if images stored outside of document are specified when external file access is disabled', function() {
330+
test('given external file access is disabled by default then error if images stored outside of document are specified', function() {
331331
var docxPath = path.join(__dirname, "test-data/external-picture.docx");
332-
return mammoth.convertToHtml({path: docxPath}, {externalFileAccess: false}).then(function(result) {
332+
return mammoth.convertToHtml({path: docxPath}).then(function(result) {
333333
assert.equal(result.value, '');
334334
assert.equal(result.messages[0].message, "could not read external image 'tiny-picture.png', external file access is disabled");
335335
assert.equal(result.messages[0].type, "error");

0 commit comments

Comments
 (0)