Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 公开表行的ID是否不安全?_Php_Sql_Database - Fatal编程技术网

Php 公开表行的ID是否不安全?

Php 公开表行的ID是否不安全?,php,sql,database,Php,Sql,Database,所以在我的网站上,我有文章。文章可以被投赞成票或反对票 在文章的URL中,您可以非常清楚地看到其ID。例如: www.website.com/articles/14/这是文章的标题 当您想要对文章进行上/下投票时,post请求也会使用文章的ID,而无需任何编码 这是坏习惯还是不安全?如果是这样,最好的选择是什么?感觉这主要是关于讨论的。不确定这个答案是否真的有用/不是很明显。。。但是,假设用户需要经过身份验证才能投票,您可以这样做: <?php $articleId = 123; //th

所以在我的网站上,我有文章。文章可以被投赞成票或反对票

在文章的URL中,您可以非常清楚地看到其ID。例如:

www.website.com/articles/14/这是文章的标题

当您想要对文章进行上/下投票时,post请求也会使用文章的ID,而无需任何编码


这是坏习惯还是不安全?如果是这样,最好的选择是什么?

感觉这主要是关于讨论的。不确定这个答案是否真的有用/不是很明显。。。但是,假设用户需要经过身份验证才能投票,您可以这样做:

<?php
$articleId = 123; //these would be coming from $_GET.
$userId = 5001;
$somethingSalty = 'Constofsomesort' . floor(time() / 3600); //or no time aspect if you prefer

if ($articleId === $article->getId() 
         && $n === hash('sha256', $article->getId() . $user->getId() . $somethingSalty)) {...

ID    NAME
0     [username]
1     [username]
2     [username]
ID      NAME
421456  [username]
197635  [username]
486597  [username]
  • 无法共享投票链接
  • 每个文章/用户都是唯一的,不应被欺骗
  • 缓解“重播攻击”

    • 我不会说它不安全。很多网站在URL中使用ID。在GET或POST请求中,但它也用作路径变量

      如果你认为网站不安全,你可以称之为这一点,因为用户可以编写一个从0到最后一个用户/帖子/产品ID和擦除数据的机器人。但如果使用随机id,则可以避免这种情况。例如,您对表中的每一行使用不同的六位数id。您可以生成随机的六位数代码,并在数据库中还并没有的情况下将其交给行,而不是按升序排列

      因此,不要像这样排行:

      <?php
      $articleId = 123; //these would be coming from $_GET.
      $userId = 5001;
      $somethingSalty = 'Constofsomesort' . floor(time() / 3600); //or no time aspect if you prefer
      
      if ($articleId === $article->getId() 
               && $n === hash('sha256', $article->getId() . $user->getId() . $somethingSalty)) {...
      
      
      ID    NAME
      0     [username]
      1     [username]
      2     [username]
      
      ID      NAME
      421456  [username]
      197635  [username]
      486597  [username]
      
      您可以这样构建它们:

      <?php
      $articleId = 123; //these would be coming from $_GET.
      $userId = 5001;
      $somethingSalty = 'Constofsomesort' . floor(time() / 3600); //or no time aspect if you prefer
      
      if ($articleId === $article->getId() 
               && $n === hash('sha256', $article->getId() . $user->getId() . $somethingSalty)) {...
      
      
      ID    NAME
      0     [username]
      1     [username]
      2     [username]
      
      ID      NAME
      421456  [username]
      197635  [username]
      486597  [username]
      

      -有点不同,但想法是一样的。关注核心问题。回去工作。假设关注点是串行/批量投票?是的,在本例中是批量投票。作为顺序整数,很容易迭代。所以你要么让文章标识符很难猜测(很难循环,尽管没有什么能阻止我放弃它们或其他任何东西)。-要么你采取根据某种标准验证投票本身的方法。“时间节流”,有用户“读”过这篇文章,等等。曾经在一家营销公司工作,在那里人们可以通过观看视频获得报酬。他们必须通过提供视频不同部分显示的3个短代码来验证他们是否观看了视频。不是说你需要测试他们的阅读理解能力,而是。。。我不知道,只是想和大家分享这个故事,真的。我会考虑这个基本混淆。爬行/爬网站点与迭代ID的难度非常小。如果你的网站是可导航的,甚至有点SEO友好,我们可以这么说吗?那么获取第6条数字代码不是一个挑战/是的,这是一个相当简单的过程(取决于行数)。但我认为这是唯一的“不安全”的事情,使用ID作为路径变量,而不是不同意。谈到“关注核心问题,回过头来。”