mockbin icon indicating copy to clipboard operation
mockbin copied to clipboard

Fix invalid underscore in domain names for OpenAPI bins

Open Copilot opened this issue 3 months ago • 2 comments

Problem

OpenAPI bins were being created with _oas suffix, generating invalid domain names like https://12345678_oas.api.mockbin.io/ when using wildcard subdomains. This violates RFC 1035 DNS hostname standards, which prohibit underscores in domain names, causing TLS handshake failures in Java applications and other strict HTTP clients:

Caused by: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure

Solution

Replace underscores with hyphens in OpenAPI bin IDs while maintaining full backward compatibility:

  • New OpenAPI bins: Use -oas suffix (DNS compliant)
  • Legacy bins: Continue supporting _oas suffix for existing bins
  • All functionality preserved: Validation, detection, and URL generation work for both formats

Changes

Core Logic Updates

  • modules/handlers.ts: Changed bin ID generation from binId += "_oas" to binId += "-oas"
  • modules/utils.ts: Updated regex pattern to accept both [-_]oas formats
  • modules/utils.ts: Enhanced isOasBin() to detect both underscore and hyphen variants
  • modules/handlers.ts: Updated YAML file handling to use consistent hyphen format

Test Coverage

Added comprehensive test suite covering:

  • DNS hostname validation for new format
  • Backward compatibility with legacy format
  • Bin ID validation for both formats
  • OpenAPI bin detection logic

Impact

Before: https://12345678901234567890123456789012_oas.api.mockbin.io/ ❌ (Invalid DNS) After: https://12345678901234567890123456789012-oas.api.mockbin.io/ ✅ (RFC 1035 compliant)

  • ✅ Resolves TLS handshake failures in Java and other strict HTTP clients
  • ✅ New bins are fully DNS compliant (RFC 1035)
  • ✅ Zero breaking changes - existing bins continue working
  • ✅ All tests passing (28/28 including 10 new tests)

This fix ensures OpenAPI bins work seamlessly with all HTTP clients while maintaining complete backward compatibility.

Original prompt

This section details on the original issue you should resolve

<issue_title>Bug: invalid character in domain in case of OpenAPI Bin creation</issue_title> <issue_description>Hi!

I have created a few mockbins via the new "Create an OpenAPI Bin" functionality and the tool always generated this URL format: https://<unique_identifier>_oas.api.mockbin.io/

When attempting to make an HTTPS request to a URL via a simple Java application, the request fails with the following exception: Caused by: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure

It seems that the root cause is that the domain <unique_identifier>_oas contains an underscore (_), which is not a valid character for DNS hostnames according to RFC 1035.

Underscores are not supported in public DNS hostnames and cause TLS clients to reject the request during the handshake phase.

Requests to generated mockbin URLs should use valid domain names (only LDH characters: letters, digits, hyphens).

Could you please investigate this problem?

Thanks a lot! </issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes zuplo/mockbin#67


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot avatar Oct 11 '25 20:10 Copilot

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
mockbin Ready Ready Preview Oct 11, 2025 9:03pm

vercel[bot] avatar Oct 11 '25 20:10 vercel[bot]

The latest build updates on your Zuplo API Gateway. Learn more about Zuplo for GitHub ↗︎

Name Status Preview Updated (UTC)
Zuplo API ✅ Ready (Inspect) Visit Preview Oct 11, 2025, 09:04 PM

zuplo[bot] avatar Oct 11 '25 20:10 zuplo[bot]