AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题

问题[http-basic-authentication](server)

Martin Hope
Black
Asked: 2021-10-13 05:06:04 +0800 CST

.htaccess - 从基本身份验证保护中排除文件夹

  • 3

我有一个网站,如果不输入基本身份验证凭据,任何人都不得进入。

但是,我需要每个人都可以访问媒体文件夹,因为我们正在使用创建 PDF 的第三方扩展,并且我们只能在媒体可访问的情况下对其进行全面测试。

媒体文件夹位于/var/www/company/pub/media.

域 ( www.example.com ) 指向/var/www/company/pub,因此pub文件夹是入口点。

这是我的 .htaccess 尝试(/var/www/company/.htaccess):

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/pub/
RewriteCond %{REQUEST_URI} !^/setup/
RewriteCond %{REQUEST_URI} !^/update/
RewriteCond %{REQUEST_URI} !^/dev/
RewriteRule .* /pub/$0 [L]
DirectoryIndex index.php

AuthType Basic
AuthName "Protected"
AuthUserFile "/var/www/company/.htpasswd"

# Exclude media folder from basic auth
SetEnvIf Request_URI "^/media/*" media

Order allow,deny
Require valid-user
Allow from env=media
Deny from env=!media
Satisfy any

但是如果我尝试调用http://www.example.com/media/someimage.jpg那么我仍然会得到基本的身份验证登录提示。

环境:

阿帕奇 2.4.41 (Ubuntu)

.htaccess apache2 http-basic-authentication
  • 2 个回答
  • 2015 Views
Martin Hope
Major Kuprich
Asked: 2021-10-01 10:21:08 +0800 CST

带有基本身份验证的清漆返回 401

  • 1

我尝试使用以下解决方案在具有基本身份验证身份验证的服务器上配置 Varnish:

  • https://stackoverflow.com/a/40424168/7202171
  • https://blog.tenya.me/blog/2011/12/14/varnish-http-authentication/#comment-2882579903

但这无济于事。Varnish 日志仍然显示 401 错误:

varnishlog -g raw -i Backend_health

         0 Backend_health - mag2.default Still sick 4--X-R- 0 5 10 0.001574 0.000000 HTTP/1.1 401 Unauthorized

我的清漆配置(4.0 版):

vcl 4.0;

import std;
# The minimal Varnish version is 4.0
# For SSL offloading, pass the following header in your proxy server or load balancer: 'X-Forwarded-Proto: https'

backend default {
    .host = "127.0.0.1";
    .port = "8080";
    .first_byte_timeout = 600s;
    .probe = {
        .url = "/health_check.php";
        .timeout = 2s;
        .interval = 5s;
        .window = 10;
        .threshold = 5;
   }
}

acl purge {
    "localhost";
}

