Skip to content

Commit 85bbbb2

Browse files
committed
retry fix #1
1 parent ab0ffd0 commit 85bbbb2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

captcha/captchas.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
# public function to use
22
from django.conf import settings
33
from django.core.exceptions import ObjectDoesNotExist
4-
import os
4+
from django.http import HttpResponseBadRequest
5+
import os.path
56

67
from captcha.tools import GenCaptcha
78
from captcha.models import CaptchaStore
89

910
def setcaptcha(key):
1011
g = GenCaptcha()
11-
path = os.path.join(settings.BASE_DIR, \
12-
"uploads", "captcha", "{name}.png".format(name=key))
12+
path_prefix = os.path.join(settings.BASE_DIR, "uploads", "captcha")
13+
path = os.path.join(path_prefix, "{name}.png".format(name=key))
14+
path = os.path.normpath(path)
15+
if not path.startswith(path_prefix):
16+
raise HttpResponseBadRequest()
1317

1418
ans = g.createImg(path)
1519

0 commit comments

Comments
 (0)