Skip to content

Monolog dependency fixed to lastest and Export to word Document fixed#215

Open
asuquoe62-star wants to merge 3 commits into
unstablefrom
PHP-7-Upgrade
Open

Monolog dependency fixed to lastest and Export to word Document fixed#215
asuquoe62-star wants to merge 3 commits into
unstablefrom
PHP-7-Upgrade

Conversation

@asuquoe62-star
Copy link
Copy Markdown

No description provided.

Comment thread docker/dev/Dockerfile
apache2 \
curl \
mysql-client \
pandoc \
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love pandoc and I support this! But please add it to the main Dockerfile (in the repo root) if it is not already there too.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, @asuquoe62-star Can you add this to the commit? If not we can sync up on it or I can add it.

Comment thread htdocs/export/export_word.php Outdated
Comment thread htdocs/export/word_export_lib.php Outdated

function blis_word_export_docx($html_fragment, $file_prefix)
{
$pandoc_bin = trim((string)shell_exec('command -v pandoc'));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So - important note, but this won't work on Windows.

I'm not going to block the PR on this, since this happens elsewhere in the codebase too. But we definitely could have it work on Windows if we also shipped Pandoc in the runtime.

$tmp_docx_base = tempnam(sys_get_temp_dir(), 'blis_word_docx_');
if($tmp_html === false || $tmp_docx_base === false)
{
return false;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case (and probably all the other failure cases) you should be logging an error with the logger.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we return early here because tempnam failed for the second file, we might leave the first temporary file ($tmp_html) orphaned in the system's temp directory. We should ensure @Unlink($tmp_html) is called or consolidate the cleanup logic to prevent local storage bloat over time.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's good file hygiene, but it's not actually necessary. On Linux systems, and I assume macOS, /tmp is a tmpfs mount meaning that all of its files are stored in memory. When it's unmounted, the files disappear.

mitchell@kingsley:~$ mount | grep '/tmp'
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,seclabel,nr_inodes=1048576,inode64,usrquota)

The Windows temp dir does NOT do this as far as I know, so deleting files on that platform makes sense. However there is a cleanup utility that can run periodically on Windows that would clean these up.

Co-authored-by: Mitchell Rysavy <mitchell.rysavy@gmail.com>
}

# Some callers still pass slashed payloads.
$normalized = stripcslashes($html_fragment);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since stripcslashes is being used on raw $_REQUEST data that is eventually echoed back in the blis_word_send_legacy_doc fallback, we should be careful about XSS. If Pandoc isn't available, we are essentially rendering unsanitized HTML. It might be worth adding a step to strip <script> tags or sensitive event handlers here to secure the legacy export path. Somewhat of a fallback

header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
header('Content-Disposition: attachment; filename="'.$file_name.'"');
header('Content-Length: '.filesize($tmp_docx));
readfile($tmp_docx);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good idea to call ob_end_clean() here before readfile(). If any PHP notices or stray whitespace were echoed earlier in the execution, they could prepend the file stream and corrupt the resulting .docx file structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants