如何为通过 URL 传递变量创建额外的保护? [JavaScript]

发布于 2025-01-07 00:12:12 字数 366 浏览 2 评论 0原文

我使用变量通过 URL(即“.derp.html?name=derp?lname=herp”)传递到弹出窗口(它使用这些参数来预填充页面上的信息)。虽然这些页面是内部的,但我想创建更多的安全性。我不希望有人输入自己的链接并提交包含虚假值的表单。

我正在考虑在打开链接后运行一个函数,该函数会打开弹出窗口,并通过变量而不是通过 URL 将参数发送到新窗口。但是,我仍然需要将值发送到 java 脚本函数...

我还能做些什么来更安全吗?

编辑:让我重新表述一下......这不是公开的,这是内部的。我不希望用户尝试侵入系统来创建虚假表单。

我无法进行服务器端验证,因为我正在使用非常古老的方法,例如 IE 中的表格数据控制。没有真正的数据库来验证任何东西。

I'm using variable passing through a URL (ie ".derp.html?name=derp?lname=herp") to a popup (which uses these parameters to prefill information on the page). Although these pages are internal, I want to create more security. I do not want someone to type in their own link and submit a form with fake values.

I was thinking of having a function run once the link is opened instead, which opens the popup, and sends the parameters through variables to the new window, instead of through the URL. However, I would still need to send values to the java script function...

Anything else I can do to be more secure?

EDIT: Let me rephrase then... This is not public, this is internal. I'm not expecting users to try and hack into the system to create fake forms.

I can't do server-side validation because I'm working with very old methods like tabular data control in IE. There is no real data base to verify anything.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

我家小可爱 2025-01-14 00:12:12

您可以POST这些值,而不是将它们附加到 URL。这就是 HTML 表单的用途。例如:

<form action="derp.html" method="POST" target="myNewWindow">
    <input type="hidden" value="derp" name="name"/>
    <input type="hidden" value="derp" name="lname"/>
    <a href="#" onclick="window.open("myNewWindow");this.parentNode.submit()">Click to open in a new window</a>
</form>

You can POST the values, instead of appending them to the URL. This is what HTML forms are for. For example:

<form action="derp.html" method="POST" target="myNewWindow">
    <input type="hidden" value="derp" name="name"/>
    <input type="hidden" value="derp" name="lname"/>
    <a href="#" onclick="window.open("myNewWindow");this.parentNode.submit()">Click to open in a new window</a>
</form>
黑凤梨 2025-01-14 00:12:12

您有两个选择

1)不使用 GET 方法(在 URL 中发送参数),而是使用 POST 方法,并且参数将不再位于 HTML URL 中,您可以通过 Javascript 来完成。然而,想要向您的服务器发送虚假值的人仍然可以这样做,只是有点困难。

2) 创建一个哈希函数(Javascript 代码),在提交 URL 之前对所有参数进行编码,并在服务器端收到后对其进行解码。 http://en.wikipedia.org/wiki/Hash_function

无论哪种方式,都不会为您提供 100 % 安全性,但您仍然应该在服务器端执行参数验证。

You have two options

1) Instead of using GET method (sending parameter in URL), use POST method and the parameters will not be in HTML URL anymore and you can do it by Javascript. However, a person who want to send fake values to you server, still is able to do so, but it's just a bit harder.

2) Create a hash function(Javascript code) which encode all the parameters before submit the URL and decode it upon received on server side. http://en.wikipedia.org/wiki/Hash_function

Either way, will not provide you 100% security, and still you should perform parameter validation on-server side.

虐人心 2025-01-14 00:12:12

您可以将其更改为发布请求...但是如果逻辑是前端,这就是您所能做的所有事情...除了混淆变量名称之外。

you can change it to a post request...but that's about all you can do if the logic is front-side...other than obfuscating the variable names.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文