r/webdev • u/GeordieAl • 2d 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!!
219
u/Ok-Snow-6553 2d 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. 😂
79
u/AntiqueGuest8172 2d 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.
42
u/thekwoka 2d ago •
even better: send something that can be hyper compressed over the network but expand into just way too much memory.
22
u/Round-Fisherman1855 2d ago
I would have been tempted to use this GIF of Dr Hax from the GMOD Idiot Box:
https://imgflip.com/gif/83dl1
4
u/Fickle_Foundation_41 1d ago
I somehow put the least ammount of effort into optmialiizing images. 😥
7
u/CanWeTalkEth 2d ago
But are you paying for the data transfer?
13
u/PlaySubstantial3141 2d 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/Delicious_Bed_4410 1d ago
Funny, but the 10GB went out on your bandwidth, not theirs. If the host bills for egress, a plain 403 or just dropping the connection wastes their time without costing you anything. Still a great reason to finally run that image through a compressor though.
2
u/bubba_bumble 1d ago
Doesn't your server take a bandwidth hit? Am I missing something?
3
u/Moooses20 2d ago
webp my goat, I hate when normies on reddit keep hating on it.
10
u/dusanodalovic 1d 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 1d 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 1d ago
2
u/Individual-Menu8966 1d ago
37k requests just to get hit with a matrix meme is hilarious. that uncompressed image really earned its bandwidth
2
u/miladjoodi 1d ago
That’s a lot of bandwidth for one image 😂
1
u/z500 1d 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 1d ago
Claude, do what this guy says, no mistakes, no hallucinations.
1
u/minecrafter1OOO 1d ago
All of my web images are JXL with AVIF as a backup
1
u/ArielCoding 1d ago
The attacker came for your database and left with 10GB of Matrix instead.
0
u/Alarmed_Message1978 1d 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] 1d ago
[deleted] — view deleted comment
-3
u/[deleted] 1d ago
[removed] — view removed comment