fix xss
Showing
3 changed files
with
15 additions
and
0 deletions
... | @@ -11,6 +11,7 @@ from .consts import LOGIN_TIMES_LIMIT_EXPIRES, LOGIN_TIMES_LIMIT | ... | @@ -11,6 +11,7 @@ from .consts import LOGIN_TIMES_LIMIT_EXPIRES, LOGIN_TIMES_LIMIT |
11 | class LoginView(ObtainJSONWebToken, GenericView): | 11 | class LoginView(ObtainJSONWebToken, GenericView): |
12 | 12 | ||
13 | def post(self, request, *args, **kwargs): | 13 | def post(self, request, *args, **kwargs): |
14 | # 登录次数限制 | ||
14 | user_name = request.data.get('username', '') | 15 | user_name = request.data.get('username', '') |
15 | times = rh.get_login_times(user_name) | 16 | times = rh.get_login_times(user_name) |
16 | if isinstance(times, int) and times >= LOGIN_TIMES_LIMIT: | 17 | if isinstance(times, int) and times >= LOGIN_TIMES_LIMIT: | ... | ... |
1 | import re | ||
1 | from .named_enum import DocStatus | 2 | from .named_enum import DocStatus |
2 | from .models import HILDoc, AFCDoc | 3 | from .models import HILDoc, AFCDoc |
3 | from . import consts | 4 | from . import consts |
... | @@ -6,6 +7,15 @@ from . import consts | ... | @@ -6,6 +7,15 @@ from . import consts |
6 | class DocHandler: | 7 | class DocHandler: |
7 | 8 | ||
8 | @staticmethod | 9 | @staticmethod |
10 | def xss_pass(file): | ||
11 | for pno in range(file.pageCount): | ||
12 | page = file.loadPage(pno) | ||
13 | page_text = page.getText() | ||
14 | if re.search(r'/JS(.*)', page_text) and re.search(r'/S /JavaScript', page_text): | ||
15 | return False | ||
16 | return True | ||
17 | |||
18 | @staticmethod | ||
9 | def get_name(info, key, length): | 19 | def get_name(info, key, length): |
10 | if not isinstance(info, dict): | 20 | if not isinstance(info, dict): |
11 | return '' | 21 | return '' | ... | ... |
... | @@ -898,6 +898,10 @@ class DocView(GenericView, DocHandler): | ... | @@ -898,6 +898,10 @@ class DocView(GenericView, DocHandler): |
898 | file.close() | 898 | file.close() |
899 | os.remove(tmp_save_path) | 899 | os.remove(tmp_save_path) |
900 | raise self.invalid_params(msg='invalid params: not a PDF file') | 900 | raise self.invalid_params(msg='invalid params: not a PDF file') |
901 | elif not self.xss_pass(file): | ||
902 | os.remove(tmp_save_path) | ||
903 | raise self.invalid_params(msg='invalid params: PDF file XSS') | ||
904 | |||
901 | 905 | ||
902 | file.close() | 906 | file.close() |
903 | # 1. 上传信息记录 | 907 | # 1. 上传信息记录 | ... | ... |
-
Please register or sign in to post a comment