Server-Side Gatekeeper
Relevant source files
The following files were used as context for generating this wiki page:
The Server-Side Gatekeeper is a critical security and orchestration layer within the Debug Arena platform. Its primary purpose is to maintain competitive integrity by enforcing proctoring rules, validating code safety, and controlling access to challenge levels based on team progress and violation counts.
This system acts as the intermediary between the client-side proctoring script and the back-end evaluation engine. It ensures that teams cannot bypass security measures, such as fullscreen requirements, or execute malicious code on the host server.
Sources: README.md:92-100, routes/arena_routes.py:14-20
Core Security Mechanisms
The Gatekeeper employs three distinct layers of security: access control, proctoring enforcement, and code execution safety.
Access Control & Disqualification
The Gatekeeper monitors the violations field in the Team model. If a team reaches or exceeds a threshold of 3 violations, the system blocks access to the dashboard and all arena levels, redirectly the user to a disqualification state.
The logic ensures that even if a user manually attempts to access a level URL, the server-side check prevents unauthorized progression.
Sources: routes/arena_routes.py:16-20, routes/arena_routes.py:53-57, models/team.py:17
Code Safety Validation
Before any submitted code is executed by the system, it passes through a validation utility that scans for dangerous keywords and patterns. This prevents remote code execution (RCE) and system-level interference.
| Restriction Type | Description | Targeted Patterns |
|---|---|---|
| Module Blacklist | Prevents importing system-sensitive libraries | os, sys, subprocess, shutil |
| Function Blacklist | Blocks dangerous built-in Python functions | eval(), exec(), open(), __import__ |
| Attribute Access | Prevents introspection attacks | getattr, setattr, __subclasses__ |
| Input Length | Limits code to 2000 characters to prevent memory exhaustion | N/A |
Sources: utils/security.py:4-21, services/code_runner.py:7-10
Proctoring Integration
The Gatekeeper exposes specific API endpoints that receive real-time signals from the client-side proctor.js script. When a user switches tabs or exits fullscreen mode, a violation is logged permanently in the database.
Violation Logging Flow
- The client detects a
visibilitychangeorfullscreenchange. - A POST request is sent to
/log_violation. - The Gatekeeper increments the
Team.violationscount and commits to the database. - The response notifies the client if the disqualification threshold has been met.
Secure Code Execution
The Gatekeeper oversees the execution of user-submitted code through the code_runner service. This service utilizes subprocess.run with strict environment constraints to isolate the user code from the main application process.
- Timeout Enforcement: Code is terminated if it runs longer than 2 seconds to prevent infinite loops.
- Shell Protection:
shell=Falseis used to prevent shell injection attacks. - Output Capture: Standard output and standard error are captured and returned for evaluation or debugging.
Sources: services/code_runner.py:13-22, routes/submit_routes.py:31-35
Level Progression Logic
The Gatekeeper enforces a linear progression system. Teams are prevented from "skipping ahead" to higher levels by verifying the current_level stored in the team's database record against the requested level_id.
| Endpoint | Security Check | Purpose |
|---|---|---|
/dashboard | Violation check | Displays only levels where level_id <= current_level. |
/arena/<int:level_id> | Progression check | Aborts or redirects if level_id > current_level. |
/run_code/<int:level_id> | Integrity check | Only awards points if the level being solved matches the team's current_level. |
Sources: routes/arena_routes.py:65-67, routes/submit_routes.py:61-63
Conclusion
The Server-Side Gatekeeper ensures the Debug Arena remains a fair and secure environment for competitive debugging. By combining database-backed violation tracking, strict code sanitization, and isolated execution, it protects the host infrastructure while maintaining the integrity of the contest standings.