如何对呈现到页面并最终在 URL 中使用的值进行编码?

发布于 2024-09-12 10:23:39 字数 689 浏览 0 评论 0原文

我有一个脚本,它作为跟踪解决方案 (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 &#123;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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沧桑㈠ 2024-09-19 10:23:39

这些值只需进行 URL 编码即可传输到客户端。如果信息由客户显示,那么他们有责任确保自己保护自己免受 xss 攻击,而不是您的。

<script>
var et_cart= 'lars+%FCmlaut%2C10.0%2C100045%3Bnice+jacket%2C20.00%2C29887';
</script>

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.

<script>
var et_cart= 'lars+%FCmlaut%2C10.0%2C100045%3Bnice+jacket%2C20.00%2C29887';
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文