Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/03.reference/01.functions/encodeforsql/_examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,26 @@ dump( SQLQuery );
SQLQuery="SELECT * FROM dogs WHERE name='#encodeForSQL( url.name, 'mySql' )#';";
dump( SQLQuery );
```

# Recommended: use query parameters instead

```luceescript+trycf
dogs = queryNew(
"name, owner",
"varchar, varchar",
[ [ "lassie", "timmy" ], [ "rex", "anna" ] ]
);

// an url sql injection attempt
url.name = "' or '1'='1";

// the value is sent as a bound parameter and is never part of the SQL string
result = queryExecute(
sql = "SELECT * FROM dogs WHERE name = :name",
params = {
name: { value: url.name, type: "varchar" }
},
options = { dbtype: "query" }
);
dump( result.recordCount ); // 0, the injection attempt matches nothing
```
7 changes: 3 additions & 4 deletions docs/03.reference/01.functions/encodeforsql/function.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ related:
categories:
- esapi
- query
description: this function is deprecated, use query parameters instead.
---

Encodes the given string for safe output in a query to reduce the risk of SQL Injection attacks.

_This method is not recommended_ -
**Deprecated:** this function is deprecated and not recommended. It still works, but escaping characters cannot protect a query as reliably as bound parameters do. Use query parameters instead, see [[tag-queryparam]] and the `params` argument of [[function-queryexecute]].

This function is no longer suppprted by the underlying ESAPI library since 2.7.0 due to security concerns.

The use of query parameters are strongly encouraged. See [[tag-queryparam]].
The underlying ESAPI library removed this function in version 2.7.0 due to security concerns. The Lucee ESAPI extension keeps its own implementation, so existing code is not affected, but new code should not use it.
6 changes: 2 additions & 4 deletions docs/03.reference/05.objects/string/encodeforsql/_method.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ categories:

Encodes the given string for safe output in a query to reduce the risk of SQL Injection attacks.

_This method is not recommended_ -
**Deprecated:** this function is deprecated and not recommended. It still works, but escaping characters cannot protect a query as reliably as bound parameters do. Use query parameters instead, see [[tag-queryparam]] and the `params` argument of [[function-queryexecute]].

This function is no longer suppprted by the underlying ESAPI library since 2.7.0 due to security concerns.

The use of query parameters are strongly encouraged. See [[tag-queryparam]].
The underlying ESAPI library removed this function in version 2.7.0 due to security concerns. The Lucee ESAPI extension keeps its own implementation, so existing code is not affected, but new code should not use it.
Loading