<- All posts

My Take on AI

AI is getting more and more common, especially in software development. This is my take on it.

3 min read

Yeah, AI is getting more and more common and we mustn't ignore it. And this is my way of using it

Mini-confession

Yes, I code parts of this website using AI, but I couldn't bother making complex GROQ queries when one could be made by AI. Like, have you seen the syntax? It's so complicated.

AI can be used to make boilerplates such as that, database queries like SQL and Mongo, unit tests (check to see if it works), and other repetitive tasks.

It saves so much time so I can focus on what I actually like, making accessible UI/UX and performant logic.

There's no such thing as free lunch

You have to appreciate the verbosity of AI-generated code.

Python
import os
import httpx
from fastapi import FastAPI, Request, HTTPException

app = FastAPI()

# Read the webhook URL from an environment variable
DISCORD_WEBHOOK_URL = os.getenv("DISCORD_WEBHOOK_URL")

@app.post("/webhook")
async def forward_webhook(request: Request):
    if not DISCORD_WEBHOOK_URL:
        raise HTTPException(
            status_code=500,
            detail="DISCORD_WEBHOOK_URL is not configured in the environment variables."
        )

    # 1. Read the incoming request body as a string
    raw_body = await request.body()
    message = raw_body.decode("utf-8")

    # 2. Format the message for Discord (using Markdown header)
    content = f"# You Got Message!\n{message}"

    # Discord messages have a limit of 2000 characters
    if len(content) > 2000:
        content = content[:1997] + "..."

    # 3. Forward to Discord
    async with httpx.AsyncClient() as client:
        discord_response = await client.post(
            DISCORD_WEBHOOK_URL,
            json={"content": content}
        )

    if discord_response.is_error:
        raise HTTPException(
            status_code=discord_response.status_code,
            detail=f"Failed to deliver to Discord: {discord_response.text}"
        )

    return {"status": "ok", "message": "Forwarded to Discord"}

Nobody in the human race writes numbered comments

# Read the webhook URL from an environment variable
So, what else does os.getenv() do?

# 1. Read the incoming request body as a string
No crap, (await request.body()).decode("utf-8") does exactly what the comment said—reads the body as UTF-8.

# 2. Format the message for Discord (using Markdown header)
Revolutionary. f stands for format.

# Discord messages have a limit of 2000 characters
Then why else do we need a if len(content) > 2000 check?

# 3. Forward to Discord
The comment says what the code does precisely. It forwards to Discord with httpx.

It's a variant of the same problem:

Python
# 1. Increment left pointer by one
left += 1
# 2. Decrement right pointer by one
right -= 1

On top of that, do not let it write security. A study done by Hammond Pearce (2021) revealed that around 40% of code generated by GitHub Copilot was in the top 25 CWEs.

  • SQL Injection: db.execute(f"SELECT * FROM users WHERE email = '{email}'")
  • XSS: document.getElementById("qotd").innerHTML = userComment;
  • Nonexistent Authz: DELETE /api/invoice/{id}. There is a Bearer token, just that the AI didn't check if the token owns that invoice.
  • Hardcoded Fallbacks: API_KEY = os.getenv("API_KEY", "sk-xxxxx")
  • Path Traversal: return FileResponse(f"./uploads/{filename}"), but filename is ../../../../etc/passwd.
  • Command Injection: os.system(f"convert {user_filename} output.png") but user_filename is ; rm -rf /
  • SSRF: httpx.get(user_provided_url), but it won't check if the URL is http://169.254.169.254/latest/meta-data/ to dump your entire AWS cloud credentials.
  • Wrong Algorithm: hashlib.sha256(password.encode()).hexdigest(), but SHA256 is stupid fast, making it easy to brute-force.
  • Timing Attack: if provided_api_key == REAL_API_KEY. Equality is roughly O(n), so attackers can see the response time character-by-character to guess the secret key.
  • Yolo CORS: allow_origins=["*"], allow_credentials=True. There you go, you defeated the purpose of CORS.

One thing that makes this worse is automation bias—the output looks clean, tidy, formatted, so you automatically assume it's flawless and invulnerable. It's not.

Bottom-Line

You can let AI write repetitive code such as unit tests, deserialization structs, SQL/GROQ queries, and others. But be sure to check if AI wrote verbose and/or vulnerable code.

Join the mailing list
Get new posts delivered to your inbox. No spam, unsubscribe anytime.