Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add login endpoint #2

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open

Add login endpoint #2

wants to merge 20 commits into from

Conversation

alpire
Copy link
Contributor

@alpire alpire commented Apr 6, 2021

This PR introduces a SQL Injection and a Path Traversal in new login, logout and attachments endpoints, which Mayhem for API detects, preventing the PR from being merged.

@github-actions
Copy link

github-actions bot commented Jan 5, 2023

Mayhem for API Automated API Testing Report

❗ 3 Errors Found

Rule Method Path Details
Internal Server Error GET /login ↗️
Internal Server Error GET /login ↗️
Internal Server Error GET /login ↗️

✔️ 🎆 0 Warnings Found


Testing details and issue reproduction found at https://app.mayhem.security/forallsecure-demo/mapi-action-examples/fastapi/276

@app.get("/login")
async def login(email: str, password: str):
cur = con.cursor()
cur.execute("SELECT * FROM users WHERE email = '%s' and password = '%s'" % (email, password))

Check failure

Code scanning / mAPI

Internal Server Error (sqlite3.Warning) Error

Internal Server Error (sqlite3.Warning) in 'GET /login'. Sample Request GET /login?email=G{s%{5';7E}H<}*YZy2ARA_y_IC}'F3MJP~eFZ;~gQGIxU9tep6E]+up591^Em"F#1y;MouJ-S5(dMHE3$krAwJYSa{>9Rx9Aj3Gg7)89<3&password=79234& HTTP/1.1 content-length: 0 x-mapi-program-uuid: abc81901-7fd7-4c13-ba8b-cd8e8b5a4bd6 Sample Response HTTP/1.1 500 Internal Server Error date: Mon, 22 Apr 2024 22:56:56 GMT server: uvicorn content-length: 2479 Traceback (most recent call last): File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/middleware/errors.py", line 164, in __call__ await self.app(scope, receive, _send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/middleware/exceptions.py", line 65, in __call__ await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app raise exc File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app await app(scope, receive, sender) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/routing.py", line 756, in __call__ await self.middleware_stack(scope, receive, send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/routing.py", line 776, in app await route.handle(scope, receive, send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/routing.py", line 297, in handle await self.app(scope, receive, send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/routing.py", line 77, in app await wrap_app_handling_exceptions(app, request)(scope, receive, send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app raise exc File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app await app(scope, receive, sender) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/routing.py", line 72, in app response = await func(request) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/fastapi/routing.py", line 278, in app raw_response = await run_endpoint_function( File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/fastapi/routing.py", line 191, in run_endpoint_function return await dependant.call(**values) File "/home/runner/work/mapi-action-examples/mapi-action-examples/src/main.py", line 41, in login cur.execute("SELECT * FROM users WHERE email = '%s' and password = '%s'" % (email, password)) sqlite3.Warning: You can only execute one statement at a time. Details
@app.get("/login")
async def login(email: str, password: str):
cur = con.cursor()
cur.execute("SELECT * FROM users WHERE email = '%s' and password = '%s'" % (email, password))

Check failure

Code scanning / mAPI

Internal Server Error (ValueError) Error

Internal Server Error (ValueError) in 'GET /login'. Sample Request GET /login?email='&&cat /etc/passwd�&password=50808-5856& HTTP/1.1 content-length: 0 x-mapi-program-uuid: 37042005-77ea-4134-b5be-ae47cfd63fae Sample Response HTTP/1.1 500 Internal Server Error date: Mon, 22 Apr 2024 22:56:56 GMT server: uvicorn content-length: 2464 Traceback (most recent call last): File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/middleware/errors.py", line 164, in __call__ await self.app(scope, receive, _send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/middleware/exceptions.py", line 65, in __call__ await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app raise exc File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app await app(scope, receive, sender) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/routing.py", line 756, in __call__ await self.middleware_stack(scope, receive, send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/routing.py", line 776, in app await route.handle(scope, receive, send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/routing.py", line 297, in handle await self.app(scope, receive, send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/routing.py", line 77, in app await wrap_app_handling_exceptions(app, request)(scope, receive, send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app raise exc File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app await app(scope, receive, sender) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/routing.py", line 72, in app response = await func(request) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/fastapi/routing.py", line 278, in app raw_response = await run_endpoint_function( File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/fastapi/routing.py", line 191, in run_endpoint_function return await dependant.call(**values) File "/home/runner/work/mapi-action-examples/mapi-action-examples/src/main.py", line 41, in login cur.execute("SELECT * FROM users WHERE email = '%s' and password = '%s'" % (email, password)) ValueError: the query contains a null character Details
src/main.py Fixed Show fixed Hide fixed
@app.get("/login")
async def login(email: str, password: str):
cur = con.cursor()
cur.execute("SELECT * FROM users WHERE email = '%s' and password = '%s'" % (email, password))

Check failure

Code scanning / mAPI

Internal Server Error (sqlite3.OperationalError) Error

Internal Server Error (sqlite3.OperationalError) in 'GET /login'. Sample Request GET /login?email=WX>70T2Qy`JlCd&password='5{ritk0CJ4"06[3b& HTTP/1.1 content-length: 0 x-mapi-program-uuid: 2d6469ee-adaf-4354-9455-ed56aca7c788 Sample Response HTTP/1.1 500 Internal Server Error date: Mon, 22 Apr 2024 22:56:56 GMT server: uvicorn content-length: 2465 Traceback (most recent call last): File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/middleware/errors.py", line 164, in __call__ await self.app(scope, receive, _send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/middleware/exceptions.py", line 65, in __call__ await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app raise exc File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app await app(scope, receive, sender) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/routing.py", line 756, in __call__ await self.middleware_stack(scope, receive, send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/routing.py", line 776, in app await route.handle(scope, receive, send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/routing.py", line 297, in handle await self.app(scope, receive, send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/routing.py", line 77, in app await wrap_app_handling_exceptions(app, request)(scope, receive, send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app raise exc File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app await app(scope, receive, sender) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/routing.py", line 72, in app response = await func(request) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/fastapi/routing.py", line 278, in app raw_response = await run_endpoint_function( File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/fastapi/routing.py", line 191, in run_endpoint_function return await dependant.call(**values) File "/home/runner/work/mapi-action-examples/mapi-action-examples/src/main.py", line 41, in login cur.execute("SELECT * FROM users WHERE email = '%s' and password = '%s'" % (email, password)) sqlite3.OperationalError: near "5": syntax error Details
src/main.py Fixed Show fixed Hide fixed
@app.get("/login")
async def login(email: str, password: str):
cur = con.cursor()
cur.execute("SELECT * FROM users WHERE email = '%s' and password = '%s'" % (email, password))

Check failure

Code scanning / mAPI

Internal Server Error (sqlite3.OperationalError) Error

Internal Server Error (sqlite3.OperationalError) in 'GET /login'. Sample Request GET /login?email=WX>70T2Qy`JlCd&password='5{ritk0CJ4"06[3b& HTTP/1.1 content-length: 0 x-mapi-program-uuid: 2d6469ee-adaf-4354-9455-ed56aca7c788 Sample Response HTTP/1.1 500 Internal Server Error date: Mon, 22 Apr 2024 22:56:56 GMT server: uvicorn content-length: 2465 Traceback (most recent call last): File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/middleware/errors.py", line 164, in __call__ await self.app(scope, receive, _send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/middleware/exceptions.py", line 65, in __call__ await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app raise exc File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app await app(scope, receive, sender) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/routing.py", line 756, in __call__ await self.middleware_stack(scope, receive, send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/routing.py", line 776, in app await route.handle(scope, receive, send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/routing.py", line 297, in handle await self.app(scope, receive, send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/routing.py", line 77, in app await wrap_app_handling_exceptions(app, request)(scope, receive, send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app raise exc File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app await app(scope, receive, sender) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/routing.py", line 72, in app response = await func(request) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/fastapi/routing.py", line 278, in app raw_response = await run_endpoint_function( File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/fastapi/routing.py", line 191, in run_endpoint_function return await dependant.call(**values) File "/home/runner/work/mapi-action-examples/mapi-action-examples/src/main.py", line 41, in login cur.execute("SELECT * FROM users WHERE email = '%s' and password = '%s'" % (email, password)) sqlite3.OperationalError: near "5": syntax error Details
@app.get("/login")
async def login(email: str, password: str):
cur = con.cursor()
cur.execute("SELECT * FROM users WHERE email = '%s' and password = '%s'" % (email, password))

Check failure

Code scanning / mAPI

Internal Server Error (ValueError) Error

Internal Server Error (ValueError) in 'GET /login'. Sample Request GET /login?email='&&cat /etc/passwd�&password=50808-5856& HTTP/1.1 content-length: 0 x-mapi-program-uuid: 37042005-77ea-4134-b5be-ae47cfd63fae Sample Response HTTP/1.1 500 Internal Server Error date: Mon, 22 Apr 2024 22:56:56 GMT server: uvicorn content-length: 2464 Traceback (most recent call last): File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/middleware/errors.py", line 164, in __call__ await self.app(scope, receive, _send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/middleware/exceptions.py", line 65, in __call__ await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app raise exc File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app await app(scope, receive, sender) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/routing.py", line 756, in __call__ await self.middleware_stack(scope, receive, send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/routing.py", line 776, in app await route.handle(scope, receive, send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/routing.py", line 297, in handle await self.app(scope, receive, send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/routing.py", line 77, in app await wrap_app_handling_exceptions(app, request)(scope, receive, send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app raise exc File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app await app(scope, receive, sender) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/routing.py", line 72, in app response = await func(request) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/fastapi/routing.py", line 278, in app raw_response = await run_endpoint_function( File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/fastapi/routing.py", line 191, in run_endpoint_function return await dependant.call(**values) File "/home/runner/work/mapi-action-examples/mapi-action-examples/src/main.py", line 41, in login cur.execute("SELECT * FROM users WHERE email = '%s' and password = '%s'" % (email, password)) ValueError: the query contains a null character Details
@app.get("/login")
async def login(email: str, password: str):
cur = con.cursor()
cur.execute("SELECT * FROM users WHERE email = '%s' and password = '%s'" % (email, password))

Check failure

Code scanning / mAPI

Internal Server Error (sqlite3.Warning) Error

Internal Server Error (sqlite3.Warning) in 'GET /login'. Sample Request GET /login?email=G{s%{5';7E}H<}*YZy2ARA_y_IC}'F3MJP~eFZ;~gQGIxU9tep6E]+up591^Em"F#1y;MouJ-S5(dMHE3$krAwJYSa{>9Rx9Aj3Gg7)89<3&password=79234& HTTP/1.1 content-length: 0 x-mapi-program-uuid: abc81901-7fd7-4c13-ba8b-cd8e8b5a4bd6 Sample Response HTTP/1.1 500 Internal Server Error date: Mon, 22 Apr 2024 22:56:56 GMT server: uvicorn content-length: 2479 Traceback (most recent call last): File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/middleware/errors.py", line 164, in __call__ await self.app(scope, receive, _send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/middleware/exceptions.py", line 65, in __call__ await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app raise exc File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app await app(scope, receive, sender) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/routing.py", line 756, in __call__ await self.middleware_stack(scope, receive, send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/routing.py", line 776, in app await route.handle(scope, receive, send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/routing.py", line 297, in handle await self.app(scope, receive, send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/routing.py", line 77, in app await wrap_app_handling_exceptions(app, request)(scope, receive, send) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app raise exc File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app await app(scope, receive, sender) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/starlette/routing.py", line 72, in app response = await func(request) File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/fastapi/routing.py", line 278, in app raw_response = await run_endpoint_function( File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/fastapi/routing.py", line 191, in run_endpoint_function return await dependant.call(**values) File "/home/runner/work/mapi-action-examples/mapi-action-examples/src/main.py", line 41, in login cur.execute("SELECT * FROM users WHERE email = '%s' and password = '%s'" % (email, password)) sqlite3.Warning: You can only execute one statement at a time. Details
src/main.py Fixed Show fixed Hide fixed
src/main.py Fixed Show fixed Hide fixed
src/main.py Fixed Show fixed Hide fixed
src/main.py Fixed Show fixed Hide fixed
src/main.py Fixed Show fixed Hide fixed
src/main.py Fixed Show fixed Hide fixed
src/main.py Fixed Show fixed Hide fixed
src/main.py Fixed Show fixed Hide fixed
@vlussenburg vlussenburg force-pushed the bad-login-endpoint branch 3 times, most recently from 0c8cfbb to f9014dd Compare January 12, 2023 18:58
src/main.py Fixed Show fixed Hide fixed
src/main.py Fixed Show fixed Hide fixed
@vlussenburg vlussenburg force-pushed the bad-login-endpoint branch 4 times, most recently from 863be11 to b3f647d Compare January 12, 2023 19:51
@vlussenburg vlussenburg force-pushed the bad-login-endpoint branch 2 times, most recently from 44168ec to c7ad466 Compare January 20, 2023 00:06
@codecov-commenter
Copy link

codecov-commenter commented Feb 28, 2023

Codecov Report

Attention: Patch coverage is 47.05882% with 9 lines in your changes are missing coverage. Please review.

Project coverage is 59.52%. Comparing base (8813c9d) to head (c816f67).

Files Patch % Lines
src/main.py 47.05% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main       #2      +/-   ##
==========================================
- Coverage   69.23%   59.52%   -9.71%     
==========================================
  Files           2        2              
  Lines          26       42      +16     
==========================================
+ Hits           18       25       +7     
- Misses          8       17       +9     
Flag Coverage Δ
unit-tests 59.52% <47.05%> (-9.71%) ⬇️
vulnerability-tests 59.52% <47.05%> (-9.71%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants