Summary
A SQL injection flaw in the /edit_exam.php endpoint of SourceCodester Class and Exam Timetabling System 1.0 allows an attacker to manipulate the ID parameter and inject arbitrary SQL commands into backend queries.
When user-supplied identifiers are concatenated directly into SQL statements without proper validation or parameterization, remote attackers can exploit the application over HTTP to access or tamper with stored exam data.
Affected context
This vulnerability occurs in the web-based Class and Exam Timetabling System, specifically within the PHP script handling exam editing (/edit_exam.php).
It typically manifests when the application constructs SQL queries using the ID request parameter directly in the query string, without using prepared statements or rigorous validation.
Installations exposed to the internet or untrusted internal networks, where the edit exam functionality is reachable without strong access controls, are more likely to be affected.
Exploit preconditions
- Attack surface: HTTP interface of the
/edit_exam.phpendpoint. - Required access: Ability to send crafted requests to the exam editing page; authentication requirements depend on deployment and role-based access controls.
- Trigger point: Application code that builds SQL queries using the
IDargument from GET or POST parameters without parameterization. - Why exploitation is possible: The
IDparameter is treated as trusted input and concatenated into SQL statements, enabling attackers to alter query structure instead of just data values.
Why this happens
The root cause is insecure construction of SQL queries in PHP code, where dynamic user input (the ID parameter) is interpolated into query strings without binding through prepared statements or rigorous sanitization.
This aligns with CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), and is related to CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component, because the database is treated as a downstream consumer of unneutralized data.
At an abstract level, the pattern is: accepting untrusted input, failing to constrain it to an expected format (such as numeric IDs), and passing it directly into command-like contexts where metacharacters change control flow.
Potential impact
- Attackers may read exam records and associated class scheduling data they would not normally be authorized to access.
- Malicious users could modify, insert, or delete exam entries, corrupting timetables and operational data.
- The vulnerability may allow extraction of sensitive information stored in the same database, depending on schema and permissions.
- Under permissive database configurations, attackers could create new administrative accounts or adjust authentication-related data.
- In some deployments, SQL injection could be chained to execute database-specific functions that impact system stability or availability.
General mitigation guidance
Effective mitigation focuses on eliminating direct concatenation of user input into SQL queries and tightening trust boundaries around request parameters.
Common defensive patterns include:
- Using parameterized queries or prepared statements for all database operations, ensuring that user input is treated strictly as data.
- Constraining the
IDparameter to a well-defined type (e.g., integer) and validating it server-side before it reaches the data-access layer. - Centralizing database access logic to enforce consistent query construction practices and input validation rules.
- Applying least-privilege principles to database accounts so that even if a query is abused, accessible operations and data are minimized.
- Adopting secure-by-default frameworks or ORM layers that discourage manual string-based query building.
How teams detect issues like this
Detection can rely on a combination of code-centric and behavior-centric approaches:
- Static analysis rules that flag concatenation of request parameters (e.g.,
$_GET,$_POST) into SQL strings or calls to database APIs without bound parameters. - Targeted code review focusing on PHP scripts that handle editing or viewing operations, looking for direct interpolation of variables like
IDinto SQL. - Runtime monitoring and logging to identify anomalous query patterns, such as unexpected operators, comment markers, or tautological conditions in WHERE clauses.
- Security testing routines (including automated web scanners) configured to exercise form fields and URL parameters associated with exam and class management functionality.
- Policy enforcement in CI pipelines that disallow direct string-based SQL construction, backed by automated checks against database access layers.

