2017-10-30 7 views
1

양식 및 LDAP 인증을 사용하여 사용자 인증을 처리하는 역방향 프록시가 있습니다. 이것은 잘 작동합니다.로그인 폼 기반의 LDAP 인증을 통한 Apache 역방향 프록시의 CSRF 보호

지금, 내가 CSRF 로그인 보호 기능을 구현하도록 요청하고, 여기에 설명 :

https://support.detectify.com/customer/portal/articles/1969819-login-csrf 내가 가장 쉬운 방법은 두 양식이 토큰을 생성하고 응답 내에서 전달되는로드 쿠키를 제출 구현하는 것입니다 읽기 사용자에게 사용자가 양식을 제출하면 양식은 쿠키가 동일한 지 확인합니다.

양식이 인증을 처리하지 않지만 mod_auth_form 모듈이이 구현을 사용할 수 없습니다. 가 여기에 우리의 설정입니다 :

가상 호스트 설정 :

<VirtualHost *:80> 
    ServerName test.example.com 
    RewriteEngine On 
    RewriteCond %{HTTPS} off 
    RewriteRule (.*) https://%{SERVER_NAME}$1 [R,L] 
</VirtualHost> 
<VirtualHost *:443> 
    ServerName test.example.com 
    SSLEngine on 
    SSLCipherSuite AES256+EECDH:AES256+EDH 
    SSLProtocol All -SSLv2 -SSLv3 
    SSLHonorCipherOrder On 
    SSLCompression off 
    SSLCertificateFile test.example.com.cer 
    SSLCertificateKeyFile test.example.com.key 
    SSLCertificateChainFile test.example.com.ca 
    Alias "/auth" "/var/www/auth" 
    Customlog /var/log/apache2/test.example.com-access.log combined 
    ErrorLog /var/log/apache2/test.example.com-error.log 
    SSLProxyEngine on 
    SetEnvIfNoCase Request_URI "^/auth/" noauth 
    <Location /auth/logout> 
    SetHandler form-logout-handler 
    AuthType form 
    AuthName realm 
    AuthFormLogoutLocation/
    Session On 
    SessionCookieName session path=/ 
    </Location> 
    <Location /> 
    AuthType form 
    AuthFormProvider ldap 
    AuthName realm 
    AuthFormLoginSuccessLocation %{REQUEST_URI} 
    Session On 
    SessionCryptoPassphrase secretphrase 
    SessionCookieName session path=/ 
    <RequireAny> 
     Require ldap-group CN=webapp_users,OU=Groups,DC=example,DC=com 
     Require env noauth 
    </RequireAny> 
    ErrorDocument 401 "/auth/login.html" 
    AuthLDAPBindDN [email protected] 
    AuthLDAPBindPassword secretpass 
    AuthLDAPURL "ldap://example.com/OU=Users,DC=example,DC=com?sAMAccountName,displayName?sub" 
    AuthLDAPMaxSubGroupDepth 5 
    AuthLDAPGroupAttribute member 
    AuthLDAPSubgroupAttribute member 
    AuthLDAPSubGroupClass group 
    </Location> 
    ProxyPass /auth/ ! 
    ProxyPreserveHost On 
    ProxyPass    /   https://webapp.example.com/ 
    ProxyPassReverse  /   https://webapp.example.com/ 
    ProxyRequests   Off 
    AllowEncodedSlashes  NoDecode 
    Header always append X-Frame-Options SAMEORIGIN 
</VirtualHost> 

과 같이 로그인 폼 보이는 : 기본적으로 무슨 일이 여기 일이 그래서

<html> 
    <head> 
    <title></title> 
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> 
    <meta name="mobile-web-app-capable" content="yes"> 
    <link href='https://fonts.googleapis.com/css?family=Roboto+Condensed:300' rel='stylesheet' type='text/css'> 
    <link rel="stylesheet" type="text/css" href="auth/css/style.css" /> 
    <link rel="icon" href="auth/assets/example_com.ico" /> 
    <script type="text/javascript"> 
     function init() { 
     var sitename = window.location.hostname; 
     document.getElementById("sitename").innerHTML =sitename; 
     document.title = sitename; 
     document.getElementById("username").focus(); 
     } 

     function tryLogin() { 
     localStorage.setItem("tryLogin", true); 
     } 
    </script> 
    </head> 
    <body onload="init()"> 
     <div id=wrap-logo> 
     <div id=logo></div> 
     </div> 
    <div id="content"> 
     <h1><div id='sitename'>empty</div> requires a login</h1> 
     <form method="POST" action="" onsubmit="tryLogin()" autocomplete="off"> 
     <label for="username">Username</label><input type="text" id="username" name="httpd_username" placeholder="Username" value="" /> 
     <label for="password">Password</label><input type="password" id="password" name="httpd_password" placeholder="Password" value="" /> 
     <input type="submit" name="login" value="Login" /> 
     </form> 
    </div> 
    </body> 
</html> 

; 로그인하지 않은 경우 로그인 페이지 인 401 오류 페이지로 리디렉션됩니다. 폼을 제출할 때 인증 자격증 명은 mod_ldap 모듈로 전달되어 제대로 인증되면 세션 쿠키를 생성합니다. 그 후,/auth/* 이외의 것은 대상으로 프록시됩니다.

이 설정에서 CSRF 로그인 보호를 구현할 수있는 방법이 있습니까?

나는 mod_csrf을 시도했지만 제대로 작동하지 않으며, 알파 릴리즈가 있기 때문에 사용하지 않을 것입니다.

답변

-1

mod_auth_form은 항상 사용자의 요청을 먼저 처리하기 때문에 mod_auth_form과 함께 사용할 수 없습니다.

아파치 서버에 php를 설치하고 보내시는 링크가 마음에 드세요. ' $ token = bin2hex (openssl_random_pseudo_bytes (16)); setcookie ("CSRFtoken", $ token, time() + 60 * 60 * 24);

 <form action="loginchecker.php" method="post"> 
      <input name="user"> 
      <input name="pass" type="password"> 
      <input name="CSRFtoken" type="hidden" value="' . $token . '"> 
      <input type="submit"> 
     </form>;` 

당신은 쿠키 엔 토큰이 올 경우,이 페이지의 새로운 양식 작성 JS 직접 보내 확인 페이지에 양식을 리디렉션 할 수 있습니다. document.forms["loginFormname"].submit();

+0

이 링크는 내가 궁금해하는 부분입니다. – rinini