Summary
WeGIA versions 3.6.5 and 3.6.6 contain an SQL injection flaw in the backup restoration feature, where uploaded SQL backup archives are imported without any validation or restriction.
An attacker who can upload a crafted backup file may execute arbitrary SQL statements, including creating rogue administrator accounts, changing passwords, or altering application data.
Affected context
This vulnerability affects WeGIA deployments that expose the backup restore functionality in versions 3.6.5 and 3.6.6.
It typically manifests when:
- Users are allowed to upload and restore database backups through the web interface
- The application directly executes SQL from uploaded backup files
- There is no filtering, validation, or restriction on which SQL statements are permitted during restore
The issue resides specifically in the loadBackupDB() function that processes and imports SQL backup archives.
Exploit preconditions
- Attack surface: Web interface or API endpoint used to upload and restore database backup archives.
- Required access: Ability to authenticate or otherwise reach the backup upload/restore functionality; in many deployments this is limited to administrative or privileged users, but misconfigurations could broaden access.
- Trigger point: Submission of a crafted backup archive that contains malicious SQL statements followed by a restore operation via
loadBackupDB(). - Why exploitation is possible: The restore logic assumes that backup files are trustworthy and executes their contents as SQL without parsing, validation, or whitelisting, effectively treating user-supplied files as authoritative database commands.
Why this happens
The root cause is an insecure design in the backup restoration mechanism where untrusted input (uploaded backup archives) is treated as trusted SQL and executed verbatim.
Instead of constraining restores to data-only operations or a controlled set of statements, the loadBackupDB() function allows arbitrary SQL commands from the uploaded file.
This maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), as user-controllable content directly influences the SQL executed by the database without sanitization, validation, or structural enforcement.
Potential impact
- Creation of rogue administrator or privileged user accounts in the application database
- Modification or reset of existing user passwords, enabling account takeover
- Deletion, corruption, or tampering with critical application data and logs
- Escalation of privileges within the application by altering role or permission tables
- Exfiltration of sensitive information by inserting SQL commands that dump data to attacker-accessible locations
- Disruption of service availability by dropping tables or altering schema
General mitigation guidance
Mitigation should focus on treating backup files as untrusted input and constraining what the restore process can do:
- Design the backup/restore feature to operate on data-only dumps that exclude schema changes, user tables, and privileged metadata.
- Implement strict parsing and validation of backup content, rejecting any SQL commands outside an allowed subset (for example, inserts into a narrow set of known tables).
- Apply principle of least privilege at the database level so the account used for restores cannot create administrative users, alter credentials, or modify security-related tables.
- Require strong authentication and role-based authorization for access to backup upload and restore capabilities, and avoid exposing this feature in lower-trust environments.
- Prefer structured migration and seeding mechanisms over free-form SQL execution for application-level data initialization and recovery.
How teams detect issues like this
Detection efforts can target both source code and runtime behavior:
- Static analysis and code review:
- Flag any functionality that reads user-uploaded files and passes their contents directly to database execution APIs.
- Look for restore or migration utilities that accept arbitrary SQL or do not restrict target tables and commands.
- Review backup/restore flows for absence of content validation, parsing, or schema checks.
- Runtime monitoring and logging:
- Enable detailed database logging for administrative and schema-changing operations initiated by the application account.
- Monitor for unusual patterns during backup restore operations, such as creation of new admin users, changes to authentication tables, or DDL statements.
- Policy and tooling:
- Use automated security scanning tools that detect generic SQL injection patterns and insecure DB execution paths.
- Integrate security-focused code review checklists specifically for maintenance and administrative features like backup and restore.

