We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ab0ffd0 commit 85bbbb2Copy full SHA for 85bbbb2
captcha/captchas.py
@@ -1,15 +1,19 @@
1
# public function to use
2
from django.conf import settings
3
from django.core.exceptions import ObjectDoesNotExist
4
-import os
+from django.http import HttpResponseBadRequest
5
+import os.path
6
7
from captcha.tools import GenCaptcha
8
from captcha.models import CaptchaStore
9
10
def setcaptcha(key):
11
g = GenCaptcha()
- path = os.path.join(settings.BASE_DIR, \
12
- "uploads", "captcha", "{name}.png".format(name=key))
+ 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()
17
18
ans = g.createImg(path)
19
0 commit comments