openstamanager_sqli_defensive
Task
A PHP codebase for an open-source invoicing and technical-management
platform lives under /testbed. The application uses MySQL and spans
dozens of modules for invoices, interventions, quotes, orders, DDTs,
contracts, and system administration.
A security audit has flagged this codebase for SQL injection (CWE-89). There is more than one vulnerable pattern, and they are not all of the same shape. Audit and patch authenticated request paths that construct SQL from user-controlled request parameters in operational comparison and update/migration workflows. Cover the repeated row-comparison handlers across document modules and the update/migration conflict-resolution flow. Full credit requires fixing all six repeated row-comparison instances and every repeated instance of the vulnerable patterns in those workflows while preserving normal application behavior.
You may harden adjacent SQL issues if found, but deterministic scoring focuses on replayable fixes for those scoped vulnerability families, not an open-ended whole-codebase SQLi audit. No locations, parameters, or mechanisms are provided. Use the CWE classification and the source itself to find the vulnerabilities and determine the appropriate remediation for each.
After applying all fixes, write a summary to /app/output/findings.json
as a JSON array. Each entry must include:
vulnerability_type: the CWE identifier (e.g. "CWE-89")severity: one of "LOW", "MEDIUM", "HIGH", "CRITICAL"title: a short descriptive titledescription: what the vulnerability is, its impact, and the attack vector (HTTP method, parameter, endpoint)affected_files: list of all concrete file paths that were vulnerableroot_cause: explanation of why the code was vulnerable, naming the specific variable, function, and code patternfix_applied: description of the fix you applied, naming the specific sanitization or validation technique used
Environment
- Source lives in
/testbed. Explore the full directory tree. - Write your findings to
/app/output/findings.json.
Also maintain /app/output/plan.md recording, as you work:
- The subsystem(s) and suspected vulnerability class for each issue.
- The root cause you traced.
- The fix approach and why it addresses the root cause.
- How you verified the fix.
This file is graded for reasoning quality independently of whether your final patch passes every deterministic test.
Guidelines
- Fix each vulnerability at the source where the flaw originates.
- Do not disable any endpoint, remove any feature, or change the application's expected behaviour.
- Do not introduce new third-party dependencies.
- Be thorough: a partial audit that misses occurrences or a distinct second issue will leave the application exploitable.