Track 08 · Lesson 15 of 20Attacks and defenses
- 01What HTTPS protects
- 02The same-origin policy
- 03CORS
- 04Security headers
- 05Cookies done right
- 06Cross-site scripting (XSS)
- 07Content Security Policy
- 08Cross-site request forgery (CSRF)
- 09Clickjacking
- 10Unsafe URLs and open redirects
- 11Prompt injection
- 12SQL and command injection
- 13Prototype pollution, CRLF and SVG
- 14Server-side request forgery (SSRF)
- 15Remote code execution and denial of service
- 16Spoofed headers
- 17Rate limiting
- 18Cache poisoning
- 19The OWASP Top 10
- 20The attack lab
Track 08 · Attacks and defenses
Remote code execution and denial of service
Lesson 15 of 20· 8 min
The worst thing an attacker can do to a server is run their own code on it; the cheapest is to knock it over. Both often come through the same door: a public endpoint that does expensive work on input a stranger chose, like resizing an image.
Attack an image endpoint
Pick a request, send it, then add defenses
What arrives
GET /_next/image?url=https://cdn.example.com/avatars/u81.png&w=640&q=75
Remote code execution#
RCE means the attacker’s code runs on your server, as your app: it can read every environment variable (your database URL and API keys), change data and reach other systems. It usually comes from a bug in code that parses complicated input, often native code like image, PDF, video or archive libraries, or from injection into a shell. That’s why advisories for those libraries are the most urgent kind: patch first, investigate after.
Denial of service#
DoS makes a service slow or unavailable. The dangerous kind is asymmetric: cheap for the attacker, expensive for you. A 40 KB image that decodes to 3.6 GB, a request that skips every cache, a regex that takes minutes on a crafted string, a zip that expands to terabytes. Find the operations that cost you far more than they cost the caller, and cap them: pixel and size limits, timeouts, allowlists of sizes, rate limits.
Image optimization endpoints#
Frameworks ship public image resizers, like Next.js’s /_next/image?url=…&w=…. They download a remote file and decode it with native libraries (sharp and libvips). In Next.js, images.remotePatterns decides which hosts it will fetch from, and deviceSizes and imageSizes decide which widths it will produce. Keep both tight, and keep the framework patched.
In a code review
CriticalFrontend / BackendKnown-vulnerable dependency
Fix: Bump to the fixed version; force transitive ones with an override or resolution; rerun the audit until no High remains; automate it in CI.
0 of 3 checked
Check yourself