r/webdev • u/GeordieAl • 8d ago
Just a reminder to every web dev, optimize your images!
So last night I was working on optimizing some code for a clients website. The site has been getting hammered by AI bots recently so I thought I’d go through all my code and make sure it was all as optimized as possible.
While analyzing the log file I noticed that someone was actively trying a SQL injection attack, so I thought I’d have some fun, I redirected all their requests to this image, which I didn’t compress in my rush to have some fun.
37,000 requests later and almost 10Gb of data transferred they finally stopped.
Yeah I realize it was probably an automated attack and they never actually saw the image, but part of me wishes it was some script kiddie and the image popped up on their screen 😜
So remember people, optimize your images!!
297
u/Ok-Snow-6553 8d ago
Genius. Next time someone tries SQL injection on my forms, I'll just serve them a 10MB uncompressed PNG.
But yeah, this is a great reminder. Image optimization isn't just for SEO, it's for fighting bots too. 😂
95
u/AntiqueGuest8172 8d ago
37k requests for 10GB works out to roughly 270KB a pop, which is just a normal jpg. So the bot got bored of an entirely ordinary image, and you paid the egress for it.
58
u/thekwoka 8d ago •
even better: send something that can be hyper compressed over the network but expand into just way too much memory.
25
u/Round-Fisherman1855 8d ago
I would have been tempted to use this GIF of Dr Hax from the GMOD Idiot Box:
https://imgflip.com/gif/83dl1
5
u/Fickle_Foundation_41 8d ago
I somehow put the least ammount of effort into optmialiizing images. 😥
8
u/CanWeTalkEth 8d ago
But are you paying for the data transfer?
14
u/PlaySubstantial3141 8d ago
10GB over 37k requests is like 270KB per image, that's not uncompressed at all, that's a normal jpeg. you're bragging about a slow loris attack with a stock photo
3
u/bubba_bumble 8d ago
Doesn't your server take a bandwidth hit? Am I missing something?
3
u/Moooses20 8d ago
webp my goat, I hate when normies on reddit keep hating on it.
13
u/dusanodalovic 8d ago
if you want the fun without paying the egress, a tarpit is cheaper. keep their connection open and drip one byte every few seconds, the bot just sits there waiting and you send almost nothing. before the fun part id also grep the logs for 500s on the requests with the injection strings in them. a 500 there often means the input actualy reached a query and broke it, and thats the one to fix first
1
u/Embarrassed_Event_10 8d ago
the usual culprit isn't the build, it's the upload path: someone drops a 4MB phone photo into the CMS and nothing between there and the browser ever resizes it. capping the upload width and converting to webp on upload fixed more of this on the sites I look after than any build step, since the build never sees those files.
2
u/captain_obvious_here back-end 8d ago
2
u/Individual-Menu8966 8d ago
37k requests just to get hit with a matrix meme is hilarious. that uncompressed image really earned its bandwidth
2
u/miladjoodi 8d ago
That’s a lot of bandwidth for one image 😂
1
u/z500 8d ago
Someone needs to send this to the people who make our AI training at work, with its 600 megabyte GIF up in the corner
1
u/tribak 8d ago
Claude, do what this guy says, no mistakes, no hallucinations.
1
u/minecrafter1OOO 7d ago
All of my web images are JXL with AVIF as a backup
1
u/exitof99 2d ago
This and the responses below are just reminding me of this banger from around 1999:
Barcelona - I Have the Password to Your Shell Account
https://www.youtube.com/watch?v=SX1bedJSpLk
Someone hacked one of my client's websites and they replaced the homepage with a hack brag page that played this song. I fixed their site, but kept the song and put it into my playlist.
Maybe you can just forward them to the above link.
1
u/ArielCoding 8d ago
The attacker came for your database and left with 10GB of Matrix instead.
0
u/Alarmed_Message1978 8d ago
Petit détail: "je redirigeais" au milieu de tout le reste au passé composé, ça accroche un peu à la lecture. Et du coup le titre sur l'optimisation des images ne colle pas vraiment à l'anecdote.
0
u/[deleted] 8d ago
[deleted] — view deleted comment
2
u/[deleted] 8d ago
[removed] — view removed comment
-3
u/[deleted] 8d ago
[removed] — view removed comment