- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
感谢您对此的帮助。我是 Rails 新手(使用 Rails 2,我知道它并不理想,但对于该项目来说是必要的。)我有一个包含多个输入的表单。我想确保我正在保护我的用户免受 SQL 注入(inject)。我认为我已经正确处理了它,但我只是想确定一下,尤其是在输入方面。
footwear.html.erb 具有保存到鞋子和 socks 表的表单
<% form_for @shoe, :html=>{:id=>'createanOrder'} do |f| %>
<input id="shoe_name" name="shoename" size="30" type="text" value="New Shoe"></p>
<p>Enter a decoration for the top:
<input id="topdecorationinput" type="text" name="topdecorationinput" size="56"></p>
<p>Or, select a decoration from the list:
<select id="topdecorationdropdown" name="topdecorationdropdown">
<option value="">
<% for allshoe in @allshoe %>
<option value="<%= allshoe.decoration %>"><%= allshoe.decoration %></option>
<% end %>
</select>
</p>
<select multiple id="socks" name="socksselected[]">
<% for sock in @sock %>
<option selected value="<%= sock.name %>">
<%= sock.name %></option>
<% end %>
</select>
<input type="checkbox" name="shipit" id="shipt" checked="true">
<p>Enter a decoration for the bottom:
<input id="bottomdecorationinput" type="text" name="bottomdecorationinput" size="56"></p>
<p>Or, select a decoration from the list:
<select id="bottomdecorationdropdown" name="bottomdecorationdropdown">
<option value="">
<% for allshoe in @allshoe %>
<option value="<%= allshoe.decoration %>"><%= allshoe.decoration %></option>
<% end %>
</select>
</p>
<input type="submit" id="savethisorder" value="Save Order or Update Order">
<% end %>
鞋子 Controller
class ShoesController < ApplicationController
# GET /shoes
# GET /shoes.xml
def index
@shoe = Shoe.all
@sock = Sock.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @shoes }
end
end
# GET /shoes/1
# GET /shoes/1.xml
def show
@shoe = Shoe.find(params[:id])
@sock = Sock.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @shoe }
end
end
# GET /shoes/new
# GET /shoes/new.xml
def new
@shoe = Shoe.new
@sock = Sock.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @shoe }
end
end
# GET /shoes/1/edit
def edit
@shoe = Shoe.find(params[:id])
@sock = Sock.find(params[:id])
respond_to do |format|
format.html # edit.html.erb
format.xml { render :xml => @activity }
end
end
# POST /shoes
# POST /shoes.xml
def create
@shoe = Shoe.new(params[:shoe])
@shoe.name = params[:shoename]
if !params[:topdecorationdropdown].blank?
@shoe.decoration = params[:topdecorationinput]
else
@shoe.decoration = params[:topdecorationdropdown]
topdecorationdropdown_array = params[:topdecorationdropdown].split(',').collect(&:strip)
@shoe.sparkletopdecorationdropdown = Allshoe.find(:first, :conditions => {:sparkle => topdecorationdropdown_array[0]).sparkle
end
socks = params[:socksselected]
socks.each do |sock_info|
sock = Sock.new
sock.sockdescription = sock_info
sock.shoe = @shoe
sockdecoration_array = sock_info.split(',').collect(&:strip)
@sockisaset = Allshoe.find(:first, :conditions => {:decoration => sockdecoration_array[0]})
if @sockisaset
sock.sparkle = Allshoe.find(:first, :conditions => {:sparkle => sockdecoration_array[0]).sparkle
else
sock.sparkle = nil
end
sock.save
end
if !params[:shipit].blank?
@shoe.shipit = 1
else
@shoe.shipit = 0
end
if !params[:bottomdecorationdropdown].blank?
@shoe.decoration = params[:bottomdecorationinput]
else
@shoe.decoration = params[:bottomdecorationdropdown]
bottomdecorationdropdown_array = params[:bottomdecorationdropdown].split(',').collect(&:strip)
@shoe.sparklebottomdecorationdropdown = Allshoe.find(:first, :conditions => {:sparkle => bottomdecorationdropdown_array[0]).sparkle
end
end
respond_to do |format|
if @shoe.save
format.html { redirect_to "/store" }
format.xml { render :xml => @shoe, :status => :created}
else
format.html { render :action => "new" }
format.xml { render :xml => @shoe.errors, :status => :unprocessable_entity }
end
end
end
# PUT /shoes/1
# PUT /shoes/1.xml
def update
@shoe = Shoe.find(params[:id])
respond_to do |format|
if @shoe.update_attributes(params[:shoe])
flash[:notice] = 'Shoe was successfully updated.'
format.html { redirect_to "/store" }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @shoe.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /shoes/1
# DELETE /shoes/1.xml
def destroy
@shoe = Shoe.find(params[:id])
@shoe.destroy
respond_to do |format|
format.html { redirect_to "/store" }
format.xml { head :ok }
end
end
end
鞋款
class Shoe < ActiveRecord::Base
belongs_to :footwear
has_many :socks, :dependent => :destroy
end
最佳答案
上面给出的代码受到 SQL 注入(inject)的保护。 ROR 中可以进行注入(inject),但通常在构建查询时直接在 find by sql 命令中使用变量时发生。
对于 EX:
sq = "Select * from users where id = {params[:id]}"
res = User.find_by_sql(sql)
在上述情况下,可以通过在 params[:id] 中发送适当的语句来完成 SQL 注入(inject)。上面同样的代码可以写成下面这样来防止注入(inject)。
sq = "Select * from users where id = ?"
res = User.find_by_sql([sql,params[:id]])
上面编写的代码是安全的,不会受到 SQL 注入(inject)的影响。
关于mysql - 此 Ruby on Rails 代码是否容易受到 SQL 注入(inject)攻击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18326010/
我想创建一个游戏,您可以在其中尝试避开“攻击”您的物体(圆圈)。我这样做的方式: 首先计算对象和我之间的 x_and y 差值(在这段代码中 AI_x 是对象的 x 位置(AI_y:y 位置),x,y
前言 传统的 DDOS 防御通常使用“硬抗”的方式,导致开销很大,而且有时效果并不好。例如使用 DNS 切换故障 IP 的方案,由于域名会受到缓存等因素的影响通常有分钟级延时,前端难以快速生效。例
我们目前正在使用 OWASP Antisamy 项目来保护我们的应用程序免受 XSS 攻击。当任何给定的表单提交给服务器时,每个输入字段都会被清理。它工作正常,但我们在公司名称、组织名称等字段上遇到问
正则表达式: ^\d+(\.\d+)*$ 我试图打破它: 1234567890.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.
我正在创建一个网页,用户可以在其中交互并在远程计算机上执行基本的文件系统操作(创建文件/目录、删除文件/目录、导航文件系统)。 该网页是基本的 HTML(UTF-8 编码)和 Javascript。我
两个客户端 Alice 和 Bob 使用服务器登录并通过服务器交换消息。登录时,他们都发送他们的公钥以存储在服务器上。当 Alice 想与 Bob 通话时,她用 Bob 的公钥加密一个对称 key ,
一直在阅读 MitB 攻击,有些事情让我担心。 来自 WIKI : The use of strong authentication tools simply creates an increased
很难说出这里问的是什么。这个问题是模棱两可的、模糊的、不完整的、过于宽泛的或修辞的,无法以目前的形式得到合理的回答。如需帮助澄清这个问题以便重新打开它,visit the help center .
我正在使用 Summernote 所见即所得编辑器(如下所示),发现它使用 HTML 标签来格式化文本。 如何保护我的应用程序免受 XSS 攻击?我将输入存储为纯文本,并使用输出:{!! $body
我有一个应用程序,用户可以在其中注册并输入他们的手机和其他数据。 为了验证用户是否有效,在我将其保存到我的数据库之前,我向用户发送了一 strip 有代码的短信。之后他们应该在表单中输入代码。 问题是
由于 xpath 注入(inject)攻击正在攻击网站,因此我们需要保护 xml 文档作为 xpath 查询参数化的解决方案。如果有人可以解释xpath查询的参数化是什么意思,请帮忙?以及这种参数化如
我想知道电子邮件地址是否可以用于 XSS 攻击。 假设有一个网站,您可以在其中注册并提供他的电子邮件地址。如果有人想攻击给定的网站,他或她可能会创建一个电子邮件地址,例如: ""@stmpname
这可能更适合 Serverfault,但许多只来这里的 web 开发人员可能会从这个问题的可能答案中受益。 问题是:您如何有效地保护自己免受针对您的网络服务器的拒绝服务攻击? 看完这篇 article
检查引荐来源网址是否足以防止跨站点请求伪造攻击?我知道引荐来源网址可能会被欺骗,但是攻击者有没有办法为客户端做到这一点?我知道代币是常态,但这行得通吗? 最佳答案 这是一个 3 年前的问题,有四个不同
我从输入类型中获取值,如下所示: var num = $(document).find('#num').val(); 我尝试使用以下代码来避免输入类型受到 XSS 攻击: num = j
我需要使用超链接动态更新以下代码中的“src”链接,该超链接又指向另一个 .js 文件。以下只是用于“src”的示例 URL。我的问题是,允许在运行时更改“src”,此代码是否容易受到 XSS 攻击?
我在 OWASP 和网络上看到了很多关于如何避免/防止 XSS 攻击的信息。但是,我还没有找到任何提及在检测到 XSS 攻击时如何响应的内容。 应返回什么 HTTP 状态代码(即 400、403...
保护站点免受 DoS 攻击的最佳方法是什么?知道流行的网站/服务如何处理这个问题吗? 应用程序、操作系统、网络、托管级别有哪些工具/服务? 如果有人能分享他们处理过的真实经历,那就太好了。 谢谢 最佳
我到处寻找缓解方法 this vulnerability ,我发现类似: Just disable http compression. 嗯,这很痛苦,因为压缩可以节省大量带宽,而且还可以让您的网页加载
服务器,一个运行 Spring 2.5.6 的独立 SE 应用程序和一个嵌入式 jetty 。客户端、Swing 应用程序使用 HttpInvoker 连接到服务器。 服务器公开了很多服务,现在出现了
我是一名优秀的程序员,十分优秀!