gpt4 book ai didi

javascript - 通过 url 以安全的方式共享页面?

转载 作者:行者123 更新时间:2023-12-02 17:50:05 24 4
gpt4 key购买 nike

我的index.php正在对ajax.php进行ajax post调用并获取回显的json结果,然后用js进行解析和显示。所以是POST。我希望能够通过 mydomain/index.php?q=foo&q1=foo1 这样的链接分享该结果。

这是不安全的基本伪代码场景,我想要建议如何以安全的方式实现这一点?

//index.php
//js
$.post('ajax.php', querystring, function(){

collect_result = result;
});

//ajax.php
parse($_POST);
echo json_encode(result);

// I want to be able to share result in way

http://.../index.php?q=foo&q1=foo1

//index.php

if(!empty($_GET['q]))
$querystr = http_build_query($_GET, '', '&');

<div id="div1" style="display:none"><?php echo $querystr; ?></div>

//then get it wuth jquery and make ajax.post()


$.post('ajax.php', $('#div1').html(), function(){

collect_result = result;
});


//BUT THEN USER IS ABLE TO DIRECT INJECT CODE INTO MY HTML (XSS)
//IS THERE SAFE WAY TO DO THIS SHARING VIA LINK???

最佳答案

不确定您是否引用了此内容,但正如 w3schools 中提到的:

htmlspecialchars() 函数将特殊字符转换为 HTML 实体。这意味着它将用 < 和 > 替换 HTML 字符,例如 < 和 >。这可以防止攻击者通过在表单中​​注入(inject) HTML 或 Javascript 代码(跨站点脚本攻击)来利用代码。

关于javascript - 通过 url 以安全的方式共享页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21445043/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com