sub vcl_recv {
    if (! req.http.Authorization ~ "Basic ZGV2OmRldg=") {
    return(synth(401, "Restricted"));
    }

    if (req.method == "PURGE") {
        if (client.ip !~ purge) {
            return (synth(405, "Method not allowed"));
        }
        # To use the X-Pool header for purging varnish during automated deployments, make sure the X-Pool header
        # has been added to the response in your backend server config. This is used, for example, by the
        # capistrano-magento2 gem for purging old content from varnish during it's deploy routine.
        if (!req.http.X-Magento-Tags-Pattern && !req.http.X-Pool) {
            return (synth(400, "X-Magento-Tags-Pattern or X-Pool header required"));
        }
        if (req.http.X-Magento-Tags-Pattern) {
          ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern);
        }
        if (req.http.X-Pool) {
          ban("obj.http.X-Pool ~ " + req.http.X-Pool);
        }
        return (synth(200, "Purged"));
    }

    if (req.method != "GET" &&
        req.method != "HEAD" &&
        req.method != "PUT" &&
        req.method != "POST" &&
        req.method != "TRACE" &&
        req.method != "OPTIONS" &&
        req.method != "DELETE") {
          /* Non-RFC2616 or CONNECT which is weird. */
          return (pipe);
    }

    # We only deal with GET and HEAD by default
    if (req.method != "GET" && req.method != "HEAD") {
        return (pass);
    }

    # Bypass shopping cart and checkout
    if (req.url ~ "/checkout") {
        return (pass);
    }

    # Bypass health check requests
    if (req.url ~ "/pub/health_check.php") {
        return (pass);
    }

    # Set initial grace period usage status
    set req.http.grace = "none";

    # normalize url in case of leading HTTP scheme and domain
    set req.url = regsub(req.url, "^http[s]?://", "");

    # collect all cookies
    std.collect(req.http.Cookie);

    # Compression filter. See https://www.varnish-cache.org/trac/wiki/FAQ/Compression
    if (req.http.Accept-Encoding) {
        if (req.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|flv)$") {
            # No point in compressing these
            unset req.http.Accept-Encoding;
        } elsif (req.http.Accept-Encoding ~ "gzip") {
            set req.http.Accept-Encoding = "gzip";
        } elsif (req.http.Accept-Encoding ~ "deflate" && req.http.user-agent !~ "MSIE") {
            set req.http.Accept-Encoding = "deflate";
        } else {
            # unknown algorithm
            unset req.http.Accept-Encoding;
        }
    }

    # Remove all marketing get parameters to minimize the cache objects
    if (req.url ~ "(\?|&)(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=") {
        set req.url = regsuball(req.url, "(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=[-_A-z0-9+()%.]+&?", "");
        set req.url = regsub(req.url, "[?|&]+$", "");
    }

    # Static files caching
    if (req.url ~ "^/(pub/)?(media|static)/") {
        # Static files should not be cached by default
        return (pass);

        # But if you use a few locales and don't use CDN you can enable caching static files by commenting previous line (#return (pass);) and uncommenting next 3 lines
        #unset req.http.Https;
        #unset req.http.X-Forwarded-Proto;
        #unset req.http.Cookie;
    }

     # Authenticated GraphQL requests should not be cached by default
    if (req.url ~ "/graphql" && req.http.Authorization ~ "^Bearer") {
        return (pass);
    }

unset req.http.Authorization;
    return (hash);
}

sub vcl_hash {
    if (req.http.cookie ~ "X-Magento-Vary=") {
        hash_data(regsub(req.http.cookie, "^.*?X-Magento-Vary=([^;]+);*.*$", "\1"));
    }

    if (req.url ~ "/graphql") {
        call process_graphql_headers;
    }

    # To make sure http users don't see ssl warning
    if (req.http.X-Forwarded-Proto) {
        hash_data(req.http.X-Forwarded-Proto);
    }
    
}

sub process_graphql_headers {
    if (req.http.Store) {
        hash_data(req.http.Store);
    }
    if (req.http.Content-Currency) {
        hash_data(req.http.Content-Currency);
    }
}

sub vcl_backend_fetch {
    # auth with admin:admin
    set bereq.http.Authorization = "Basic ZGV2OmRldg==";
}

sub vcl_backend_response {

    set beresp.grace = 3d;

    if (beresp.http.content-type ~ "text") {
        set beresp.do_esi = true;
    }

    if (bereq.url ~ "\.js$" || beresp.http.content-type ~ "text") {
        set beresp.do_gzip = true;
    }

    if (beresp.http.X-Magento-Debug) {
        set beresp.http.X-Magento-Cache-Control = beresp.http.Cache-Control;
    }

    # cache only successfully responses and 404s
    if (beresp.status != 200 && beresp.status != 404) {
        set beresp.ttl = 0s;
        set beresp.uncacheable = true;
        return (deliver);
    } elsif (beresp.http.Cache-Control ~ "private") {
        set beresp.uncacheable = true;
        set beresp.ttl = 86400s;
        return (deliver);
    }

    # validate if we need to cache it and prevent from setting cookie
    if (beresp.ttl > 0s && (bereq.method == "GET" || bereq.method == "HEAD")) {
        unset beresp.http.set-cookie;
    }

   # If page is not cacheable then bypass varnish for 2 minutes as Hit-For-Pass
   if (beresp.ttl <= 0s ||
       beresp.http.Surrogate-control ~ "no-store" ||
       (!beresp.http.Surrogate-Control &&
       beresp.http.Cache-Control ~ "no-cache|no-store") ||
       beresp.http.Vary == "*") {
       # Mark as Hit-For-Pass for the next 2 minutes
        set beresp.ttl = 120s;
        set beresp.uncacheable = true;
    }

    return (deliver);
}

