douzhi2012 2019-01-18 21:00
浏览 630

如何在源代码中隐藏POST请求中使用的参数?

I'm wanting to send variables to a waiting PHP document using the POST method, but these variables are used as arguments to do things such as delete, hide, etc.

The problem is that I only know of two ways to do this:

  1. An href attribute where you build your URL
  2. Using an XMLHttpRequest

There is a security risk with both of these methods as they will show the variables within the source code. This could lead to someone having control over other user's data through manipulation of the URL. All they would need is the readily available variable and the user name.

function usrVisToggle(){
    var adjNum = Number(document.getElementById('lineNum').value);
    var adjSend = new XMLHttpRequest();
    adjSend.open('POST', 'https://000webhostapp.com');
    adjSend.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    adjSend.send('argument=4&adjusted=' + adjNum, false);
    location.reload();

The above is an example of how my code works right now.

The problem is within the argument=4. This will show in the source code and once you get the argument you can begin toggling everyones' data to be visible/invisible. Building your own URL to use in HTML poses the same risk.

What would be some ways around this?

  • 写回答

2条回答 默认 最新

  • 普通网友 2019-01-18 21:07
    关注

    Not two minutes after this post I realized that instead of focusing on the manipulation codes, I could just make an impossibly hard to guess user code and save to database. This renders the argument=4 almost moot because you would have to break into the database to steal the information, or get lucky and guess a really long string that relates to the user.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用