The challenge
The code arrived with no git history, no README and three conflicting generations of the same application, with nothing to say which one was live. Diagnosis found four problems stacked on top of each other.
- Lead notification emails had been failing for an unknown period: the SMTP credential was dead and a bare except swallowed the errors
- Every completed quote was posted to a GoHighLevel account the client did not own, so their customers’ personal data went to the former developer
- The lead endpoint had no server-side validation and was being used as an open mail relay to send crypto phishing from the client’s own domain, about 200 a night; Google Cloud disabled the project and the product went offline
- Roof measurements were 56–66% off against professional survey data
What I built
I reverse-engineered the full system and wrote the documentation that did not exist. I then moved it to a clean AWS account the client controls, on Elastic Beanstalk with Docker, ACM TLS and their own domain. That removed a dependency on a domain registered by a third party that had been used as an SSL workaround.
I removed the hard-coded third-party CRM endpoint and replaced it with a ClickUp integration that fires on the first submission rather than when the quote completes. The old design meant every abandoned lead never reached the CRM at all.
I closed the mail relay with several layers rather than one: server-side validation using character allow-lists instead of block-lists (a bit.ly link got past a TLD block-list in testing), HTML escaping, header-injection guards, a honeypot, per-IP rate limiting and Cloudflare Turnstile. Service-area filtering uses the geocoded property address, not the visitor’s IP, so a local homeowner browsing while travelling is not refused.
Every external integration fails safe: a CRM or CAPTCHA outage can never cost a real lead. The work shipped behind 115 automated tests, including replays of the live attack payloads.
Architecture and stack
- Backend
- Python · FastAPI · Uvicorn · Docker
- Cloud
- AWS Elastic Beanstalk · Application Load Balancer · AWS Certificate Manager
- Measurement & reports
- Google Geocoding API · Google Solar API · Google Static Maps · NumPy · Shapely · Matplotlib · Pillow · ReportLab
- Lead delivery
- ClickUp API · Make.com webhooks · Gmail SMTP
- Abuse protection
- Cloudflare Turnstile · Rate limiting · Honeypot · Input allow-lists
- Frontend
- WordPress + Elementor (marketing site) · Jinja2 templates · Vanilla JavaScript
Outcome
The phishing stopped, the customer data leak to the former developer was closed and the product runs in an account the client owns. Leads now reach email, the CRM and the automation pipeline with a delivery status per channel, including leads from homeowners who never finish the quote.
The client also has what they were missing at the start: documentation, a single live version of the code and tests that replay the real attacks. This is the pattern I see in most rescue work: the security problem and the reliability problem turn out to be the same missing checks.
- Open mail relay closed with layered validation and rate limiting
- Customer data no longer sent to a third-party account
- Moved to the client’s own AWS account and domain
- 115 automated tests, including replays of the live attack payloads
Last updated