sub vcl_deliver {
    if (resp.http.X-Magento-Debug) {
        if (resp.http.x-varnish ~ " ") {
            set resp.http.X-Magento-Cache-Debug = "HIT";
            set resp.http.Grace = req.http.grace;
        } else {
            set resp.http.X-Magento-Cache-Debug = "MISS";
        }
    } else {
        unset resp.http.Age;
    }

    # Not letting browser to cache non-static files.
    if (resp.http.Cache-Control !~ "private" && req.url !~ "^/(pub/)?(media|static)/") {
        set resp.http.Pragma = "no-cache";
        set resp.http.Expires = "-1";
        set resp.http.Cache-Control = "no-store, no-cache, must-revalidate, max-age=0";
    }

    unset resp.http.X-Magento-Debug;
    unset resp.http.X-Magento-Tags;
    unset resp.http.X-Powered-By;
    unset resp.http.Server;
    unset resp.http.X-Varnish;
    unset resp.http.Via;
    unset resp.http.Link;
}

sub vcl_hit {
    if (obj.ttl >= 0s) {
        # Hit within TTL period
        return (deliver);
    }
    if (std.healthy(req.backend_hint)) {
        if (obj.ttl + 300s > 0s) {
            # Hit after TTL expiration, but within grace period
            set req.http.grace = "normal (healthy server)";
            return (deliver);
        } else {
            # Hit after TTL and grace expiration
            return (fetch);
        }
    } else {
        # server is not healthy, retrieve from cache
        set req.http.grace = "unlimited (unhealthy server)";
        return (deliver);
    }
}

sub vcl_synth {
  if (resp.status == 401) {
    set resp.status = 401;
    set resp.http.WWW-Authenticate = "Basic";
    return(deliver);
  }
}
magento nginx varnish http-basic-authentication authorization
  • 1 个回答
  • 570 Views
Martin Hope
Jungroy
Asked: 2021-08-05 06:08:18 +0800 CST

我不确定我的服务器上的基本身份验证是否受到保护

  • 2

这可能是一个非常愚蠢的问题,但我必须确保我对此感到满意。

我使用基本身份验证设置了一个 HTTPS 服务器,但是当我连接到身份验证页面时,浏览器告诉我连接不安全,并在我登录后告诉我连接是安全的。我想知道这是否安全,如果没有,我怎样才能使它安全?

配置(NGINX):

server {
    listen 80;
    server_name sub.example.com;

    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl http2;
    server_name sub.example.com;

    ssl_ceerificate (certpath);
    ssl_certificate_key (certkeypath);
    ssl_trusted_certificate (anotherpath);
    ssl_dhparam (dhparam);

    ssl_protocols TLSv1.2 TLSv1.3;                                                                                                                                          
    ssl_prefer_server_ciphers on;                                                                                                                                           
    ssl_ciphers TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA25$
    ssl_ecdh_curve secp384r1;                                                                                                                                               
    ssl_session_timeout 10m;                                                                                                                                                
    ssl_session_cache shared:SSL:10m;                                                                                                                                       
    ssl_session_tickets off;                                                                                                                                                
    ssl_stapling on;                                                                                                                                                        
    ssl_stapling_verify on;                                                                                                                                                 

    add_header X-Content-Type-Options "nosniff" always;                                                                                                                     
    add_header X-Frame-Options "SAMEORIGIN" always;                                                                                                                         
    add_header X-XSS-Protection "1; mode=block"                                                                                                                                                            

    location / {                                                                                                                                                    
        auth_basic 'Nothing to see here';                                                                                                                                                                                                

        proxy_pass http://localhost:4000/;                                                                                                                     
    }
}

