0

在任何事情之前,我除了回答“这是一个 BIGGGGG 安全问题”之外,没有问题,但是我想详细回答风险。

这是我的问题:我正在使用 php 来自动保护一些文件夹,而无需编辑里面的文件。然后它通过.htaccess。问题是创建了 .htaccess 和 .htpasswd 文件,具有良好的访问权限(文件夹等等),但是它总是返回 500 内部错误,当我检查错误日志时,没有任何关于该错误的具体说明. 如果我手动创建文件,它可以工作。

这是php代码:

$htpath = '../../.htpasswds/'.$ref;
mkdir($htpath, 0750);               
$htpass = $htpath.'/.htpasswd';
$ourFileHandle = fopen($htpass, 'wb') or die("Can't create .htpasswd file.");
$chars = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789";
$special_chars = '-_@#)([]|-=';
$pass = $chars[rand(0,strlen($chars)-1)].$special_chars[rand(0,strlen($special_chars)-1)].$chars[rand(0,strlen($chars)-1)].rand(0, 9999).$chars[rand(0,strlen($chars)-1)].$special_chars[rand(0,strlen($special_chars)-1)];
$content = 'client_access'.$id.':'.crypt($pass, base64_encode($pass));
fwrite($ourFileHandle, $content) or die("Can't create .htaccess file.");                
fclose($ourFileHandle);

$htpass = $path.'/.htaccess';
$handle = fopen($htpass, 'wb') or die("Can't create .htpasswd file.");
$content = 'AuthType "Basic" ';
$content .= "\n";
fwrite($handle, $content);              
$content = 'AuthUserFile "/home/thedigi1/.htpasswds/'.$ref.'/.htpasswd" ';
$content .= "\n";               
fwrite($handle, $content);
$content = 'Require valid-user ';
$content .= "\n";               
fwrite($handle, $content);
$content = 'RewriteOptions inherit';
$content .= "\n";               
fwrite($handle, $content) or die("Can't create .htaccess file.");
fclose($handle);

您对可能导致问题的原因有任何想法吗?或者也许有更好的解决方案?

非常感谢!

编辑:这是创建的 htaccess 的代码:

AuthType "Basic" 
AuthUserFile "/home/thedigi1/.htpasswds/A-161012-47/.htpasswd" 
Require valid-user 
RewriteOptions inherit

但是我已经通过 htaccess 进行了身份验证,可以访问创建 htaccess 的 php 文件,你认为这可能是问题吗?

4

1 回答 1

0

问题解决了:

htaccess 文件缺少 AuthName 参数

AuthName "text"

我不得不将 .htpasswd 文件夹改成 755 而不是 750。

感谢您的回答!

于 2012-10-17T14:33:36.300 回答