fix: Reliable cheat reports and a usable admin side
Reports - Sharing within a team is no longer reported: owner and submitter are compared by account (the team in teams mode), not by user. - Admins (e.g. testing in preview mode) are never reported. - A personal flag without a valid owner no longer crashes the submission (int() of its data raised a 500); empty flags never match. - One report per cheater, challenge and flag (unique constraint plus a check before inserting): "all" logic re-checks every earlier submission on each attempt, which created duplicates. Migration 5b1e0c7d9a24 drops existing duplicates and adds the constraint. - Every new report is logged. Matching uses hmac.compare_digest. Flags and helpers - The admin flag forms sent the owner as "user id", which CTFd's flag API ignores: personal flags created by admins had no owner. They now send "data", with labels bound to their inputs. - create_flag_if_missing only considers personal flags, deterministically. Plugin - Migrations run under the plugin's real directory (was "cheaters"); asset paths follow the directory instead of hardcoding it. - Model renamed CheatReport (owner instead of helper); table and column names unchanged. Dates stored in UTC. - Admin page: newest first, paginated, related rows loaded with the page, real report ids, url_for links, team columns in teams mode, local-time dates, and a Dismiss action. - README (install as ctfd_cheaters, "any" logic, API for other plugins); pyrightconfig without an absolute path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
47b9a8a7f1
commit
8084b3996a
9 files changed
+368
-132
No files matched your search
@@ -1,45 +1,51 @@
|
||||
from datetime import datetime
|
||||
|
||||
from CTFd.models import db
|
||||
|
||||
|
||||
class CheaterTeams(db.Model):
|
||||
class CheatReport(db.Model):
|
||||
"""A user submitted a personal flag that belongs to another account."""
|
||||
|
||||
# table and column names kept from older versions (CheaterTeams/helper)
|
||||
__tablename__ = "cheater_teams"
|
||||
__table_args__ = (
|
||||
# one report per cheater, challenge and leaked flag, however many
|
||||
# times the flag is submitted or re-checked
|
||||
db.UniqueConstraint(
|
||||
"challenge_id", "cheater_id", "flag_id", name="uq_cheater_teams_report"
|
||||
),
|
||||
)
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
challenge_id = db.Column(
|
||||
db.Integer, db.ForeignKey("challenges.id", ondelete="CASCADE")
|
||||
)
|
||||
# who submitted the flag
|
||||
cheater_id = db.Column(db.Integer, db.ForeignKey("users.id", ondelete="CASCADE"))
|
||||
helper_id = db.Column(db.Integer, db.ForeignKey("users.id", ondelete="CASCADE"))
|
||||
# whom the flag belongs to (who leaked it)
|
||||
owner_id = db.Column(
|
||||
"helper_id", db.Integer, db.ForeignKey("users.id", ondelete="CASCADE")
|
||||
)
|
||||
flag_id = db.Column(db.Integer, db.ForeignKey("flags.id", ondelete="CASCADE"))
|
||||
|
||||
date = db.Column(db.DateTime, default=db.func.current_timestamp())
|
||||
|
||||
# Relationships
|
||||
cheater = db.relationship(
|
||||
"Users", foreign_keys="CheaterTeams.cheater_id", lazy="select"
|
||||
)
|
||||
helper = db.relationship(
|
||||
"Users", foreign_keys="CheaterTeams.helper_id", lazy="select"
|
||||
)
|
||||
flag = db.relationship("Flags", foreign_keys="CheaterTeams.flag_id", lazy="select")
|
||||
# UTC, like CTFd's own timestamps
|
||||
date = db.Column(db.DateTime, default=datetime.utcnow)
|
||||
|
||||
cheater = db.relationship("Users", foreign_keys=[cheater_id], lazy="select")
|
||||
owner = db.relationship("Users", foreign_keys=[owner_id], lazy="select")
|
||||
flag = db.relationship("Flags", foreign_keys=[flag_id], lazy="select")
|
||||
challenge = db.relationship(
|
||||
"Challenges",
|
||||
foreign_keys="CheaterTeams.challenge_id",
|
||||
lazy="select",
|
||||
"Challenges", foreign_keys=[challenge_id], lazy="select"
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self, challenge_id: int, cheater_id: int, helper_id: int, flag_id: int
|
||||
):
|
||||
def __init__(self, challenge_id: int, cheater_id: int, owner_id: int, flag_id: int):
|
||||
self.challenge_id = challenge_id
|
||||
self.cheater_id = cheater_id
|
||||
self.helper_id = helper_id
|
||||
self.owner_id = owner_id
|
||||
self.flag_id = flag_id
|
||||
|
||||
def __repr__(self):
|
||||
return "<CheaterTeams User {0} maybe cheated for challenge {1} with the flag {2} belonging to the User {3} at {4} >".format(
|
||||
self.cheater_id,
|
||||
self.challenge_id,
|
||||
self.flag.content,
|
||||
self.helper_id,
|
||||
self.date,
|
||||
return (
|
||||
f"<CheatReport user {self.cheater_id} submitted the flag {self.flag_id} "
|
||||
f"of user {self.owner_id} for challenge {self.challenge_id} at {self.date}>"
|
||||
)
|
||||
Reference in new issue
Block a user