截屏

security https http-basic-authentication
  • 1 个回答
  • 70 Views
Martin Hope
Asmodean
Asked: 2021-07-26 05:18:22 +0800 CST

Nginx Http 基本认证安全

  • 1

所以可以说我在端口 6000 上托管了类似 netdata 仪表板的东西。

然后我 nginx 将它反向代理到子域 netdata.domain.com

虽然在 nginx.conf 中应用了基本身份验证以允许站点范围的保护。

我的问题是,由于我与 netdata.domain.com 的连接是 http 而不是 https,因此我的数据未加密。那么在这个连接下登录到 nginx 基本身份验证不会基本上暴露 MITM 攻击的密码吗?

但是,如果我在真实 ip 之间添加 cloudflare,那会提供一层代理,并且基本上会增加很多困难,对吗?

我不知道我的担心是否有效。

nginx http-basic-authentication
  • 1 个回答
  • 493 Views
Martin Hope
Asmodean
Asked: 2021-07-25 21:54:15 +0800 CST

如何从 Nginx 子域中排除基本身份验证

  • 0

我在 nginx.conf 中添加了两行基本身份验证。

这样反向代理下的所有子域块都受密码保护。但我确实有一些我不希望它有那个。

为了让它们通过,我需要在这些服务器块中包含什么?

谢谢!

抱歉,我不知道通配符是什么,也不知道它是否适用于这种情况。

subdomain nginx http-basic-authentication
  • 1 个回答
  • 566 Views
Martin Hope
CodeFlo
Asked: 2020-11-29 04:28:47 +0800 CST

我可以在 Apache 中对 HTTP 基本身份验证使用速率限制吗?

  • 3

所以我在我的服务器上运行了一些流行的 Web 应用程序。我希望这些可以从任何计算机上访问,而不会造成太多漏洞。

我使用 Apache 2.4.29 作为我的 HTTP 服务器。我目前对攻击者隐藏应用程序中潜在安全漏洞的想法是AuthType Basic为相关虚拟主机启用 HTTP 基本身份验证 () 作为附加安全层。当然,我只允许 SSL 连接。

现在这一切都很容易完成。但我的问题是:我怎样才能最好地避免使用 HTTP 基本身份验证的蛮力式攻击?即,如何启用速率限制?

我目前的计划是这样的:

由于我使用 ufw(简单防火墙)来限制 SSH 连接,我想我可以在用于 HTTPS 的特定端口上做同样的事情。但是,我看到了两个问题:

  1. 攻击者不能在Connection: Keep-Alive不重新连接的情况下使用并继续尝试不同的密码吗?所以限制传入连接在这里没有任何用处。
  2. 如果我以某种方式禁用Connection: Keep-Alive,我想我会遇到底层 Web 应用程序的问题,因为它们需要大量单独的连接,以便浏览器可以检索其他文件。

如果我可以指示 Apache 只为经过身份验证的用户保持连接并在尝试失败时断开连接,那将是完美的。有没有办法做到这一点?我实际上不确定默认行为是什么,并且对 HTTP 了解不够,无法轻松测试。

Apache 中的KeepAliveandMaxKeepAliveRequests设置显然可以基于每个虚拟主机进行配置,但我不确定如何根据成功的身份验证更改这些设置。

security rate-limiting apache-2.4 ufw http-basic-authentication
  • 1 个回答
  • 746 Views
Martin Hope
frlan
Asked: 2016-11-24 07:58:40 +0800 CST

通过 http auth 和大量请求提高 Nginx 的性能

  • 1

我在 Nginx 服务器后面通过 fpm 运行了一个 PHP 端。对于 $reasons,我们需要在该设置之前有一个 http 基本身份验证,所以我最终设置为:

#… server section ….

    auth_basic "Restricted";
    auth_basic_user_file /path/to/htpasswd;

#… some more locations …

