Skip to content
Open
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
11 changes: 8 additions & 3 deletions djangocms_versioning/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1101,9 +1101,14 @@ def publish_view(self, request, object_id):
self.message_user(request, _("Version published"))

# Redirect to published?
if conf.ON_PUBLISH_REDIRECT == "published":
if hasattr(version.content, "get_absolute_url"):
requested_redirect = requested_redirect or version.content.get_absolute_url()
if not requested_redirect and conf.ON_PUBLISH_REDIRECT == "published":
if hasattr(version.content, "get_full_url"):
full_url = version.content.get_full_url()
if full_url:
Comment on lines +1106 to +1107
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code-quality): Use named expression to simplify assignment and conditional (use-named-expression)

Suggested change
full_url = version.content.get_full_url()
if full_url:
if full_url := version.content.get_full_url():

# Can't resolve full_url, redirect directly to it
Comment on lines +1107 to +1108
Copy link
Contributor

Choose a reason for hiding this comment

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

🚨 issue (security): Redirecting directly to 'full_url' may bypass internal URL resolution.

Validating 'full_url' before redirecting can help prevent open redirect vulnerabilities. Ensure the URL is within the expected domain or document why this approach is secure.

return redirect(full_url)
elif hasattr(version.content, "get_absolute_url"):
requested_redirect = version.content.get_absolute_url()

return self._internal_redirect(requested_redirect, redirect_url)

Expand Down
4 changes: 3 additions & 1 deletion djangocms_versioning/cms_toolbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,9 @@ def _add_view_published_button(self):
if not published_version:
return

url = published_version.get_absolute_url() if hasattr(published_version, "get_absolute_url") else None
url = published_version.get_full_url() if hasattr(published_version, "get_full_url") else None
if not url and hasattr(published_version, "get_absolute_url"):
url = published_version.get_absolute_url()
Comment on lines +261 to +263
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: The fallback logic for URL resolution could be simplified.

If 'get_full_url' exists but returns a falsy value, the code falls back to 'get_absolute_url'. Confirm this is intentional, as it could hide problems with 'get_full_url' implementations.

Suggested change
url = published_version.get_full_url() if hasattr(published_version, "get_full_url") else None
if not url and hasattr(published_version, "get_absolute_url"):
url = published_version.get_absolute_url()
if hasattr(published_version, "get_full_url"):
url = published_version.get_full_url()
elif hasattr(published_version, "get_absolute_url"):
url = published_version.get_absolute_url()
else:
url = None

if url and (self.toolbar.edit_mode_active or self.toolbar.preview_mode_active):
item = ButtonList(side=self.toolbar.RIGHT)
item.add_button(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@



<form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="?language={{ language }}{% if request.GET.parent_page %}&amp;parent_page={{ request.GET.parent_page }}{% endif %}{# parameter `parent_node` only for django CMS 4.1 support #}{% if request.GET.parent_node %}&amp;parent_node={{ request.GET.parent_node }}{% endif %}{%if request.GET.source %}&amp;source={{ request.GET.source }}{% endif %}" method="post" id="{{ opts.model_name }}_form">
<form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="?language={{ language }}{% if request.GET.site %}&amp;site={{ request.GET.site }}{% endif %}{% if request.GET.parent_page %}&amp;parent_page={{ request.GET.parent_page }}{% endif %}{# parameter `parent_node` only for django CMS 4.1 support #}{% if request.GET.parent_node %}&amp;parent_node={{ request.GET.parent_node }}{% endif %}{%if request.GET.source %}&amp;source={{ request.GET.source }}{% endif %}" method="post" id="{{ opts.model_name }}_form">
{% csrf_token %}
{% block form_top %}{% endblock %}

Expand Down
Loading