我正在构建一个webform,我想要预先填充来自外部oracle数据库的数据。我们使用的是rails OCI8插件。
我希望通过在查询中直接使用URL参数来确保自己不会被注入。
例如,在控制器中:
def new
if params[:provider] && u = findByUserName(params[:provider])
monkey = {
:employeeEmail => u['EMAIL_ADDRESS'],
:employeeFirst => u['FIRST_NAME'],
:employeeLast => u['LAST_NAME'],
:userID => u['LOGIN_ID'],
:supervisorUserID => u['SUPERVISOR_ID'],
:supervisorName => u['SUPERVISOR_NAME'],
:supervisorEmail => u['SUPERVISOR_EMAIL']
}
@service = Service.new(monkey)
else
@service = Service.new
end
end正如您所看到的,params:provider被直接传递给OCI8查询:
def findByUserName(id)
if id
cursor = cursor_exec("SELECT DISTINCT
<QUERY INFO HERE>
AND external_user = :id
ORDER BY last_name, first_name", id)
collection = cursor.fetch_hash()
cursor.close
logoff
collection
end
endCursor_exec函数
def cursor_exec(sql, *params)
@conn = OCI8.new('user','pass','server')
if params.length > 0
cursor = @conn.exec(sql, *params)
else
cursor = @conn.exec(sql)
end
endOCI8是否可以通过绑定正确清理参数,或者有没有更安全的方法可以使用?
发布于 2012-04-09 22:51:00
由于您是在内部调用OCI8#exec(),传递给它的第二个参数将被绑定为查询的参数,因此您不必担心额外的转义。它应该由exec()调用在内部进行保护。
From the docs:
exec(sql,*bindvars)
执行sql语句。返回值的类型取决于sql语句的类型: select;insert、update和delete;create、alter和drop;以及PL/SQL。
当指定绑定变量时,它们在执行前被绑定为绑定变量。
https://stackoverflow.com/questions/10074500
复制相似问题