location ~ \.php$ {


    fastcgi_pass 127.0.0.1:9001;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include /etc/nginx/fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param HTTPS off;
    fastcgi_param APPLICATION_ENV production;
}

哪个有效-但速度很慢。它仅以 100% 的 cpu 利用率处理一个又一个请求。如果我删除 http_auth 它的工作速度很快。

我的问题是:如何改进设置以确保即使使用 http_auth 性能也不错?

以供参考:

# nginx -V
nginx version: nginx/1.8.1
built with OpenSSL 1.0.2j  26 Sep 2016
TLS SNI support enabled
configure arguments: --prefix=/usr --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error_log --pid-path=/run/nginx.pid --lock-path=/run/lock/nginx.lock --with-cc-opt=-I/usr/include --with-ld-opt=-L/usr/lib --http-log-path=/var/log/nginx/access_log --http-client-body-temp-path=/var/lib/nginx/tmp/client --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --with-ipv6 --with-libatomic --with-pcre --with-http_realip_module --add-module=external_module/ngx_devel_kit-0.2.19 --add-module=external_module/lua-nginx-module-0.9.15 --add-module=external_module/modsecurity-2.9.1-nginx-207c85d/nginx/modsecurity --with-http_ssl_module --without-mail_imap_module --without-mail_pop3_module --without-mail_smtp_module --user=nginx --group=nginx
php nginx http-basic-authentication
  • 2 个回答
  • 1002 Views
Martin Hope
hellb0y77
Asked: 2016-10-26 06:07:19 +0800 CST

基本身份验证 apache 2.2 绕过 IP

  • 0

如何设置 apache 2.2 的基本身份验证以绕过 IP?我已经关注了这个 wiki http://wiki.apache.org/httpd/BypassAuthenticationOrAuthorizationRequirements,但总是询问密码,也列出了 IP:

<Directory /var/www/html/mydir>
    AuthName "Private"
    AuthType Basic
    AuthUserFile "/etc/httpd/htpasswd"
    Require valid-user
    Order allow,deny
    Allow from 111.111.111.111 222.222.222.222
    Satisfy any
</Directory>

我在haproxy下,但我设置了IP转发,我已经这样设置LogFormat了:

LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

access_log 是:

111.111.111.111 - - [25/Oct/2016:12:35:41 +0200] "GET /index.html HTTP/1.1" 401 487 "-" "Mozilla/5.0 (X11; Linux armv7l; rv:38.0) Gecko/20100101 Firefox/38.0 Iceweasel/38.7.0"
apache-2.2 authentication http-basic-authentication mod-authz-host
  • 1 个回答
  • 1904 Views
Martin Hope
Tuan Anh Tran
Asked: 2016-08-02 19:20:51 +0800 CST

是否可以仅为 1 个特定域绑定设置基本身份验证?

  • 2

我只想为 1 个域绑定启用基本身份验证,并让其余的公共访问。IIS可以做到这一点吗?

iis http-basic-authentication
  • 1 个回答
  • 2003 Views
Martin Hope
Christos Hayward
Asked: 2016-06-23 12:52:18 +0800 CST

阿帕奇着火了(AH00025)。怎么修?

  • 5

我试图让 Apache 2.4.10 执行.htaccess文件中指定的基本身份验证(在 HTTPS 下)。我将一个目录的设置更改为AllowOverride all,它开始只提供普通的 500 页。将该目录恢复到AllowOverride none似乎没有固定的东西。

我在日志中发现的错误似乎都将请求的相对 URL 解释为授权用户名,并发出呱呱叫:

[2016 年 6 月 22 日星期三 20:34:00.565683] [core:crit] [pid 24994] [client ____:51295] AH00025:配置错误:无法检查用户:/writing/icons/rublev_trinity_icon.gif,引用者:____

AH00025 是什么意思?我找到了一些页面,例如https://httpd.apache.org/docs/trunk/upgrading.html,但没有明确定义错误代码。

我想要什么 /etc/apache2/mods-enabled/auth* 文件?

apache-2.4 http-basic-authentication
  • 1 个回答
  • 4946 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve