GhostManager / Ghostwriter

The SpecterOps project management and reporting engine
https://ghostwriter.wiki
BSD 3-Clause "New" or "Revised" License
1.37k stars 184 forks source link

Template rendering failed unexpectedly #486

Closed cmitcho closed 3 months ago

cmitcho commented 4 months ago

Describe the bug

There seems to be a bug with linting a docx report. When Creating a report template, and submitting, we see the expected warning: Template is missing a recommended style (see documentation): CodeInline As well as an error below: Template rendering failed unexpectedly

Looking at the logs, we see the following:

INFO 2024-07-23 23:21:43,756 signals 18 137756409506616 Deleted old template file /app/ghostwriter/media/templates/v5.1-ghostwriter-executive-document_OTcPzou.docx
INFO 2024-07-23 23:21:43,756 signals 18 137756409506616 Template file change detected, so starting linter
INFO 2024-07-23 23:21:43,757 signals 18 137756409506616 Linting newly uploaded template: /app/ghostwriter/media/templates/v5.1-ghostwriter-executive-document_QUbTZfD.docx
INFO 2024-07-23 23:21:43,757 docx 18 137756409506616 Linting docx file '/app/ghostwriter/media/templates/v5.1-ghostwriter-executive-document_QUbTZfD.docx'
INFO 2024-07-23 23:21:43,807 docx 18 137756409506616 Template loaded for linting
ERROR 2024-07-23 23:21:44,136 docx 18 137756409506616 Template failed linting
Traceback (most recent call last):
  File "/app/ghostwriter/modules/reportwriter/base/docx.py", line 282, in lint
    if document_styles[style].type != WD_STYLE_TYPE.CHARACTER:
  File "/usr/local/lib/python3.10/site-packages/docx/styles/styles.py", line 53, in __getitem__
    raise KeyError("no style with name '%s'" % key)
KeyError: "no style with name 'CodeInline'"
INFO 2024-07-23 23:21:44,137 docx 18 137756409506616 Linting finished: 1 warnings, 1 errors
INFO:     172.24.0.4:59414 - "POST /reporting/templates/update/16 HTTP/1.0" 302 Found
INFO:     172.24.0.4:59424 - "GET /reporting/templates/16 HTTP/1.0" 200 OK

I was able to track down the code within file ./ghostwriter/modules/reportwriter/base/docx.py.

Running a git reset before the commit, rebuilding images, and spinning up the containers, the report is able to be created.

git reset --hard 736635087cf5675f1f2bcba5a3447b03691944cb

To Reproduce Steps to reproduce the behavior:

  1. Create a Report Template without any Styles.
  2. Submit to Ghostwriter within Report Template Library > Upload A Report Template
  3. Notice the Warning and the Failure.

Expected Behavior

Screenshots Bah, didn't get this since I have already rolled back. If unable to reproduce issue, let me know and I'll update and grab this for you.

Server Specs:

Linux ip-10-0-0-214 6.5.0-1023-aws #23~22.04.1-Ubuntu SMP Fri Jun 21 19:23:45 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.3 LTS"
PRETTY_NAME="Ubuntu 22.04.3 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.3 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
Docker version 24.0.6, build ed223bc
docker-compose version 1.29.2, build 5becea4c

Additional context Looks like template style is throwing a traceback rather than handling the error as a warning. I assume the correct path forward is to catch this error and report a warning, allowing the linting to continue.

chrismaddalena commented 3 months ago

Thanks for letting me know. It's a simple fix that will go out in the next release. For now, you will be able to use the template if the style is defined in the template.