Trust custom CA certificates
Experimental
A site with a certificate from a private certificate authority (CA) does not load in a session, because the browser does not trust that CA. Internal sites and test servers often use such certificates. The same thing happens when a proxy inspects HTTPS traffic and signs it with its own CA.
Pass the CA's certificate in caCertificates when you create the session, and the browser trusts it for that session.
Before you begin
Put your Steel API key in the STEEL_API_KEY environment variable, and install the Steel SDK for your language: TypeScript, Python, Go or Rust.
You also need the root certificate of the CA, in PEM format. The examples read it from a file named ca.pem.
Pass the CA certificates
Set caCertificates to a list of certificates. Each item is one root CA certificate in PEM format, the text that starts with -----BEGIN CERTIFICATE-----.
import { readFileSync } from "node:fs";
const session = await client.sessions.create({
caCertificates: [readFileSync("ca.pem", "utf8")],
});from pathlib import Path
session = client.sessions.create(
ca_certificates=[Path("ca.pem").read_text()],
)import "os"
ca, err := os.ReadFile("ca.pem")
if err != nil {
return err
}
session, err := client.Sessions.New(ctx, steel.SessionNewParams{
CaCertificates: steel.F([]string{string(ca)}),
})
if err != nil {
return err
}let session = client
.sessions()
.create(steel_rs::SessionCreateParams {
ca_certificates: Some(vec![std::fs::read_to_string("ca.pem")?]),
..Default::default()
})
.await?;To trust more than one CA, add one item for each certificate.
If you bring your own proxy and it inspects HTTPS traffic, pass its CA certificate in caCertificates and its URL in proxyUrl in the same request.
Check that it worked
Open a page of the site in the session, and watch it in the live view. The page loads, and the browser shows no certificate warning.
Troubleshooting
net::ERR_CERT_AUTHORITY_INVALID
page.goto: net::ERR_CERT_AUTHORITY_INVALID at https://internal.example.com/Cause: The browser does not trust the CA that signed the site's certificate. The session has no caCertificates, or it has a certificate from a different CA.
Fix: Create a new session with the root certificate of the CA that signed the site's certificate, in PEM format, in caCertificates.
Verify: Open the page again. It loads without the error.