Skip to content

Commit d00d8d8

Browse files
authored
Inline finding images on reports (#10738)
* reports-inline-images Inline finding images (in findings and endpoint listings) on custom reports * reports-inline-images change check for image mimetype
1 parent 0eb6652 commit d00d8d8

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

dojo/templates/dojo/custom_html_report_endpoint_list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ <h6>References</h6>
151151
<pre>{{ finding.references|markdown_render }}</pre>
152152
{% endif %}
153153
{% if include_finding_images %}
154-
{% include "dojo/snippets/file_images.html" with size='original' obj=finding format="HTML" %}
154+
{% include "dojo/snippets/file_images.html" with size='original' obj=finding format="INLINE" %}
155155
{% endif %}
156156
{% if include_finding_notes %}
157157
{% with notes=finding.notes.all|get_public_notes %}

dojo/templates/dojo/custom_html_report_finding_list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ <h6>References</h6>
154154
{% endif %}
155155

156156
{% if include_finding_images %}
157-
{% include "dojo/snippets/file_images.html" with size='original' obj=finding format="HTML" %}
157+
{% include "dojo/snippets/file_images.html" with size='original' obj=finding format="INLINE" %}
158158
{% endif %}
159159
{% if include_finding_notes %}
160160
{% with notes=finding.notes.all|get_public_notes %}

dojo/templates/dojo/snippets/file_images.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ <h6>Images</h6>
99
<p class="text-center">No images found.</p>
1010
{% endfor %}
1111
{% endwith %}
12+
{% elif format == "INLINE" %}
13+
{% with images=obj|file_images %}
14+
<h6>Images</h6>
15+
{% for pic in images %}
16+
<p><img src="{{ pic|inline_image }}" style="max-width: 85%" alt="Finding Image"></p>
17+
{% empty %}
18+
<p class="text-center">No images found.</p>
19+
{% endfor %}
20+
{% endwith %}
1221
{% else %}
1322
{% with images=obj|file_images %}
1423
{% for pic in images %}

dojo/templatetags/display_tags.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import base64
12
import datetime
23
import logging
4+
import mimetypes
35
from itertools import chain
46

57
import bleach
@@ -420,6 +422,18 @@ def pic_token(context, image, size):
420422
return reverse("download_finding_pic", args=[token.token])
421423

422424

425+
@register.filter
426+
def inline_image(image_file):
427+
try:
428+
if img_type := mimetypes.guess_type(image_file.file.name)[0]:
429+
if img_type.startswith("image/"):
430+
img_data = base64.b64encode(image_file.file.read())
431+
return f"data:{img_type};base64, {img_data.decode('utf-8')}"
432+
except:
433+
pass
434+
return ""
435+
436+
423437
@register.filter
424438
def file_images(obj):
425439
return get_file_images(obj, return_objects=True)

0 commit comments

Comments
 (0)