잘좀하자 개발/WEB Service

local Cookie - Login cookie

kissuu 2018. 11. 1. 21:32


1. Issue

(1) 같은 domain에서 1번 URL을 login 후 2번 url을 login 하면, 
1번 URL 재 접속시 아래와 같은 error가 발생함
ex)

 #

 Site 

 1번

 Artifactory

 2번

 JIRA 



The server encountered an internal error that prevented it from fulfilling this request.

java.lang.RuntimeException: more than one filter accepted this request
    org.artifactory.webapp.servlet.authentication.ArtifactoryAuthenticationFilterChain.acceptFilter(ArtifactoryAuthenticationFilterChain.java:115)
    org.artifactory.webapp.servlet.AccessFilter.doFilterInternal(AccessFilter.java:187)
    org.artifactory.webapp.servlet.AccessFilter.doFilter(AccessFilter.java:165)
    org.artifactory.webapp.servlet.RequestFilter.doFilter(RequestFilter.java:67)
    org.springframework.session.web.http.SessionRepositoryFilter.doFilterInternal(SessionRepositoryFilter.java:164)
    org.springframework.session.web.http.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:80)
    org.artifactory.webapp.servlet.SessionFilter.doFilter(SessionFilter.java:62)
    org.artifactory.webapp.servlet.ArtifactoryFilter.doFilter(ArtifactoryFilter.java:116)



2. Root Cause

(1) token cookie
아래와 같은 이유로 Login 후 token 생성하여 login을 skip함.
 - Login session을 유지
 - 다른 page move시 login 절차없이 token으로 page 접속

(2) 일부 Page의 경우 이미 token 값이 생성되었으면 해당 token으로 communication 해야함
ex) Artifactory의 경우 default로는 cookie에 값이 전달되지 않지만, 
JIRA를 login 후 해당 domain에 cookie token이 생성하면, 같은 domain 접속시 default로 cookie의 값들이 포함되어 전달됨. Artifactory의 경우 token이 전달되면, 해당 token으로 permission을 check한다고 생각됨.
ex)
[Checked by Fiddler]
Request sent 106 bytes of Cookie data:

_ga=GA1.2.148576493.1541073439
_gid=GA1.2.1855707260.1541073439
crowd.token_key=QLc9doaQB9QXaXE4gPY4ug00


3. Solution

(1) Cookie 삭제

Chrome의 경우 아래로 접속하여 해당 domain의 cookie data를 삭제

chrome://settings/siteData



(2) curl을 통한 token 전달

https://stackoverflow.com/questions/46127689/artifactory-deploy-error-http-status-500-more-than-one-filter-accepted-this-r

curl http://<user_id>:<token>@docker.for.mac.localhost/artifactory/php-local/

-> 나의 경우 Artifactory의 token을 기억하고 있을 수 없고, window 상에서 curl 사용이 제한적이어서 이 부분은 고려하지 않음.


(3) Chrome Extension 사용

 Javascript 또는 PHP 상에서 Client Application 접속이 제한적임.

따라서, google chrome에서 제공하는 Chrome Extension을 통해 원하는 cookie만 삭제


[manifest.json]
{
  "name": "Remove local cookie",
  "description" : "Base Level Extension",
  "version": "1.0",
  "browser_action": {
    "default_icon": "hello_extensions.png"
  },
  "manifest_version": 2,
  "permissions": [
  "activeTab",
    "clipboardWrite",
  "cookies",
    "https://*/",
    "http://*/"
  ],
  "background": {
      "scripts": ["background.js"],
      "persistent": false
  },
  "commands": {
    "_execute_browser_action": {
      "suggested_key": {
        "default": "Ctrl+Shift+F",
        "mac": "MacCtrl+Shift+F"
      },
      "description": "Opens hello.html"
    }
  }
}

[background.js]

chrome.browserAction.onClicked.addListener(function(tab) {
alert('hi');
   //chrome.tabs.executeScript(null, {file: "remove_cookie.js"});
/*
chrome.cookies.getAll({domain: "lge.com"}, function(cookies) {
    for(var i=0; i<cookies.length;i++) {
      alert(cookies[i].domain);
      alert(cookies[i].path);
      alert(cookies[i].name);
      chrome.cookies.remove({url: "https://" + cookies[i].domain  + cookies[i].path, name: cookies[i].name});
    }
});
*/
var domain = 'domain.com';
var path = '/';
var cookie_name = 'crowd.token_key';
chrome.cookies.remove({url: "https://" + domain  + path, name: cookie_name});
});