如何对呈现到页面并最终在 URL 中使用的值进行编码?
我有一个脚本,它作为跟踪解决方案 (etracker) 的一部分呈现到 html 页面。
它是这样的:
<script>
var et_cart= 'nice shoes,10.0,100045;nice jacket,20.00,29887';
</script>
这将通过一些我无法控制的 JavaScript 传输到跟踪解决方案的服务器。它将最终成为 2 个项目。这些项目在源中用分号分隔(在“100045”之后)。
显然我需要对将要呈现的值进行 Html 编码和 Javascript 编码。 我首先进行 Html 编码,然后删除单引号。
这可行,但我对法语和德语中的特殊字符有疑问,例如元音变音(ü,ä...)。 他们渲染类似 {.使用 lars ümlaut 作为文章时脚本的输出为:
<script>
var et_cart= 'lars {mlaut,10.0,100045;nice jacket,20.00,29887';
</script>
跟踪解决方案将分号评估为项目分隔符。
跟踪解决方案的支持告诉我对值进行 url 编码。这行得通吗? 我猜 URL 编码并不能阻止任何 xss 攻击。可以先进行 url 编码和 html 编码,然后再进行 javascript 编码吗?
I have a script that is rendered to an html page as a part of a tracking solution (etracker).
It is something like this:
<script>
var et_cart= 'nice shoes,10.0,100045;nice jacket,20.00,29887';
</script>
This will be transmitted to the server of the tracking solution by some javascript that I don't control. It will end up as 2 items. The items are separated by a semicolon in the source (after '100045').
I obviously need to Html-encode and Javascript-encode the values that will be rendered.
I first Html-encode and after that remove single quotes.
This works, but I have an issue with special characters in french and german e.g. umlaut (ü, ä...).
They render something like {. The output of the script when using lars ümlaut as the article is:
<script>
var et_cart= 'lars {mlaut,10.0,100045;nice jacket,20.00,29887';
</script>
The semicolon is evaluated as an item separator by the tracking solution.
The support of the tracking solution told me to url-encode the values. Can this work?
I guess URL-encoding doesn't stop any xss-atacks. Is it ok to first url-encode and html-encode, then javascript-encode after it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些值只需进行 URL 编码即可传输到客户端。如果信息由客户显示,那么他们有责任确保自己保护自己免受 xss 攻击,而不是您的。
The values only need to be URL encoded to transmit to the client. If the information is being displayed by the client it's their responsibility to ensure they are protecting themselves against xss attacks, not yours.