openstamanager_sqli_defensive

defensivesql-injectionCWE-89phpmysql

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 title
  • description: what the vulnerability is, its impact, and the attack vector (HTTP method, parameter, endpoint)
  • affected_files: list of all concrete file paths that were vulnerable
  • root_cause: explanation of why the code was vulnerable, naming the specific variable, function, and code pattern
  • fix_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:

  1. The subsystem(s) and suspected vulnerability class for each issue.
  2. The root cause you traced.
  3. The fix approach and why it addresses the root cause.
  4. How you verified the fix.

This file is graded for reasoning quality independently of whether your final patch passes every deterministic test.

Guidelines

  1. Fix each vulnerability at the source where the flaw originates.
  2. Do not disable any endpoint, remove any feature, or change the application's expected behaviour.
  3. Do not introduce new third-party dependencies.
  4. Be thorough: a partial audit that misses occurrences or a distinct second issue will leave the application exploitable.