SQL Query Analysis for Injection Detection

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Current methods for preventing SQL injection attacks on relational database management systems are inadequate, relying largely on blacklists and regular expressions, which fail to accurately assess the risk of SQL queries and input variables, leading to insufficient database security.

Innovation Solution

Systems and methods that analyze SQL queries for constraint violations by tokenizing, parsing, and comparing them against a database schema and access configuration to identify potential injection attacks, including invalid field access, type comparisons, and early statement terminations, generating reports to drive mitigation policies.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Ease of manufacture

If blacklists and regular expressions are used to restrict known threats, then implementation is simple, but accuracy in assessing SQL injection risk is insufficient

Engineering Contradiction:
Improveease of implementationVSAvoidaccuracy in assessing SQL injection risk
Core Design Contradiction:
Ease of manufactureVSMeasurement precision

Solution Approach 1:

The SQL query is segmented into multiple tokens through tokenization, and each token is analyzed individually to build a comprehensive understanding of the query structure. This segmentation enables precise identification of injection patterns without requiring complex regex matching, resolving the contradiction between simple implementation and accurate risk assessment.

Inventive Principle:
Principle #1Segmentation

Solution Approach 2:

The analysis transitions from simple string pattern matching to a multi-dimensional approach involving tokenization, parsing into abstract syntax trees, and contextual analysis of operator precedence and query structure. This dimensional transformation enables accurate risk assessment while maintaining implementation feasibility through systematic processing stages.

Inventive Principle:
Principle #17Another dimension (Dimensionality change)

2Reliability

If comprehensive SQL query analysis is performed to identify injection attacks, then database security is improved, but system complexity increases

Engineering Contradiction:
Improvedatabase securityVSAvoidsystem complexity
Core Design Contradiction:
ReliabilityVSDevice complexity

Solution Approach 1:

The system performs preliminary tokenization and parsing of SQL queries before execution, building abstract syntax trees in advance. This preliminary action identifies potential injection vectors early in the process, improving security without requiring complex real-time analysis during query execution, thus managing system complexity.

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

An abstract syntax tree serves as an intermediary representation between the raw SQL query and the security analysis logic. This intermediary structure simplifies the analysis process by providing a standardized, hierarchical representation of query structure, enabling comprehensive security checking without direct complexity in the analysis code.

Inventive Principle:
Principle #24Intermediary (Mediator)

3Measurement precision

If detailed parsing and constraint checking is performed on SQL queries, then detection accuracy of injection attacks is improved, but processing time increases

Engineering Contradiction:
Improvedetection accuracyVSAvoidprocessing time
Core Design Contradiction:
Measurement precisionVSLoss of time

Solution Approach 1:

The parsing process is segmented into distinct stages: tokenization, lexical analysis, and syntax tree construction. Each stage processes specific aspects of the query independently, enabling detailed analysis of injection patterns while optimizing processing time through staged computation rather than monolithic parsing.

Inventive Principle:
Principle #1Segmentation

Solution Approach 2:

The system performs partial parsing and constraint checking focused on critical security-relevant elements such as operator precedence, quote matching, and injection patterns. This selective partial action achieves high detection accuracy for injection attacks while avoiding the time cost of analyzing every possible query nuance, thus balancing precision and performance.

Inventive Principle:
Principle #16Partial or excessive action

Data Source

PatentUS10002254B2Systems and methods for SQL type evaluation to detect evaluation flaws
Publication Date: 2018.06.19 IMPERVA INC
  • US10002254B2 patent drawing
  • US10002254B2 patent drawing
  • US10002254B2 patent drawing

AI summary

Methods and apparatuses for detecting an evaluation flaw in a SQL query, the SQL query configured to access data in a database table are disclosed. The method includes creating a parse tree from the SQL query and evaluating the parse tree to ascertain whether a condition of the SQL query results in a type or value that is independent of contents of the database table. For type evaluation, if, responsive to the evaluating, the condition is found, designating the SQL query at risk for having the tautology in the SQL query. For value evaluation, if, responsive to the evaluating, the condition is found, determining whether the condition is always true or whether the condition is always false; and if, responsive to the determining, the condition is found to be always true or always false, designating the SQL query at risk for having the evaluation flaw in the SQL query.