Skip to content

Conversation

@bitbonsai
Copy link

@bitbonsai bitbonsai commented Jan 8, 2026

Summary

This PR fixes a potential SQL injection vulnerability in the queryBuilder function in app/src/v1/Mapper.ts.

Problem

The queryBuilder function was constructing SQL queries using unsanitized field names directly from user input. The post object in Controller.ts is typed as any and populated from user-controlled content via c.get('content'), making it possible for malicious field names (e.g., "filename; DROP TABLE files--": "value") to be injected into SQL queries.

While table names are already sanitized (line 47: table.replace(/[^a-z_]/g, '')), field names were not receiving the same treatment.

Solution

This change:

  • Sanitizes field names to only allow [a-z_] characters
  • Skips invalid field names entirely
  • Applies the same sanitization pattern already used for table names

Testing

All existing functionality should continue to work as normal since valid field names (lowercase alphanumeric and underscores) pass through unchanged. The change is defensive programming to prevent potential security issues.

Files Changed

  • app/src/v1/Mapper.ts - Added field name sanitization in queryBuilder function

The queryBuilder function was constructing SQL queries using
unsanitized field names from user input, creating a potential
SQL injection vulnerability.

This change:
- Sanitizes field names to only allow [a-z_] characters
- Skips invalid field names entirely
- Matches the existing table name sanitization pattern

The 'post' object in Controller.ts is typed as 'any' and comes
from user input via c.get('content'), making field name
sanitization necessary for security.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants