r/Python • u/Stunning-Sherbet1853 • 11d ago
Discussion 112 CodeQL alerts on my python app, 14 were real
HI, i run a long-lived python backend on windows and mac!
it only listens on 127.0.0.1 and almost every route needs an access token. last week i turned on the default CodeQL scan for the first time and got 112 alerts ( 112 β 1 critical, 87 high, 24 medium).
i went through them one by one with a single question: can this value come from text someone else wrote (a web page, a downloaded file, model output)? where an alert described an attack input, i actually fed it in and timed it.
the first one that surprised me was the regex that checks whether a downloaded file is html. `<!--\` followed by \`--><!--` 28 times kept it busy for 27 seconds. two more regexes that read text we didn't write did the same thing (22s and 11s). six alerts in that family were real. after the fix the html check runs 5,000 times in 0.003s.
the one i'm most embarrassed about: to see whether a login had finished, i checked whether the url contained the site name. so `evil.example/?next=naver.com` passed as a finished login, and `evilnaver.com` counted as the same site. seven alerts across different files. now one small helper pulls out the hostname and checks "equal, or ends with `.domain`", and all seven places use it. the last real one was a script tag filter that let `</script foo>` through.
every fix got a test, and i checked that the test fails when the fix is taken out.
the other 98 i dismissed with a one-line reason each. 42 of them were in my own tests, lines that just write down the url a test expects. most of the rest were path injection or stack trace exposure on routes that need the token anyway. i only traced two of the path ones all the way, so i might be wrong about a couple.
the same "incomplete url substring" rule was noise all 42 times in tests and a real hole in the login check. asking where the value comes from got me through it faster than reading the alert type.
how do you deal with this on a localhost-only or solo project? i dismissed with reasons but i'm not sure that scales.