Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openbis
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sispub
openbis
Commits
9e995a13
Commit
9e995a13
authored
12 years ago
by
brinn
Browse files
Options
Downloads
Patches
Plain Diff
Improve protection against SQL injection for custom queries.
SVN: 27600
parent
f8029d14
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/server/DAO.java
+13
-2
13 additions, 2 deletions
...ava/ch/systemsx/cisd/openbis/plugin/query/server/DAO.java
with
13 additions
and
2 deletions
openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/server/DAO.java
+
13
−
2
View file @
9e995a13
...
@@ -197,8 +197,10 @@ class DAO extends SimpleJdbcDaoSupport implements IDAO
...
@@ -197,8 +197,10 @@ class DAO extends SimpleJdbcDaoSupport implements IDAO
return
(
TableModel
)
template
.
execute
(
resolvedQuery
,
callback
);
return
(
TableModel
)
template
.
execute
(
resolvedQuery
,
callback
);
}
}
// WORKAROUND this solution is not safe
// FIXME this solution is not safe.
// prepared statement parameters would be better but then we need to know the type of parameters
// We should use a prepared statement and set the parameters according to the information
// that PreparedStatement.getParameterMetaData() provides or check whether setObject() does the
// trick for us here.
private
static
String
createSQLQueryWithBindingsResolved
(
String
sqlQuery
,
private
static
String
createSQLQueryWithBindingsResolved
(
String
sqlQuery
,
QueryParameterBindings
bindingsOrNull
)
QueryParameterBindings
bindingsOrNull
)
{
{
...
@@ -207,10 +209,19 @@ class DAO extends SimpleJdbcDaoSupport implements IDAO
...
@@ -207,10 +209,19 @@ class DAO extends SimpleJdbcDaoSupport implements IDAO
{
{
for
(
Entry
<
String
,
String
>
entry
:
bindingsOrNull
.
getBindings
().
entrySet
())
for
(
Entry
<
String
,
String
>
entry
:
bindingsOrNull
.
getBindings
().
entrySet
())
{
{
validateParameterValue
(
entry
.
getValue
());
template
.
bind
(
entry
.
getKey
(),
entry
.
getValue
());
template
.
bind
(
entry
.
getKey
(),
entry
.
getValue
());
}
}
}
}
return
template
.
createText
();
return
template
.
createText
();
}
}
private
static
void
validateParameterValue
(
String
value
)
throws
UserFailureException
{
if
(
value
.
contains
(
"'"
))
{
throw
new
UserFailureException
(
"Parameter value \""
+
value
+
"\" contains invalid character."
);
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment