Building a Secure, Self-Contained Form Processing Backend with Go and CGI

A Complete Go Backend in a Single Binary: Secure Form Processing on Shared Hosting

How we used Go and CGI to build a self-contained form processor with bot protection, input sanitization, email delivery, and JSON responses.

Introduction

Modern web development often assumes that running backend functionality requires a dedicated server, an application runtime, or an external service.

But what if you could deliver a complete, secure form-processing backend using nothing more than a single compiled binary on traditional shared hosting?

That was the idea behind this project.

We built a lightweight form processor in Go, compiled it into a standalone executable, and deployed it as a CGI application. It handles the entire form-submission lifecycle, including request processing, input sanitization, spam and bot protection, email delivery, and JSON responses.

No persistent application server. No additional runtime dependencies. No external SMTP service required.

Just a Go binary running in an environment that has traditionally been associated with PHP scripts.

The Problem

Forms are among the most common features on websites, but processing them securely can introduce surprising complexity.

A seemingly simple contact form needs more than an endpoint that accepts a POST request.

A production-ready implementation should consider:

  • Input validation and sanitization.
  • Automated submissions and spam protection.
  • Email delivery and server restrictions.
  • Proper error handling.
  • Consistent responses for frontend applications.
  • Deployment and maintenance requirements.

For developers using static websites or traditional shared hosting, these requirements can be particularly inconvenient.

Many solutions introduce external dependencies, third-party form-processing services, dedicated application servers, or additional infrastructure.

We wanted something simpler.

The Approach: Go + CGI

Rather than building another continuously running web service, we chose Go and the Common Gateway Interface (CGI).

Go provides a convenient way to compile an application into a standalone executable. CGI provides a standardized interface through which a web server can execute that application when a request arrives.

Combining the two gave us an interesting deployment model:

  • Develop using Go.
  • Compile into a standalone binary.
  • Upload the executable to the hosting account.
  • Configure the web server to execute it through CGI.
  • Let the binary handle incoming form submissions.

There is no need to install Go on the production server or maintain a persistent application process.

This makes the solution particularly interesting for traditional shared hosting environments.

A Complete Form-Processing Pipeline

The application is designed to handle the entire submission process rather than delegating individual responsibilities to external services.

1. Request Processing

The CGI application receives incoming form submissions and processes the request.

It handles the submitted data and prepares it for validation.

2. Anti-Spam and Bot Protection

Public forms are frequent targets for automated submissions.

The application incorporates built-in anti-spam and bot-protection mechanisms to help identify and reject unwanted submissions.

Having these protections integrated into the processor means developers don’t need to assemble a collection of unrelated services just to protect a contact form.

3. Input Sanitization

Incoming data is validated and sanitized before being used.

This is an important part of the processing pipeline, helping prevent malformed or unexpected input from being passed into subsequent operations.

Validation and sanitization are treated as separate responsibilities rather than assuming that cleaning an input automatically makes it safe in every context.

4. Email Delivery Through Sendmail

One of the practical design decisions was to use the hosting server’s local sendmail interface for email delivery.

This avoids requiring the application to establish an external SMTP connection.

That can be particularly useful on shared hosting platforms where outbound SMTP connections may be restricted or where developers don’t have access to external mail-service credentials.

Email delivery still depends on the hosting provider’s mail configuration and sending policies, but it removes another external infrastructure dependency from the application.

5. Structured JSON Responses

After processing a submission, the application returns a JSON response.

This makes the backend independent of the frontend implementation.

A traditional HTML form, a JavaScript-powered website, or a static site can communicate with the same processor without needing to understand its internal implementation.

The frontend simply submits the data and handles the returned response.

The Architecture

The overall architecture is intentionally straightforward.

CGI Form Processor Architecture

The important distinction is that all backend responsibilities are handled by the same executable.

There is no separate application server, email API integration, or external form-processing platform in the request pipeline.

Why Not a Traditional Backend Server?

A persistent Go HTTP server would certainly be a valid approach. It is often preferable for applications handling substantial traffic or requiring long-lived connections.

However, it also introduces operational requirements.

A traditional application server generally needs a process that remains running, along with an appropriate hosting environment and a way to manage that process.

CGI takes a different approach.

The web server launches the executable when a request arrives. The application processes the request and exits when finished.

This has some trade-offs, particularly process startup overhead and the lack of persistent in-memory application state.

But for relatively lightweight form processing, this can be a reasonable compromise.

The objective wasn’t to replace every backend architecture. It was to make a useful piece of backend functionality deployable in a much wider range of hosting environments.

Deployment on Shared Hosting

Perhaps the most interesting aspect of this project is its deployment model.

Traditional shared hosting often provides limited control over the server environment.

Developers may not have access to install additional runtimes, configure persistent services, or run custom application servers.

A compiled Go executable changes that equation.

Provided the hosting environment supports CGI execution and permits the required executable permissions, deployment can be relatively straightforward.

The application doesn’t require the hosting provider to install Go, Node.js, Python, or another application runtime.

The result is a modern compiled backend running on infrastructure that many developers already have access to.

Design Benefits

The architecture offers several practical advantages.

Minimal deployment footprint

The application is distributed as a compiled executable rather than a collection of scripts and runtime dependencies.

No persistent application server

CGI execution eliminates the need to maintain a continuously running application process.

Built-in protection

Spam and bot protection are part of the application rather than separate services that need to be integrated.

Simplified email delivery

Using the server’s local sendmail interface avoids depending on an external SMTP connection.

Frontend independence

JSON responses make the processor usable with different frontend technologies.

Hosting flexibility

The solution can run on compatible traditional shared hosting environments without requiring a dedicated VPS or container platform.

Trade-offs and Considerations

CGI isn’t necessarily the right architecture for every application.

Because the web server launches a new process for each request, there is startup overhead compared with a persistent application server.

Other considerations include:

  • Hosting providers must support CGI execution.
  • The binary must be compatible with the server’s operating system and architecture.
  • Executable permissions and CGI configuration must be correct.
  • Hosting resource limits still apply.
  • Sendmail must be available and correctly configured.
  • Email deliverability depends on the hosting provider’s mail infrastructure.
  • Security mechanisms should be evaluated and tested against realistic abuse scenarios.

Understanding these limitations is important.

The goal is not to claim that CGI is universally superior, but to demonstrate that it remains a useful and practical interface for certain kinds of backend applications.

Conclusion

This project started with a relatively simple objective: build a reliable form processor that could be deployed without requiring a dedicated backend server.

The result is a self-contained Go application that handles request processing, spam and bot protection, input sanitization, email delivery, and JSON responses.

By combining Go’s compilation model with the long-established CGI interface, we found a way to bring modern backend functionality to traditional shared hosting.

It is a reminder that modern web development doesn’t always require more infrastructure.

Sometimes, a well-designed executable and a compatible web server are enough.

A complete backend doesn’t always need a backend server.