Summary
Twitter-Clone 1 is vulnerable to SQL injection in follow.php, where the userid parameter is directly embedded into database queries without proper sanitization or parameterization.
An attacker can inject union-based or time-based blind SQL payloads to manipulate queries and extract sensitive information such as usernames, passwords, and database credentials whenever this endpoint is reachable.
Affected context
This vulnerability occurs in the follow.php functionality of the Twitter-Clone 1 application, specifically where user-follow relationships are processed.
It affects deployments where:
- The follow.php script is exposed via HTTP(S)
- The userid parameter is accepted from client input (e.g., query string or form data)
- The application constructs SQL statements by concatenating or interpolating the userid value directly into the query
- The connected database account has access to user tables or credentials
Exploit preconditions
- Attack surface: HTTP(S) endpoint handling follow actions (follow.php)
- Required access: Ability to send crafted requests to the follow.php script (typically unauthenticated or minimally authenticated, depending on deployment)
- Trigger point: Supplying malicious SQL fragments through the userid parameter in the request
- Why exploitation is possible: The application builds SQL queries using unvalidated, unsanitized user input without using prepared statements or proper escaping, enabling attackers to alter the query structure (UNION-based, boolean/time-based blind injection).
Why this happens
The root cause is the direct inclusion of user-controlled data into SQL statements without using safe query construction mechanisms.
This aligns with CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where metacharacters (such as quotes, comment markers, and operators) provided by the attacker are interpreted as part of the SQL syntax.
Conceptually, the bug class is dynamic query generation via string concatenation or interpolation of untrusted input instead of binding values through parameterized queries, allowing attackers to reshape the query logic executed by the database.
Potential impact
- Extraction of sensitive user data, including usernames and password hashes
- Exposure of database credentials or configuration information stored in tables
- Enumeration of database schema, including table and column names
- Modification or deletion of application data (e.g., user profiles, relationships, or messages)
- Potential pivot to other parts of the system if additional stored credentials are recovered
General mitigation guidance
Mitigation focuses on enforcing safe query construction and minimizing trust in user-supplied data:
- Adopt parameterized queries or prepared statements for all database operations involving user input, especially for identifiers like userid
- Apply strict input validation on identifiers, limiting them to expected formats (e.g., numeric IDs) and rejecting anything outside defined patterns
- Centralize database access through a data access layer that enforces parameterization by default and discourages ad-hoc string-built queries
- Use least-privilege accounts at the database level so that the application's database user has only the minimum required permissions
- Implement output encoding or ORM abstractions where feasible to reduce direct interaction with raw SQL
How teams detect issues like this
Detection efforts can combine code-level and behavioral analysis:
- Static analysis rules to flag dynamic SQL strings combining request parameters, especially those involving userid, in follow.php and related modules
- Code review checklists that explicitly look for string concatenation or interpolation when building SQL queries, and verify that prepared statements are consistently used
- Security unit or integration tests that inject SQL metacharacters into userid and observe for errors or timing differences
- Web application firewall (WAF) policies that monitor for common SQL injection patterns in parameters like userid and raise alerts on suspicious traffic
- Periodic penetration testing or automated DAST scans focusing on endpoints that manipulate relational data

