Summary
The Online Voting System 1.0 contains a SQL injection flaw in the test_input function within saveVote.php, where voter fields are incorporated into database queries insecurely.
A remote attacker who can submit crafted values for voterName, voterEmail, voterID, or selectedCandidate may manipulate the underlying SQL queries, potentially altering votes or accessing sensitive data.
Affected context
The vulnerability exists in the vote submission workflow of the Online Voting System 1.0, specifically when saveVote.php processes incoming form fields.
It arises when user-supplied values for voterName, voterEmail, voterID, and selectedCandidate are fed into SQL statements without robust parameterization.
This typically affects deployments where the application directly connects to a relational database and treats HTTP request data as trusted input during vote recording.
Exploit preconditions
- Attack surface: Public-facing web endpoint handling vote submissions (
/saveVote.php). - Required access: Ability to send HTTP requests to the voting endpoint (e.g., as a normal voter or unauthenticated user, depending on deployment).
- Trigger point: Submission of specially crafted values in the voterName, voterEmail, voterID, or selectedCandidate parameters.
- Why exploitation is possible: The
test_inputroutine focuses on superficial input cleaning (e.g., trimming, basic escaping) rather than using parameterized queries or rigorous query separation, allowing attacker-controlled data to be interpreted as SQL syntax.
Why this happens
The core issue is embedding untrusted input directly into SQL query strings without using prepared statements or proper parameter binding.
The test_input function likely implements generic sanitization, such as stripping characters or applying simple escaping, which does not reliably prevent injection when data is concatenated into SQL.
This pattern maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command, and is reinforced by CWE-74: Improper Neutralization of Special Elements in Output, since the application fails to clearly separate data from command context.
Potential impact
- An attacker may read or enumerate sensitive voter records stored in the database.
- An attacker may modify, delete, or corrupt vote entries, affecting election integrity.
- An attacker could create or alter user or voter accounts within the database.
- An attacker may execute additional SQL operations, such as dropping tables, leading to denial of service.
- In some configurations, database-level SQL injection could pivot to underlying host compromise.
General mitigation guidance
Effective mitigation focuses on eliminating direct string concatenation of input into SQL and reducing trust in all externally supplied data.
Common defensive patterns include:
- Using parameterized queries or prepared statements for all database operations involving user input.
- Implementing allowlist validation for fields like voterID and selectedCandidate (e.g., numeric IDs or predefined candidate identifiers).
- Separating data and commands by avoiding dynamic query construction where possible.
- Applying least-privilege database accounts so that the application user has only the minimal permissions needed (e.g., no schema modification).
- Centralizing secure database access patterns in a data access layer to make misuse more obvious and easier to review.
How teams detect issues like this
Detection typically combines code-level review and runtime observation:
- Static analysis rules that flag string concatenation or interpolation of HTTP parameters into SQL statements, especially in
saveVote.phpand related components. - Manual code review focused on the
test_inputfunction and all call sites where its output flows into database queries. - Application security tests or dynamic scanners configured to send malicious payloads through the voterName, voterEmail, voterID, and selectedCandidate parameters and observe database error responses or behavioral anomalies.
- CI/CD policies that require prepared-statement usage for all new database access code, enforced via linters or secure coding guidelines.

