2

체리 파이를 올바르게 구성하여 utf-8로 인코딩 된 인증 문자열을 디코딩 할 수 있습니까? CherryPy가 ISO-8859-1로 기본 인증을 디코드합니다

업데이트

issue #1680에 설명 된 제한을 알 수있다.

문제가 해결 될 때까지 CherryPy는 UTF-8로 인코딩 된 기본 인증 데이터를 인식하지 못합니다.

원래 문제

나는 문제가 움라우트 문자를 사용하여 이름/암호와 기본-인증을 사용하여이있다. http- 클라이언트가 ISO-8859-1 (cherrypy가 비판적) name : password를 발급하거나 cherrypy가 utf-8을 사용하여 인증 문자열을 디코딩하도록 구성 할 수있는 방법이없는 것 같습니다. 파이썬 3.6 CherryPy 13.1.0를 사용

:

[28/Dec/2017:15:52:57] ENGINE Bus STARTING 
[28/Dec/2017:15:52:57] ENGINE Serving on http://127.0.0.1:8080 
[28/Dec/2017:15:52:57] ENGINE Bus STARTED 
realm: 'MY_REALM', username: 'Céline', password: 'motörhead' 
127.0.0.1 - C\xc3\x83\xc2\xa9line [28/Dec/2017:15:53:18] "GET/HTTP/1.1" 200 52 "" "Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US))" 
다음 cherrypy 콘솔에서 다음과 같은 출력을 줄 것이다

curl -u 'Céline:motörhead' -i -X GET http://127.0.0.1:8080/ 

: 다음 인수와 컬 호출

import cherrypy 

class SimpleWebpage(object): 
    @cherrypy.expose 
    def index(self): 
     return "<html><head></head><body>Authenticated</body></html>" 

def dummy_validate(realm, username, password): 
    print("realm: {realm!r}, username: {username!r}, password: {password!r}".format_map(locals())) 
    return True 

cherrypy.tree.mount(SimpleWebpage(), '/', 
        {'/': {'tools.auth_basic.checkpassword': dummy_validate, 
          'tools.auth_basic.on': True, 
          'tools.auth_basic.realm': 'MY_REALM',}}) 

cherrypy.config.update({'tools.sessions.on': True,}) 

cherrypy.engine.autoreload.unsubscribe() 
cherrypy.engine.start() 
cherrypy.engine.block() 

cygwin에서 curl 7.56.1 (i686-pc-cygwin)으로 테스트되었고 redhat6에서 curl 7.19.7 (x86_64-redhat-linux-gnu)으로 테스트되었습니다. . 나는 또한 google-chrome 63.0.3239.108을 사용하여 동일한 결과를 테스트했습니다. 이 코드 의지를 사용

def decode_utf8(s): 
    s_bytes = bytes([ord(c) for c in s]) 
    return s_bytes.decode('utf-8') 

def dummy_validate(realm, username, password): 
    username = decode_utf8(username) 
    password = decode_utf8(password) 
    print("realm: {realm!r}, username: {username!r}, password: {password!r}".format_map(locals())) 
    return True 

Kludge

나에게 구글 크롬과 컬 정확한 결과를 제공합니다. 그러나 ISO-8851-15 인코딩 된 문자열을 보내는 Windows 10의 Firefox 57.0.2 (32 비트)에서는 작동하지 않습니다 (예를 들어).

또한이 값은 cherrypy.request.login 값을 수정하지 않습니다.

+0

안녕하세요, github repo에서 문제를 제기하여 프레임 워크 자체에서 정렬 될 수 있도록하십시오. 코드베이스에는 많은 Unicode 비우호적 인 것들이있었습니다. 시간이 지남에 따라 수정되었지만 여전히 개선의 여지가 있습니다. https://github.com/cherrypy/cherrypy/issues/new – webKnjaZ

+0

@webKnjaZ 알았어. 문제가 게시 될 때 바로 문제를 연결합니다. 버그는 ** stackoverflow에서 ** offtopic하지 않는 것 같습니다. – MadMike

+0

네 말이 맞아. 여기에있는 것은 아니지만 수정 프로세스에 영향을 줄 수 있으므로 우스 ream에서 추적해야합니다. – webKnjaZ

답변

1

의견에서 승인 된 @webKnjaZ은 CherryPy 또는 cheroot에서 해결해야하는 버그입니다.

답변으로 질문을 고려해보십시오. 관련된 버그 진행 상황은 해당 CherryPy-Issue에서 추적 할 수 있습니다.