CWE-1073: Non-SQL Invokable Control Element with Excessive Number of Data Resource Accesses
Learn about CWE-1073 (Non-SQL Invokable Control Element with Excessive Number of Data Resource Accesses), its security impact, exploitation methods, and prevention guidelines.
What is Non-SQL Invokable Control Element with Excessive Number of Data Resource Accesses?
• Overview: CWE-1073 refers to a situation where a function or method in a software product accesses data resources excessively, without leveraging efficient database capabilities. This can slow down the application's performance and may potentially lead to vulnerabilities if the code is accessible to an attacker. A best practice is to limit data accesses to a maximum of 2 per function/method.
• Exploitation Methods:
- Attackers can exploit this vulnerability by initiating operations that force the software to perform excessive data accesses, potentially causing denial of service through resource exhaustion.
- Common attack patterns include triggering functions with high data access in quick succession, overwhelming the system, and exploiting performance bottlenecks.
• Security Impact:
- Direct consequences include reduced application performance and increased processing time for legitimate users.
- Potential cascading effects can lead to system instability, increased resource consumption, and potential denial of service.
- Business impact includes loss of customer trust, increased operational costs due to inefficiencies, and potential financial losses from downtime.
• Prevention Guidelines:
- Specific code-level fixes involve optimizing database queries, reducing the number of data accesses within individual functions, and using efficient data management techniques.
- Security best practices include conducting regular code reviews, performance testing, and refactoring code to improve data access efficiency.
- Recommended tools and frameworks include using database profilers for query optimization, implementing caching mechanisms, and utilizing ORM (Object-Relational Mapping) tools to streamline data interactions.
Corgea can automatically detect and fix Non-SQL Invokable Control Element with Excessive Number of Data Resource Accesses in your codebase. Try Corgea free today.
Technical Details
Likelihood of Exploit: Not specified
Affected Languages: SQL
Affected Technologies: Database Server
Vulnerable Code Example
-- This code demonstrates a vulnerability where multiple SQL queries are executed
-- individually in a loop, leading to excessive database access and inefficiency.
BEGIN;
DECLARE customer_cursor CURSOR FOR
SELECT customer_id FROM customers;
OPEN customer_cursor;
FETCH NEXT FROM customer_cursor INTO @customer_id;
WHILE @@FETCH_STATUS = 0
BEGIN
-- Vulnerable: Individual queries executed for each customer, causing excessive resource usage
SELECT * FROM orders WHERE customer_id = @customer_id;
FETCH NEXT FROM customer_cursor INTO @customer_id;
END;
CLOSE customer_cursor;
DEALLOCATE customer_cursor;
COMMIT;
Issues with the Vulnerable Code:
- Excessive Database Access: The loop executes a separate query for each customer, leading to multiple database accesses.
- Inefficiency: This approach is inefficient as it increases the load on the database server and can lead to performance bottlenecks.
How to fix Non-SQL Invokable Control Element with Excessive Number of Data Resource Accesses?
Fixed Code Example
-- Fixed code using a single SQL query with a JOIN for efficient data access
BEGIN;
-- Efficient: Use a JOIN to retrieve all necessary data in one query
SELECT c.customer_id, o.order_id, o.order_date
FROM customers c
JOIN orders o ON c.customer_id = o.customer_id;
COMMIT;
Improvements in the Fixed Code:
- Single Query Execution: By using a
JOIN
, the code retrieves all necessary data in one go, reducing the number of data resource accesses. - Efficiency: This method improves the efficiency and performance of the application by minimizing the load on the database server.
- Best Practices: Using
JOIN
operations is a best practice for retrieving related data across multiple tables in a single query, ensuring optimized database interactions.
On This Page
- What is Non-SQL Invokable Control Element with Excessive Number of Data Resource Accesses?
- Technical Details
- Vulnerable Code Example
- Issues with the Vulnerable Code:
- How to fix Non-SQL Invokable Control Element with Excessive Number of Data Resource Accesses?
- Fixed Code Example
- Improvements in the Fixed Code: