Appendix C
Untrusted Data Processing
Safe processing of untrusted data is a key part of a successful security protection layer implemented by any application. For APEX applications, such functionality can use features of the powerful PL/SQL language to ensure that received data is in an expected format that is safe for the application to process.
EXPECTED VALUE
One of the most robust ways of validating untrusted data is to ensure it represents an expected value (sometimes referred to as positive validation). You can do this in a number of ways:
- Check that the input is the required data type; for example, pass the data through TO_NUMBER if the application expects a numeric type.
- Check that the input is a valid value from a list; for example, select input from dual where input in ('yes','no','maybe').
SAFE QUOTE
In some cases, using untrusted data within a dynamic SQL statement may be unavoidable. Care must be taken to ensure the data does not affect the syntax of the query; for quoted strings this means that any embedded quote in the data should be escaped.
With the following, you can define a safequote function that performs this simple validation:
create or replace function safequote (
p_string IN VARCHAR2
)
return VARCHAR2
is
begin
return '''' || replace(p_string,'''','''''') || '''';
end
This function ensures quotes embedded in the input (p_string) are escaped, and that the returned value is enclosed in quotes.
COLON LIST TO COMMA LIST
Sometimes it is necessary to convert ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access