问题描述
我收到了允许用户放置图片链接的文本框(例如: http://abc.test.gif )&另一个允许用户放置替代文本的文本框(例如:This is test.gif),&一个提交按钮。
当用户点击提交按钮时,程序将生成< img src =http://abc.test.gifalt =This is test.gif>
this string&将其存储到数据库中供以后使用。
我的问题是:是否需要清理图像链接http://abc.test.gif
&例如,我需要使用<$> c $ c> UriUtils.isSafeUri(http://abc.test.gif); & SafeHtmlUtils.fromString(This is test.gif
您是故意允许用户输入任何他想要进入 另外,您将字符串存储在数据库中供以后使用(猜测),所以攻击可能会在稍后发生,当你使用这种字符串在DOM中创建节点时,会产生更多不可预知的结果。 一个解决方案可以是仅将URL和替代字符串存储在数据库中(如果有适当的输入验证),并生成 safe 使用方式如下: 这样你: I got a textbox that allows users to put image link (ex: http://abc.test.gif) & another textbox that allows user to put Alternate text (ex: "This is test.gif"), & a submit button. When a user clicks on submit buton, the program will generate My question is: do i need to sanitize the imagelink For example, do i need to use You are deliberately allowing the user to input anything he want that will go into the Also, you are storing the string in your DB for later use (guessing), so the attack may occur at later time, when you will use such string to create a node in the DOM, with even more unpredictable results. One solution could be to store only the URL and the alternative string in the database (with a proper input validation, if any), and generate the safe To be used like: This way you: 这篇关于对于SafeHtml,我们是否需要清理“链接”在< img src = link>标签,GWT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! src
和 alt
属性的 img
标签,这对任何一种XSS攻击都是开放的。看一看
img
在你需要它的时候使用一个简单的模板,比如f (或以编程方式使用 SafeHtmlBuilder
)。
public interface Template extends SafeHtmlTemplates {
@Template(< img src = \{0} \alt = \{1} \/>)
SafeHtml img(SafeUri uri,SafeHtml alternativeText);
}
template.img(
UriUtils.fromString(yourValidatedDbUrl),
SafeHtmlUtils.fromString(yourValidatedAlternativeText));
<img src="http://abc.test.gif" alt="This is test.gif">
this string & store it into DB for later use."http://abc.test.gif"
& the text in alt tag "This is test.gif"
UriUtils.isSafeUri("http://abc.test.gif");
& SafeHtmlUtils.fromString("This is test.gif"
src
and the alt
attributes of the img
tag. This is indeed open to any kind of XSS attack. Have a look here for some examples that still work in recent browsers.img
snippet right when you need it, with a simple template like the following (or programmatically using SafeHtmlBuilder
).public interface Template extends SafeHtmlTemplates {
@Template("<img src=\"{0}\" alt=\"{1}\"/>")
SafeHtml img(SafeUri uri, SafeHtml alternativeText);
}
template.img(
UriUtils.fromString(yourValidatedDbUrl),
SafeHtmlUtils.fromString(yourValidatedAlternativeText));