[Bug] HTTPS-enforcement scenarios fail when Connect / Package Manager terminate TLS on their own port

Abierto Apto para principiantes
#875 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
go, python
Área
backend, testing

Línea de trabajo

Lee cross_product/test_ssl.py y security/test_https.py; después, compara cómo request_http y make_http_request clasifican las respuestas HTTP con las pruebas existentes de los helpers en selftests/test_ssl_helper.py y selftests/test_https_helper.py. Añade casos específicos para la respuesta documentada de rechazo de TLS y para respuestas 400 no relacionadas. El objetivo se cumple cuando la respuesta conocida de texto sin cifrar sobre TLS se acepta como aplicación de HTTPS, mientras que las respuestas 400 y 200 no relacionadas siguen sin cumplir las aserciones pertinentes.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug team: connect team: package manager
VIP version

Seen live with posit-vip 2026.11.2. Reproduced against the v2026.12.0 source (1a54f5f4). The step logic in both files is unchanged on main.

Affected area

Cross-product tests (cross_product/test_ssl.py) and security tests (security/test_https.py)

What happened?

On a deployment where Connect and Package Manager terminate TLS themselves, four scenarios fail:

  • cross_product/test_ssl.py::test_http_redirects_to_https_for_product[Connect] and [Package Manager]
  • security/test_https.py::test_product_enforces_https[Connect] and [Package Manager]

Here "terminate TLS themselves" means [HTTPS] Listen = :3939 / :4242, with no plain-HTTP listener on those ports.

Both make_http_request and request_http build the HTTP URL by swapping the scheme and keeping the port. So https://connect.example.com:3939 becomes http://connect.example.com:3939, and the plaintext request lands on the TLS listener.

Connect and Package Manager serve TLS with Go's net/http. On a TLS listener, Go answers a plaintext request with a valid HTTP response, not a reset (src/net/http/server.go, c.serve, the tls.RecordHeaderError / tlsRecordHeaderLooksLikeHTTP branch):

HTTP/1.0 400 Bad Request

Client sent an HTTP request to an HTTPS server.

httpx parses that as an ordinary response, so neither function reaches its httpx.NetworkError / httpx.ProtocolError branch. The code comments there describe that branch as "what a plaintext HTTP request gets back from a TLS-only port". The assertions then see a non-3xx status:

make_http_request -> {'status': 400, 'location': '', 'refused': False}
AssertionError: HTTP request was not refused or redirected (got HTTP 400). HTTPS is not enforced.

request_http -> {'status': 400, 'location': '', 'final_url_scheme': 'http', 'error': None}
AssertionError: HTTP did not redirect to HTTPS. Initial response: HTTP 400, Location: '', final URL scheme after following redirects: 'http'

The products are enforcing HTTPS. Nothing is served over plaintext, and http_port_no_content passes on the same response. They also cannot redirect on that port. Both products document HTTP→HTTPS redirection as a separate listener ([HTTPRedirect] Listen = :80). HTTPS.Permanent only adds HSTS and the secure cookie flag. References: Connect HTTPRedirect, Connect HTTPS, Package Manager HttpRedirect, Package Manager SSL.

So a deployment that follows the docs is reported as "HTTPS is not enforced". In the same run, Workbench on :443 with a :80 redirect passes both scenarios.

What did you expect to happen?

A TLS-only port that rejects plaintext with Go's 400 should be classified like the refused/reset case (refused: True / error: "port_closed"). Both scenarios should then pass for Connect and Package Manager on :3939 / :4242.

Steps to reproduce

No Posit product needed. Run a 12-line Go TLS listener and call VIP's own step functions against it.

main.go:

package main

import (
	"log"
	"net/http"
)

func main() {
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("ok\n")) })
	log.Fatal(http.ListenAndServeTLS("127.0.0.1:18443", "cert.pem", "key.pem", nil))
}
openssl req -x509 -newkey rsa:2048 -nodes -keyout key.pem -out cert.pem -days 1 \
  -subj /CN=localhost -addext subjectAltName=DNS:localhost,IP:127.0.0.1
