Skip to content

Commit d89ff4a

Browse files
committed
added path traversal
1 parent 9a6dd03 commit d89ff4a

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/main.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from fastapi import FastAPI, Request, Response
1+
from fastapi import FastAPI, Request, Response, HTTPException
22
import os
33
import sqlite3
4+
from os.path import isfile
45

56
app = FastAPI()
67
con = sqlite3.connect(':memory:')
@@ -36,12 +37,22 @@ async def root():
3637
return {"message": "Hello World"}
3738

3839

39-
@app.get("/login")
40+
@app.post("/login")
4041
async def login(email: str, password: str):
4142
cur = con.cursor()
4243
cur.execute("SELECT * FROM users WHERE email = '%s' and password = '%s'" % (email, password))
43-
return cur.fetchone() is not None
44+
if cur.fetchone():
45+
return email;
4446

4547
@app.get("/logout")
46-
async def root(email: str):
48+
async def logout(email: str):
4749
return {"message": "Logged out %s!" % email}
50+
51+
@app.get("/attachment")
52+
async def attachment(attachment_name: str):
53+
attachment_path = 'attachments/' + attachment_name
54+
if not isfile(attachment_path):
55+
raise HTTPException(status_code=404, detail="Attachment not found")
56+
57+
with open(attachment_path) as f:
58+
return f.readlines()

0 commit comments

Comments
 (0)