/

CVE-2022-51023

Severity:

HIGH RISK

(8.2)

SQL Injection (CWE-89) in PHPOK Project API Endpoint

CVE-2022-51023

Deferred

Vulnerability type

Category:

SQL Injection

CWE:

CWE-89

Impact:

Unauthorized Database Access and Information Disclosure

Severity:

HIGH RISK

(8.2)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

PHPOK versions in the affected range contain an SQL injection vulnerability in the project API's sort parameter. An unauthenticated attacker may manipulate query ordering logic and cause database errors that disclose sensitive information when the parameter is incorporated into SQL without adequate validation.

PHPOK versions in the affected range contain an SQL injection vulnerability in the project API's sort parameter. An unauthenticated attacker may manipulate query ordering logic and cause database errors that disclose sensitive information when the parameter is incorporated into SQL without adequate validation.

Affected context

The vulnerability occurs in the PHPOK project API endpoint when the sort GET parameter is accepted from unauthenticated requests and used to construct an ORDER BY clause. Deployments are at greater risk when this endpoint is internet-accessible, query parameters are not constrained to approved sort fields, and database errors are returned to clients.

The vulnerability occurs in the PHPOK project API endpoint when the sort GET parameter is accepted from unauthenticated requests and used to construct an ORDER BY clause. Deployments are at greater risk when this endpoint is internet-accessible, query parameters are not constrained to approved sort fields, and database errors are returned to clients.

Exploit preconditions

  • Attack surface: The project API endpoint at /api.php?c=project&f=index
  • Required access: No authentication may be required when the endpoint is publicly reachable
  • Trigger point: Processing of the user-controlled sort parameter
  • Why exploitation is possible: The parameter may influence SQL query structure without strict allowlisting or safe query construction, enabling database expression manipulation and error-based information disclosure
  • Attack surface: The project API endpoint at /api.php?c=project&f=index
  • Required access: No authentication may be required when the endpoint is publicly reachable
  • Trigger point: Processing of the user-controlled sort parameter
  • Why exploitation is possible: The parameter may influence SQL query structure without strict allowlisting or safe query construction, enabling database expression manipulation and error-based information disclosure

Why this happens

The underlying bug is insufficient separation between untrusted request data and SQL query structure. When a user-controlled sorting value is concatenated into an ORDER BY clause or otherwise passed to a database query without selecting from a fixed set of permitted fields, an attacker can alter query behavior. This behavior maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').

The underlying bug is insufficient separation between untrusted request data and SQL query structure. When a user-controlled sorting value is concatenated into an ORDER BY clause or otherwise passed to a database query without selecting from a fixed set of permitted fields, an attacker can alter query behavior. This behavior maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').

Potential impact

  • An attacker may retrieve sensitive database information through query errors or other observable responses.
  • Database contents, schema details, or application metadata could be disclosed.
  • Crafted requests could degrade application availability or affect query performance.
  • If database permissions are excessive, exploitation could enable broader data modification or access.
  • An attacker may retrieve sensitive database information through query errors or other observable responses.
  • Database contents, schema details, or application metadata could be disclosed.
  • Crafted requests could degrade application availability or affect query performance.
  • If database permissions are excessive, exploitation could enable broader data modification or access.

General mitigation guidance

Mitigation generally focuses on ensuring that request parameters cannot control SQL syntax.

Common defensive patterns include:

  • Map sorting requests to a fixed allowlist of server-defined column names and directions.
  • Avoid concatenating user input into SQL statements, using parameterized queries where supported.
  • Validate types, lengths, and permitted values before database access.
  • Return generic application errors rather than database diagnostics or stack traces.
  • Apply least-privilege permissions to the application database account.
  • Place administrative or sensitive API functionality behind appropriate authentication and network controls.
  • Treat client-controlled sorting and filtering values as untrusted even when they appear non-sensitive.

Mitigation generally focuses on ensuring that request parameters cannot control SQL syntax.

Common defensive patterns include:

  • Map sorting requests to a fixed allowlist of server-defined column names and directions.
  • Avoid concatenating user input into SQL statements, using parameterized queries where supported.
  • Validate types, lengths, and permitted values before database access.
  • Return generic application errors rather than database diagnostics or stack traces.
  • Apply least-privilege permissions to the application database account.
  • Place administrative or sensitive API functionality behind appropriate authentication and network controls.
  • Treat client-controlled sorting and filtering values as untrusted even when they appear non-sensitive.

How teams detect issues like this

High-level detection can include:

  • Static analysis for string concatenation or interpolation of request parameters into SQL query construction.
  • Code review checks for dynamic ORDER BY, filtering, and pagination clauses that lack allowlists.
  • Runtime monitoring for repeated malformed query parameters, database error responses, and unusual requests to public API endpoints.
  • Web application firewall or API gateway policies that constrain sorting parameters to documented values.
  • Automated security testing that verifies invalid sort values are rejected without exposing database errors.
  • Database audit logging to identify unexpected query patterns or access to sensitive tables.

High-level detection can include:

  • Static analysis for string concatenation or interpolation of request parameters into SQL query construction.
  • Code review checks for dynamic ORDER BY, filtering, and pagination clauses that lack allowlists.
  • Runtime monitoring for repeated malformed query parameters, database error responses, and unusual requests to public API endpoints.
  • Web application firewall or API gateway policies that constrain sorting parameters to documented values.
  • Automated security testing that verifies invalid sort values are rejected without exposing database errors.
  • Database audit logging to identify unexpected query patterns or access to sensitive tables.

Sources

SourceLink
github.comgithub.com/projectdiscovery/nuclei-templates/blob/main/http/vulnerabilities/other/phpok-sqli.yaml
github.comgithub.com/qinggan/phpok/commit/d70c396f
vulncheck.comvulncheck.com/advisories/phpok-5.4.081-sql-injection-via-api-php-sort-parameter

Frequently asked

questions

Yes, it may be remotely exploitable when the affected project API is reachable over a network and accepts unauthenticated requests.

The described attack path does not require authentication, although deployment-specific routing, access controls, or network restrictions may limit exposure.

Treat the sort parameter as a symbolic value rather than raw SQL. Resolve it through a strict server-side allowlist and prevent database errors from being returned to clients.

Use parameterized query mechanisms where applicable, validate dynamic query components separately, apply least-privilege database permissions, and include SQL injection checks in code review and automated testing.

Yes, it may be remotely exploitable when the affected project API is reachable over a network and accepts unauthenticated requests.

The described attack path does not require authentication, although deployment-specific routing, access controls, or network restrictions may limit exposure.

Treat the sort parameter as a symbolic value rather than raw SQL. Resolve it through a strict server-side allowlist and prevent database errors from being returned to clients.

Use parameterized query mechanisms where applicable, validate dynamic query components separately, apply least-privilege database permissions, and include SQL injection checks in code review and automated testing.

Find out what's already
exploitable in your codebase.