Skip to content

Reject reply_to pointing to a comment on another object (main) - #573

Open
PetrDlouhy wants to merge 1 commit into
danirus:mainfrom
PetrDlouhy:fix/reply-to-same-object
Open

PetrDlouhy wants to merge 1 commit into
danirus:mainfrom
PetrDlouhy:fix/reply-to-same-object

Conversation

@PetrDlouhy

@PetrDlouhy PetrDlouhy commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Same fix as #572, for main: a reply whose reply_to points to a comment on another object no longer joins that object's thread.

The form rejects it, and WriteCommentSerializer.validate() repeats the check, because on main the serializer acts only on the form's security errors (without it the API would still answer 500).

Tests added, CHANGELOG updated.

🤖 Generated with Claude Code

XtdCommentForm accepted any reply_to, and the REST API only checked
that the parent comment exists. A reply takes its parent's thread and
level, so a comment posted to object A with reply_to pointing at a
comment on object B is stored on A but joins B's CommentThread:

- B's ancestors get their nested_count bumped for a reply that never
  shows under B.
- Withholding or publishing B's comment
  (publish_or_withhold_nested_comments) hides or publishes the reply
  on A.
- When A's model allows no threads (max_thread_level 0) but B's does,
  the API passes validation (it checks B's limit) and save() raises
  MaxThreadLevelExceededException: a 500.

Both the form (HTML endpoint) and WriteCommentSerializer.validate()
(API endpoint) now require the parent to be one of
XtdComment.objects.for_model(target), and answer 400 otherwise. The
serializer needs its own check because it only acts on the form's
security errors and would otherwise fail in save() with a ValueError.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@PetrDlouhy PetrDlouhy changed the title Reject replies to a comment on another object (main) [Suspicious comment spam alerts] Reject reply_to pointing to a comment on another object (main) Oct 16, 2026
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.

1 participant