Experience
Projects
My Stack
Case studies
Contact me
Open my CV

·6 min read

A memory scanner with a web UI needs a guard and a test for it

The most dangerous line in Unfair is not a Win32 call. It is app.run(...). Unfair is a memory scanner for Windows, and the web page I put in front of it can read and write the memory of any process my account can open. Anything that can send that page an HTTP request can do the same. So the question I had to answer was not how the scanner works, it was who gets to talk to it.

Project
Unfair
Date
Sep 2026
Stack
Python, Flask, ctypes
Commit
6620371

What broke

Nothing broke, and I want to be plain about that. The public repository has one commit, 6620371 from Sep 2026, titled as an initial commit, and one release, v1.0.0. There is no incident, no later fix, and no log of a bad day. What I can offer is the design as it stands in that commit and the reasoning visible in its code, comments and tests.

The risk is structural. The web UI exposes endpoints that scan a process, write a value to an address, write to every result at once, and freeze a value so it is rewritten continuously. In web.py they are api_write, api_write_all and api_freeze. None of them asks for a password, because the tool runs on one person's machine for that person.

A tool like that is safe only as long as nothing else can reach it. A server on a port is reachable by anything that can open a socket to it. If it listened on all interfaces, anyone on the same network could write to processes on my machine. That is the failure the guard exists to prevent, and it is why I treat it as the main design question and not as a detail.

What the code showed

There are two layers, and they are both in the code.

The first is the bind address. Both entry points start the server on localhost only. web.py does it in main(), and launcher.py, which the packaged exe uses, does it too:

python
app.run(host="127.0.0.1", port=5000, debug=False, threaded=True)

The second layer is a check on every request. The bind address stops other machines from connecting. The check is for the case where something else gets through, such as a changed host argument in a later edit. web.py registers a before_request hook:

python
@app.before_request
def local_only():
    if request.remote_addr not in ("127.0.0.1", "::1"):
        return jsonify(error="local requests only"), 403

The module docstring says why in a sentence I would still sign: "this process can read and write the memory of any process you can open, so it must never be exposed on a network."

Two layers matter because each fails differently. If someone later changes host="127.0.0.1" to "0.0.0.0" to try the UI from a phone, the bind no longer protects anything, but the hook still refuses the phone. If the hook is deleted in a refactor, the bind still keeps the network out. They are not independent in the sense of a security audit, because both are my code, but they do cover each other's most likely edit.

refused at connectlocal only127.0.0.1 or ::1403 otherwiseBind to 127.0.0.1server socketlocal_only hookbefore every requestWrite and freeze endpointsany process you can openOther machineon the network
Figure 1. Two checks stand between a network and a process-memory writer. A change to either one is covered by the other.

The fix

There is nothing to fix in the sense of a bug, so this section is the part I am proudest of: the guard is not left as a comment. test_web.py drives the whole HTTP API with Flask's test client and ends with the case that matters. The client is made to look local for the main run, then a second client is made to look remote:

python
c = web.app.test_client()
c.environ_base["REMOTE_ADDR"] = "127.0.0.1"
...
# non-local requests are refused
c2 = web.app.test_client()
c2.environ_base["REMOTE_ADDR"] = "10.0.0.5"
assert c2.get("/api/status").status_code == 403
print("  remote request          -> 403 local requests only")

The same test checks that garbage input to /api/scan returns 400 and not 500. So the web layer has a short contract and a test for each part of it: bad input is a client error, and a non-local caller gets 403.

I also put the warning where a person deploying it would see it. The README says to bind to 127.0.0.1, that other addresses are rejected, and not to put it behind a tunnel or reverse proxy, because "every endpoint is unauthenticated, and the write endpoints will happily poke any process you can open."

That last sentence points at a real gap, and it is worth reading it as a limit of the design. A reverse proxy or tunnel running on the same machine connects from 127.0.0.1. The guard would see a local address and let the request through, even though the traffic came from the network. The README warning exists because the code cannot detect that case.

What I would do differently

I would not rely on the remote address alone. It tells you who connected, not who is behind them. From reading the code, two cheap additions would close most of the gap.

First, a per-run token. The launcher could generate a random value at startup, put it in the URL it opens, and require it on every API call. A proxy or a tunnel would then not be enough to reach the endpoints, and neither would another local process that did not receive the token.

Second, a check of the Host header against the expected local names. A page in the user's own browser could try to talk to a local port, and a Host or Origin check is the usual way to refuse requests that a browser sends on behalf of another site. I did not add either one, and I have not tested the UI against that kind of request, so I am describing a gap in the design as I read it, not one I reproduced.

I would also want the test to cover the IPv6 loopback address ::1, which the hook allows. The test covers a local IPv4 caller and a remote one, but not ::1.

None of this changes the main point. A tool that can write into other processes needs its guard in code and in a test, and Unfair has both. It needs more than that, and I know where.

Where this fits

This is one design decision inside Unfair, a single-file Python scanner with a CLI, a web UI and a packaged elevated exe. The rest of the design, from region filtering to the unknown-value scan, is in the full Unfair case study.

The full write-up covers how the scanner narrows thousands of candidates to one, and how the exe is packaged.

Read the full case study

#python#flask#security#windows

Keep reading

Have a project in mind?