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>
52 lines
1.9 KiB
Python
52 lines
1.9 KiB
Python
from datetime import datetime
|
|
|
|
from CTFd.models import db
|
|
|
|
|
|
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"))
|
|
# 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"))
|
|
|
|
# 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=[challenge_id], lazy="select"
|
|
)
|
|
|
|
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.owner_id = owner_id
|
|
self.flag_id = flag_id
|
|
|
|
def __repr__(self):
|
|
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}>"
|
|
)
|