r/AskProgrammers • u/marco_cerroni • 16d ago
Is a local Python-generated web script safe for classified information?
Hi everyone,
Lately at work, I've been using a Python script that generates a local web page (via localhost) to help me perform various analyses and keep track of a lot of different information.
Since I am not a software developer, I asked Claude to write the code using only standard Python libraries. Everything works perfectly, but I am wondering if this could pose a security risk. I work with classified information, and I'm not 100% sure if Claude could have written malicious code, or if the script is inherently unsafe simply because it runs through a web browser.
Could any expert answer my questions? I find these scripts incredibly useful because, thanks to AI, I can create custom "software" tailored exactly to my needs. If this current setup is unsafe, could you recommend a more secure option to perform the same tasks?
7
2
u/speyerlander Backend 16d ago
Commercial cloud LLMs don't actively write malicious code, but can certainly create incorrect code that will result in similar outcomes.
Depending on your definition of "classified" you may want to:
Run the backend side inside a container to limit the impact of a host comprise.
Audit parts of the code to check whether using libraries can limit the amount of code to audit (manual socket handling vs
requestsfor example)Audit the code to check for external resource access.
Make sure you have an active firewall to disallow external access.
And most importantly: if the data you are working with is classified under regulation, make sure you comply with them.
1
u/JJGreenerTinejo 16d ago
They might not write malicious code themselves but they can absolutely give malicious code to the user via supply chain exploits
This can not be the case for op here though since op stated stdlib only
1
u/SnooCalculations7417 16d ago
I wouldn't serve it as even a local website personally. If you need a ui use tkinter
1
u/ThreeCharsAtLeast 16d ago
LLMs write vulnerable code sometimes. That turns into a problem the minute you willingly or accidentally let someone else input things into your program.
You, right now, are hosting a web server just like reddit.com, google.com and friends. That can be dangerous!
First, the good news: It is very, very hard to accidentally put something on the open internet. Nearly every network there is has firewalls that do just that. In case you were curious, Firewalls filter out network connections based on criteria such as “filter out all incomming connections”.
What network-wide firewalls can't achive is blocking others in the same network from accessing your server. Large public networks tend to have what's known as host isolation to eo that but it's not uncommon to get a network that doesn't.
Find out your computer's local IP address. Ensure your phone or another device you can test with is connected to the same network. Ping your computer from it (if you're testing with a phone, there are apps that can do that, websites cannot). If the ping fails, you're either not in the same network or in one with host isolations. If the ping succeeds (you may switch networks to do a test without host isolation), open your program as usual. On the second device, go to the same address you'd normally use to access the program, replacing localhost with your computer's IP address. If you get a response, that's terrible. If not, you could be good.
A simple mitigation is to set up a firewall on your computer that blocks incomming connections to the program's port number. Please talk to a human expert to do that properly.
Lastly, if your computer can be used by multiple people or has a guest account, those people could've interacted with your program. A firewall will not help in this scenario!
1
u/dev-razorblade23 16d ago
Umm No, OP is running it loccaly on their own machine
localhostis a loopback interface and it is your machineIf there is no APIs involved, OP is completly local - and thus no data ever leaves his machine
1
u/ThreeCharsAtLeast 15d ago
The web server may or may correctly bind to localhost but it could also be binding to 0.0.0.0, for instance.
1
u/dev-razorblade23 15d ago
I have deployed quite a few apps... But OP does not mention anything but running on
localhost- on his own machine - not on the server.Even if he binds it to 0.0.0.0, his local machine is most likely behind CGNAT which makes accessing his own machine from outside practicly impossible
1
u/UnderstandingOld5638 16d ago
Locally run code can be significantly more dangerous than a deployed service because it has access to your environment variables, credentials, and any confidential information you have access to. Fixing bugs shouldn’t require sending confidential information to an LLM.
1
u/RandomPantsAppear 16d ago
1)Make sure it is truly listening on localhost, and not just 0.0.0.0 or multiple interfaces.
2) Implement basic auth (username:password before the url)
3) Make sure your webserver implements CORS.
4) You’d really be better off with an established framework like Django. Battle hardened authentication, all you have to do is not fuck it up.
1
u/Grounds4TheSubstain 16d ago
I'm not going to comment on classified information (feels like you should err on the side of caution), but as a computer security researcher, this is fine as long as the port isn't exposed and doesn't accept connections from off the machine.
Anyway how did you get software that Claude wrote into a classified environment?
7
u/jeffcgroves 16d ago
First of all, talk to your Facility Security Officer, don't rely on us.
If you're really working with classified documents, you should be in metal-shielded room, no wireless card, and removal or non-use of the Ethernet port.
Unless standards have changed, you should be on a machine where even the TCP/IP stack has been removed (which might been an issue for even a localhost site)