printf 'module repro\ngo 1.27\n' > go.mod && go build -o tlsonly . && ./tlsonly &
curl -s http://127.0.0.1:18443/   # -> Client sent an HTTP request to an HTTPS server.

test_repro.py, run from an empty dir containing a bare pytest.ini ([pytest]):

import types
URL = "https://127.0.0.1:18443"

def cfg(url):
    pc = types.SimpleNamespace(is_configured=True, url=url)
    return types.SimpleNamespace(verify=False, product_config=lambda key: pc)

def test_security_https_enforced():
    from vip_tests.security.test_https import make_http_request, https_enforced
    https_enforced(make_http_request(URL, cfg(URL)))

def test_ssl_redirects_to_https():
    from vip_tests.cross_product.test_ssl import request_http, redirects_to_https
    redirects_to_https(request_http("Connect", cfg(URL)))

def test_ssl_http_port_no_content():
    from vip_tests.cross_product.test_ssl import request_http, http_port_no_content
    http_port_no_content(request_http("Connect", cfg(URL)))
uv run --no-project --with /path/to/vip python -m pytest -p no:vip -q -rA test_repro.py
# FAILED test_security_https_enforced  - AssertionError: HTTP request was not refused or redirected (got HTTP 400) ...
# FAILED test_ssl_redirects_to_https   - AssertionError: HTTP did not redirect to HTTPS. Initial response: HTTP 400 ...
# PASSED test_ssl_http_port_no_content
Relevant logs or output

Live vip verify --basic (2026.11.2), on one host running all three products: 4 failed, 65 passed, 26 skipped. The four failures are exactly the scenarios above, with the same assertion messages. A plain curl http://<host>:3939/ and curl http://<host>:4242/ both return Client sent an HTTP request to an HTTPS server.

Environment
  • Live:
    • Ubuntu 24.04, publicly trusted certificates.
    • Workbench 2026.11.1 on :443, with a :80 redirect.
    • Connect 2026.11.1 with [HTTPS] Listen = :3939 and no HTTP.Listen.
    • Package Manager 2026.11.2 with [HTTPS] Listen = :4242 and [HTTP] Listen = (empty).
  • Repro: Go 1.27.4, Python 3.15, VIP source 1a54f5f4.
Suggested fix

The comments in request_http and make_http_request say to keep the two in sync. In both, classify the response as refused / port_closed when it is a 400 carrying a known plaintext-on-TLS signature.

Keep it as narrow as #457 / #555 intended: match the server's signature, not any 400. A 400 for any other reason should still fail.

_PLAINTEXT_ON_TLS = (
    b"Client sent an HTTP request to an HTTPS server",  # Go net/http: Connect, Package Manager
    b"The plain HTTP request was sent to HTTPS port",   # nginx 497 -> 400 page
)

def _rejected_plaintext_on_tls(resp: httpx.Response) -> bool:
    return resp.status_code == 400 and any(sig in resp.content for sig in _PLAINTEXT_ON_TLS)

The nginx string is from ngx_http_special_response.c (ngx_http_error_497_page). I only hit the Go case. Nothing here tested Workbench serving TLS on a non-default port.

request_http could report a distinct reason such as "tls_only" instead of reusing port_closed. The report would then say the TLS port rejected plaintext rather than "port closed".

Selftests can follow the existing monkeypatch.setattr(httpx, "get", fake_get) pattern in selftests/test_https_helper.py and the #555 block in selftests/test_ssl_helper.py:

  • httpx.Response(400, content=b"Client sent an HTTP request to an HTTPS server.\n") → refused / passes;
  • a 400 with an unrelated body → still fails;
  • a 200 → still fails http_port_no_content.

Related: #457 and #555 narrowed this exception handling. #546 (TLS in CI) would exercise this path if the product terminates TLS itself.

Lenguaje dominante
Python
Estrellas
9
Forks
1
Merge medio
15 h 31 min
PR fusionados (30 d)
44

Preparar el entorno

  • Incluye un Dockerfile o un archivo de Docker Compose
  • Sin plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de posit-dev/vip

Todos los issues de posit-dev/vip

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.