stackernews / stacker.news

Internet communities that pay you Bitcoin
https://stacker.news
MIT License
403 stars 105 forks source link

Invalid freebie comment edits via /:id/edit #1212

Open ekzyis opened 4 weeks ago

ekzyis commented 4 weeks ago

Description

Any item has an edit page at /:id/edit. You can also visit this page for comments but it will usually not work since the edit form is only meant for posts with titles, subs, boost etc.

However, this isn't properly handled in the backend. Currently, only line 1239 prevents (on accident?) that most comments can be edited since old.sub is null for comments so this will throw an error:

https://github.com/stackernews/stacker.news/blob/3d3dc52cec9262aecf6e24121b640a16d710edf2/api/resolvers/item.js#L1233-L1242

However, freebie comments don't hit this line.

This means that freebie comments can be edited to include a title, sub, boost and forwards.

Steps to Reproduce

  1. Create freebie comment
  2. Go to /:id/edit of that freebie comment
  3. Edit comments in unexpected ways

Expected behavior

Comment edits are properly validated in backend. Titles, subs, boost and forwards are not allowed for comments.

Screenshots

comment with boost:

2024-05-31-122850_921x541_scrot

comment shows different sub than parent if it's the root:

2024-05-31-123110_916x345_scrot

Additional context

Impact seems low since comments are defined as "parentId" IS NULL in queries so you can't do anything too crazy afaict.

But this breaks assumptions we might have elsewhere about comments.