Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
O
OHR Support
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
97
Issues
97
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
OHR Support
Commits
e178f1ce
Commit
e178f1ce
authored
Jun 13, 2012
by
Holger Just
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix SQL injection via nested hashes in conditions. CVE-2012-2695 #1037
parent
c3d3bec4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
0 deletions
+39
-0
10-patches.rb
config/initializers/10-patches.rb
+39
-0
No files found.
config/initializers/10-patches.rb
View file @
e178f1ce
...
...
@@ -151,3 +151,42 @@ module ActionController
end
end
end
# Backported fix for CVE-2012-2695
# https://groups.google.com/group/rubyonrails-security/browse_thread/thread/9782f44c4540cf59
# TODO: Remove this once we are on Rails >= 3.2.6
require
'active_record/base'
module
ActiveRecord
class
Base
class
<<
self
def
sanitize_sql_hash_for_conditions
(
attrs
,
default_table_name
=
quoted_table_name
,
top_level
=
true
)
attrs
=
expand_hash_conditions_for_aggregates
(
attrs
)
conditions
=
attrs
.
map
do
|
attr
,
value
|
table_name
=
default_table_name
if
not
value
.
is_a?
(
Hash
)
attr
=
attr
.
to_s
# Extract table name from qualified attribute names.
if
attr
.
include?
(
'.'
)
and
top_level
attr_table_name
,
attr
=
attr
.
split
(
'.'
,
2
)
attr_table_name
=
connection
.
quote_table_name
(
attr_table_name
)
else
attr_table_name
=
table_name
end
attribute_condition
(
"
#{
attr_table_name
}
.
#{
connection
.
quote_column_name
(
attr
)
}
"
,
value
)
elsif
top_level
sanitize_sql_hash_for_conditions
(
value
,
connection
.
quote_table_name
(
attr
.
to_s
),
false
)
else
raise
ActiveRecord
::
StatementInvalid
end
end
.
join
(
' AND '
)
replace_bind_variables
(
conditions
,
expand_range_bind_variables
(
attrs
.
values
))
end
alias_method
:sanitize_sql_hash
,
:sanitize_sql_hash_for_conditions
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment