Dynamic challenges do not recalculate their value when solves are removed
While working on my first blood plugin, I discovered that dynamic challenges do not properly recalculate their value when:
- A solve is manually deleted from the "submissions" page
- An user/team who solved the challenge previously is deleted
- An user/team who solved the challenge previously is hidden/shown again (because hidden users are ignored in the score calculation)
- An user/team who solved the challenge previously is banned/unbanned (because banned users are ignored in the score calculation)
- CTFd is reset using the
/admin/resetfunctionality (but that's basically the same as removing solves, but in bulk)
The challenge value updates only after you open the challenge editor and click "Update" or anybody submits a flag.
In my plugin I worked around this by detecting modifications to Solves, Users and Teams objects using sqlalchemy events and triggering the recalculation on that. I could pull request something similar, but I wonder if there is any better way to implement this given that sqlalchemy events don't seem to be used anywhere in the CTFd codebase.
Environment:
- CTFd Version/Commit: 3.1.1, running from the ctfd/ctfd Docker container
- Operating System: Ubuntu 20.04
- Web Browser and Version: Chrome 85.0.4183.121
What happened? The challenge value did not update
What did you expect to happen? The challenge value to update to reflect removal of the solve
How to reproduce your issue
- Create a dynamic challenge with parameters: initial=500, decay=1, minimum=100
- Solve the challenge
- The challenge value should still be 500 (if there is only one solve, the challenge value == max)
- Solve the challenge again using another account
- The challenge value should drop to 100
- As an admin, remove one of the solves using the "Submissions" page (or do any other action mentioned at the beginning)
- The challenge value should update back to 500, but it does not - until you open the challenge editor and save without changing anything or somebody submits a flag
Any associated stack traces or error logs none
Source: CTFd/CTFd