I am trying to make a CLI Python App that uses the Spotify API and I have implemented the Authorization Code Flow (called like that in their docs) which from my understanding is basically:
create a url for the user to copy paste into their Web Browser
After user logins, it redirects to a specified url (Like http://localhost:8000) and it has the code written at the end of the url.
user copy pastes that code which is the auth code into my App and we have the auth and refresh token all set
So what I don't like is that manual labor so I created a basic webserver that listens to the redirect url and grabs the code automatically. It handles ONLY one request using a specified method for that.
from http.server import BaseHTTPRequestHandler, HTTPServer
class WebServer():
authorization_code = None
def __init__(self, hostName, serverPort):
self.hostName = hostName
self.serverPort = serverPort
self.server = HTTPServer((self.hostName, self.serverPort), CallbackHandler)
def get_auth_code(self):
self.server.handle_request()
class CallbackHandler(BaseHTTPRequestHandler):
def do_GET(self):
WebServer.authorization_code = self.path.split('?')[1].split('=')[1]
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write(b'<html><body><h1>Authorization Successful!</h1></body>
</html>')
My question comes in to parts:
Is this kind of thing "safe"? like the webserver is not exposed to the internet it's only local so there is absolutely no way for an attacker to get in... right? (Not paranoid just curious about hacking)
I wanna understand security in a more general way. Suppose I have an http Web Server at a port that is port forwarded to the open internet for anyone to see. the Web Server does something veery simple, like returning hello world at every Get request or hand out a NON-sensitive file. Does this kind of scenario has any other vulnerability? like a hacker gaining access to my computer/network? doing any "magic" tricks that I don't get? I imagine that absolute worst case scenario is a hacker just getting my non-sensitive file... Like I've read a lot about SQL injection attacks and HTTP server in python following symbolic links etc etc... but in a simple scenario like this where I don't care about the actual data being transferred neither my script does anything advanced exploitable, is the rest of my PC/files safe ?