Skip to content

Commit 9b47699

Browse files
jira: truncate description if max length exceeded (#12732)
* jira: truncate description if max length exceeded * jira: truncate description if max length exceeded * jira: truncate description if max length exceeded * make extra room * adjust to 2^15-1
1 parent fef9339 commit 9b47699

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

dojo/jira_link/helper.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from dojo.utils import (
3838
add_error_message_to_response,
3939
get_file_images,
40+
get_full_url,
4041
get_system_setting,
4142
prod_name,
4243
to_str_typed,
@@ -646,6 +647,12 @@ def jira_description(obj, **kwargs):
646647
kwargs["finding_group"] = obj
647648

648649
description = render_to_string(template, kwargs)
650+
defect_dojo_obj_url = get_full_url(obj.get_absolute_url())
651+
max_length = getattr(settings, "JIRA_DESCRIPTION_MAX_LENGTH", 32767)
652+
suffix = f"\n\nIssue Description Too Long: See [DefectDojo|{defect_dojo_obj_url}] for full description."
653+
if len(description) > max_length:
654+
# suffix can be longer after rendering do to urlenocoding, so we take twice the length of the suffix as a buffer
655+
description = description[:max_length - (2 * len(suffix))] + suffix
649656
logger.debug("rendered description: %s", description)
650657
return description
651658

dojo/settings/settings.dist.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@
226226
DD_MAX_REQRESP_FROM_API=(int, -1),
227227
DD_MAX_AUTOCOMPLETE_WORDS=(int, 20000),
228228
DD_JIRA_SSL_VERIFY=(bool, True),
229+
DD_JIRA_DESCRIPTION_MAX_LENGTH=(int, 32767),
229230
# When interacting with jira tickets that attached finding groups, we should no be opening any findings
230231
# on the DefectDojo side because jira has no way of knowing if a finding really should be reopened or not
231232
DD_JIRA_WEBHOOK_ALLOW_FINDING_GROUP_REOPEN=(bool, False),
@@ -1643,6 +1644,7 @@ def saml2_attrib_map_format(din):
16431644
JIRA_ISSUE_TYPE_CHOICES_CONFIG += ((extra_type, extra_type),)
16441645

16451646
JIRA_SSL_VERIFY = env("DD_JIRA_SSL_VERIFY")
1647+
JIRA_DESCRIPTION_MAX_LENGTH = env("DD_JIRA_DESCRIPTION_MAX_LENGTH")
16461648
JIRA_WEBHOOK_ALLOW_FINDING_GROUP_REOPEN = env("DD_JIRA_WEBHOOK_ALLOW_FINDING_GROUP_REOPEN")
16471649

16481650
# ------------------------------------------------------------------------------

0 commit comments

Comments
 (0)