Skip to content

Commit

Permalink
prevent directory traversal in the web UI
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkot committed Aug 28, 2022
1 parent ac02a77 commit 9e78657
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions ldm/dream/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ def do_GET(self):
self.end_headers()
with open("./static/dream_web/index.html", "rb") as content:
self.wfile.write(content.read())
elif os.path.exists("." + self.path):
mime_type = mimetypes.guess_type(self.path)[0]
else:
path = "." + self.path
cwd = os.getcwd()
is_in_cwd = os.path.commonprefix((os.path.realpath(path), cwd)) == cwd
if not (is_in_cwd and os.path.exists(path)):
self.send_response(404)
return
mime_type = mimetypes.guess_type(path)[0]
if mime_type is not None:
self.send_response(200)
self.send_header("Content-type", mime_type)
Expand All @@ -24,8 +30,6 @@ def do_GET(self):
self.wfile.write(content.read())
else:
self.send_response(404)
else:
self.send_response(404)

def do_POST(self):
self.send_response(200)
Expand Down
2 changes: 1 addition & 1 deletion static/dream_web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h2 id="header">Stable Diffusion Dream Server</h2>
<input value="-1" type="number" id="seed" name="seed">
<button type="button" id="reset">&olarr;</button>
<br>
<label title="Strenght of the gfpgan algorithm ex: '1', --gfpgan startup flag is required." for="gfpgan_strength">GPFGAN Strength:</label>
<label title="Strength of the gfpgan algorithm ex: '1', --gfpgan startup flag is required." for="gfpgan_strength">GPFGAN Strength:</label>
<input value="0.75" min="0" max="1" type="number" id="gfpgan_strength" name="gfpgan_strength" step="0.01">
</fieldset>
</form>
Expand Down

0 comments on commit 9e78657

Please sign in to comment.