Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invert localUrlAccess to fix https://www.npmjs.com/advisories/1095 #623

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function PDF (html, options) {
if (!this.options.phantomPath) this.options.phantomPath = phantomjs && phantomjs.path
this.options.phantomArgs = this.options.phantomArgs || []

if (this.options.localUrlAccess) this.options.phantomArgs.push('--local-url-access=false')
if (!this.options.localUrlAccess) this.options.phantomArgs.push('--local-url-access=false')
assert(this.options.phantomPath, "html-pdf: Failed to load PhantomJS module. You have to set the path to the PhantomJS binary using 'options.phantomPath'")
assert(typeof this.html === 'string' && this.html.length, "html-pdf: Can't create a pdf without an html string")
this.options.timeout = parseInt(this.options.timeout, 10) || 30000
Expand Down
8 changes: 4 additions & 4 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,29 +229,29 @@ test('load with cookies js', function (t) {
})
})

test('allows local file access with localUrlAccess=true', function (t) {
test('does not allow localUrlAccess by default', function (t) {
t.plan(2)

pdf.create(`
<body>here is an iframe which receives the cookies
<iframe src="file://${path.join(__dirname, 'multiple-pages.html')}" width="400" height="100"></iframe>
</body>
`, {localUrlAccess: true})
`)
.toBuffer(function (error, buffer) {
t.error(error)
const count = buffer.toString().match(/\/Type \/Page\n/g).length
t.assert(count === 1, 'Renders a page with 1 page as the content is missing')
})
})

test('does not allow localUrlAccess by default', function (t) {
test('allows local file access with localUrlAccess=true', function (t) {
t.plan(2)

pdf.create(`
<body>here is an iframe which receives the cookies
<iframe src="file://${path.join(__dirname, 'multiple-pages.html')}" width="400" height="100"></iframe>
</body>
`)
`, {localUrlAccess: true})
.toBuffer(function (error, buffer) {
t.error(error)
const count = buffer.toString().match(/\/Type \/Page\n/g).length
Expand Down