r/AskProgrammers • u/marco_cerroni • Sep 30 '26
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?
6
u/jeffcgroves Sep 30 '26
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)
6
u/Yamoyek Sep 30 '26
If it’s truly local, then I don’t see why it would be an issue.
However, if you can’t personally verify the code yourself, then you won’t know if it’s truly local. It may be making external API calls somewhere, in the code. Remember, YOU are responsible for your code, not Claude.
2
u/speyerlander Backend Sep 30 '26
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:
requestsfor example)1
u/SnooCalculations7417 Sep 30 '26
I wouldn't serve it as even a local website personally. If you need a ui use tkinter
1
u/ThreeCharsAtLeast Sep 30 '26
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
localhostwith 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/UnderstandingOld5638 Sep 30 '26
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 Sep 30 '26
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/drbomb Sep 30 '26
You could read the generated script yourself and judge its safety but I understand that's why you use AI, to avoid reading.
1
u/DSudz Sep 30 '26
It's not inherently unsafe but you don't have the skills to determine it. There could be issues in your code, your python install, access to your machine, the unmentioned webserver you seem to be running etc.
1
u/Grounds4TheSubstain Sep 30 '26
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?