How an Untamed Filter Parameter Unlocked SQL Injection

Background — When Query Builders Trust User Input
During a penetration test of a multi-tenant ERP platform, our team uncovered a critical SQL-injection vulnerability in the OData $filter parameter used by several REST endpoints. The application dynamically merged user-supplied filters into SQL WHERE clauses without parameterisation, leaving the data layer wide-open while the API presented a façade of strict access control. This is the classic “string-building trap”—security checks live on the client, but the final query assembly happens unchecked on the server.
Discovery — Two Quotes, Full Control
During a penetration test of a multi-tenant ERP platform, our team uncovered a critical SQL-injection vulnerability in the OData $filter parameter used by several REST endpoints. The application dynamically merged user-supplied filters into SQL WHERE clauses without parameterisation, leaving the data layer wide-open while the API presented a façade of strict access control. This is the classic “string-building trap”—security checks live on the client, but the final query assembly happens unchecked on the server.
GET /api/v1//GenXDatas
?$filter=TypeCode eq 'HotKeys'
and ProductID eq 'Ep'
and Key1 eq 'manager'''
Authorization: Bearer
Result – The server replied 200 OK with a valid JSON payload, demonstrating that the payload reached the database unfiltered. A follow-up payload such as
Key1 eq 'manager''' or 1=1 --
returned full record sets, confirming Boolean-based SQL injection.
Technical Root Cause — Dynamic SQL in $filter Handling
// Simplified pseudo-code
var where = $"TypeCode = '{type}' AND ProductID = '{product}' AND Key1 = '{key1}'";
var sql = $"SELECT * FROM GenXData WHERE {where}";
No prepared statements — variables are spliced directly into SQL.
Missing escaping/validation — a single quote ends the literal and appends attacker code.
Shared helper — the same builder assembles queries for search, reporting and admin views, multiplying impact.
Real-World Risks — What Attackers Could Do
Bulk data exfiltration – Read sensitive configuration and business records across tenants.
Повышение привилегий – Manipulate auth tables to grant admin roles.
Data tampering – Alter pricing, insert fraudulent defaults, disrupt production schedules.
Denial of service – Run heavy queries (WAITFOR DELAY, expensive joins) to exhaust resources.
Broader Lessons — SQL Injection Isn’t a “Legacy” Issue
Modern APIs (OData, GraphQL, serverless functions) still fall to SQLi when dev teams assume “the framework sanitises it.” Typical patterns include:
• Dynamic string templates for “flexible” reporting.
• Conditional clause assembly instead of parameter arrays.
• Debug toggles that disable ORM parameterisation and later reach production.
If you concatenate anything into SQL, you need a threat-model review—framework or not.
Recommendations — Fix Fast, Prevent Future Slips
✅ Parameterise every query
• In .NET: SqlParameter, Entity Framework lambdas—never raw string interpolation.
✅ Harden query builders
• Whitelist permitted fields/operators in $filter.
• Strip comments (--, /* */) and block stacked queries (;).
✅ Centralised validation layer
• Reject payloads with unmatched quotes or suspicious keywords.
✅ Least-privilege DB accounts
• Application credentials need only minimal SELECT/EXEC rights—no ALTER, DROP.
✅ Continuous monitoring
• Log anomalous $filter lengths and “always true” patterns (or 1=1).
• Alert on spikes in query time or cardinality.
Conclusion — Query Safety Is a Continuous Discipline
Parameterized queries add a few lines of code but save entire businesses. Here, a single unescaped quote transformed a harmless filter into a master key for the ERP’s data layer. Every time you build a SQL string, an attacker smiles—unless you lock it down first.
Другие Услуги
Insomnia Security Scanner
AI-powered web application security scanner by CQR. Automated vulnerability discovery, exploit verification, and detailed reporting for modern applications.
Узнать большеЗащита Инфраструктуры CRYEYE
Аудит безопасности с помощью CryEye обеспечивает информационную безопасность предприятия, защищая всю инфраструктуру.
Узнать большеТестирование на проникновение
Найдите уязвимости во всей инфраструктуре вашего бизнеса раньше, чем это сделают хакеры! В рамках консалтинга по тестированию на проникновение мы подберем методы пентестов.
Узнать большеСоциальная инженерия
Simulate real-world phishing, vishing, and pretexting attacks to measure and improve your team's security awareness and response capabilities.
Узнать большеНагрузочное Тестирование
All kinds of load and performance testing of your system from the CQR online security company.
Узнать большеAI-Powered Vulnerability Assessment
Leverage artificial intelligence to discover, prioritize, and remediate vulnerabilities across your digital assets faster and more accurately than traditional scanners.
Узнать большеCloud Security Audit (AWS / GCP / Azure)
Comprehensive security review of your cloud environments — IAM policies, network controls, data exposure, and misconfigurations across all major cloud platforms.
Узнать большеDevSecOps Integration
Embed security into every stage of your CI/CD pipeline. Automated SAST, DAST, SCA, and secret scanning so vulnerabilities are caught before they reach production.
Узнать большеAPI Security Testing
In-depth testing of REST, GraphQL, and SOAP APIs for authentication flaws, authorization bypasses, injection vulnerabilities, and data leakage risks.
Узнать большеMobile Application Penetration Testing
Manual and automated security testing for iOS and Android applications — reverse engineering, runtime analysis, traffic interception, and backend API assessment.
Узнать большеIoT Security Assessment
Evaluate firmware, communication protocols, cloud backends, and physical interfaces of IoT devices to identify vulnerabilities before attackers do.
Узнать большеBlockchain & Smart Contract Audit
Formal verification and manual code review of smart contracts on Ethereum, Solana, and other chains. Detect reentrancy, overflow, and logic flaws before deployment.
Узнать большеRed Team Operations
Advanced adversary simulation using real attacker TTPs (MITRE ATT&CK) to test your detection, response, and overall security posture under realistic conditions.
Узнать большеThreat Intelligence & Monitoring
Continuous monitoring of threat feeds, dark web, and attacker infrastructure to provide actionable intelligence specific to your organization and industry.
Узнать большеZero Trust Architecture Review
Assess and design your Zero Trust security model — identity verification, micro-segmentation, least-privilege access, and continuous validation controls.
Узнать большеCompliance Consulting (PCI DSS / SOC 2 / GDPR)
Expert guidance to achieve and maintain compliance with major security frameworks. Gap analysis, remediation roadmaps, and audit-readiness support.
Узнать большеDark Web Monitoring
Continuous surveillance of dark web forums, marketplaces, and breach databases for leaked credentials, sensitive data, or mentions of your organization.
Узнать большеPhishing Simulation & Awareness Training
Controlled phishing campaigns combined with interactive security awareness training to build a human firewall across your entire organization.
Узнать большеSupply Chain Security Audit
Assess third-party vendor risks, open-source dependencies, and software supply chain integrity to prevent attacks like SolarWinds and Log4Shell.
Узнать большеContainer & Kubernetes Security
Security review of Docker images, Kubernetes clusters, RBAC policies, network policies, and runtime configurations to harden your container infrastructure.
Узнать большеWeb Application Firewall (WAF) Deployment
Professional WAF setup, rule tuning, and ongoing management to block SQL injection, XSS, CSRF, and other OWASP Top 10 threats in real time.
Узнать большеBug Bounty Program Management
Full lifecycle management of your bug bounty program — scope definition, researcher coordination, triage, validation, and remediation tracking.
Узнать большеOSINT Investigation Services
Open-source intelligence gathering on individuals, organizations, and infrastructure. Ideal for pre-engagement recon, fraud investigation, and competitive analysis.
Узнать большеDigital Forensics & Incident Response
Rapid response to security breaches — evidence collection, malware analysis, attacker timeline reconstruction, and actionable remediation recommendations.
Узнать больше