2009-05-23 5 views
10

XSS와 같은 악의적 인 입력을 필터링 할 수있는 적극적으로 유지 관리되는 파이썬 라이브러리가 있습니까?XSS 필터링을위한 Python 라이브러리?

+0

잘 아무것도

당신을 도울 수있는 CGI 모듈에 뭔가가있다. 원하는 물건에 대한 특별한 요구 사항이 있습니까? – SpliFF

+0

위의 설명은 매우 순진하다고 지적하고 싶습니다. 읽으면 https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet를 시작으로 읽어보십시오. – mkoistinen

답변

0

Strip-o-Gram 라이브러리가 상당히 멋지게 보입니다. 제대로 체크 아웃하지는 않았지만 일을 잘하는 것처럼 보입니다 (즉, HTML 태그를 허용하고 HTML을 이스케이프 처리하는 것은 불쾌합니다).

from stripogram import html2text, html2safehtml 
    mylumpofdodgyhtml # a lump of dodgy html ;-) 
    # Only allow <b>, <a>, <i>, <br>, and <p> tags 
    mylumpofcoolcleancollectedhtml = html2safehtml(mylumpofdodgyhtml,valid_tags=("b", "a", "i", "br", "p")) 
    # Don't process <img> tags, just strip them out. Use an indent of 4 spaces 
    # and a page that's 80 characters wide. 
    mylumpoftext = html2text(mylumpofcoolcleancollectedhtml,ignore_tags=("img",),indent_width=4,page_width=80) 

희망하는 데 도움이 :

다음 해당 페이지에서 인용 한 사용 예 조각은입니다.

+2

공격자가 멋진 태그를 넣을 수 있다고 믿을 수는 없습니다. strip-o-gram이 크게 인코딩 된 태그 (rsnake의 목록 : http://ha.ckers.org/xss.html 참조)에서 작동하지 않는 한이 방법은 작동하지 않습니다. – Mystic

+0

신토닉이 말한 것과 마찬가지입니다. Strip-o-gram (소년은 외로운 친구를 응원하기 위해 주문할 수도있는 소리를내는 것처럼 보입니다)는 XSS에 대한 방어 수단으로 묘사되지 않았습니다. –

8

웹 프레임 워크와 Jinja2와 같은 템플릿 엔진을 사용하는 경우 템플릿 엔진이나 프레임 워크에 이와 비슷한 기능이 내장되어있을 가능성이 있습니다.

cgi.escape('malicious code here')

은 다음을 참조하십시오 : http://docs.python.org/library/cgi.html#cgi.escape

또한 Jinja2 탈출 제공 : 그렇게 할 것입니다 HTML 태그를 제거

from jinja2 import utils 
str(utils.escape('malicious code here')) 
+0

파이썬 3.4 이상부터 stdlib에'html.escape'이 ​​있습니다! –

관련 문제