Skip to content

Fail fast when HTTPS is requested but certificates are missing#1638

Closed
kmcginnes wants to merge 6 commits intomainfrom
fix-silent-https-fallback
Closed

Fail fast when HTTPS is requested but certificates are missing#1638
kmcginnes wants to merge 6 commits intomainfrom
fix-silent-https-fallback

Conversation

@kmcginnes
Copy link
Copy Markdown
Collaborator

Description

Stop silently falling back to HTTP when PROXY_SERVER_HTTPS_CONNECTION=true but certificate files are missing. Previously, the server would log a warning and serve over HTTP without any indication to the user that their HTTPS configuration was being ignored.

  • Add ServerConfigError class in server-config.ts that throws when HTTPS is enabled but cert files are missing, reporting the specific missing file paths
  • Catch ServerConfigError in node-server.ts with logger.fatal and process.exit(1)
  • Add set -e to docker-entrypoint.sh so setup-ssl.sh failures stop the container
  • Add || true to grep for set -e compatibility when the env var is absent
  • Fix POSIX sh compatibility: ===, [ $HOST ][ -n "$HOST" ], quote variables
  • Fix setup-ssl.sh: add set -e, fix duplicate rootCA.crt check that missed server.key, report each missing file individually
  • Tighten test assertions to verify specific missing file paths

Blocked by #1632 and #1637 — this PR is rebased on top of both.

Validation

  • pnpm checks passes
  • pnpm test passes (129 tests in proxy server package)
  • Docker tested with Finch: HTTPS without certs now fails fast instead of silently falling back to HTTP

Related Issues

Check List

  • I confirm that my contribution is made under the terms of the Apache 2.0 license.
  • I have verified pnpm checks passes with no errors.
  • I have verified pnpm test passes with no failures.
  • I have covered new added functionality with unit tests if necessary.
  • I have updated documentation if necessary.

- Move cert generation and validation from docker-entrypoint.sh to setup-ssl.sh
- Accept CERT_DIR and HOST as environment variables
- Use absolute paths with CERT_DIR instead of cd + relative paths
- Use portable sed pattern matching instead of hardcoded line numbers
- Preserve existing behavior including known bugs (duplicate rootCA.crt check)
- Add 7 tests documenting current behavior including bug test case
- Add ServerConfigError and throw when cert files are missing
- Catch ServerConfigError in node-server.ts with a clean fatal log
- Fix docker-entrypoint.sh: add set -e, fix bracket syntax, fix duplicate check
- Update tests to expect thrown errors instead of silent fallback

Closes #1634
};

try {
const res = await fetch(url.href, options);
…forgery'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@kmcginnes
Copy link
Copy Markdown
Collaborator Author

I'm planning to move the URL validation to its own branch.

@kmcginnes kmcginnes closed this Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Server silently falls back to HTTP when HTTPS is requested but certificates are missing

2 participants