Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set SSL properly for created dynamic backends #1016

Merged
merged 6 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ routes.set('/backend/timeout', async () => {
);
routes.set('/implicit-dynamic-backend/dynamic-backends-enabled', async () => {
allowDynamicBackends(true);
await assertResolves(() => fetch('https://http-me.glitch.me/headers'));
await assertResolves(async () => {
await fetch('https://http-me.glitch.me/headers');
const backend = Backend.fromName('http-me.glitch.me');
strictEqual(backend.isSSL, true);
});
await assertResolves(() => fetch('https://www.fastly.com'));
enforceExplicitBackends();
await assertRejects(() => fetch('https://www.fastly.com'));
Expand Down
5 changes: 4 additions & 1 deletion runtime/fastly/builtins/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1694,7 +1694,9 @@ JSObject *Backend::create(JSContext *cx, JS::HandleObject request) {
if (!name_js_str) {
return nullptr;
}
JS::RootedValue name(cx, JS::StringValue(name_js_str));
std::string name_str((char *)slice.data, slice.len);
JS::SetReservedSlot(request, static_cast<uint32_t>(Request::Slots::Backend), name);

// Check if we already constructed an implicit dynamic backend for this host.
bool found;
Expand All @@ -1707,6 +1709,7 @@ JSObject *Backend::create(JSContext *cx, JS::HandleObject request) {
return nullptr;
}
JS::RootedObject backend(cx, &already_built_backend.toObject());

return backend;
}

Expand All @@ -1722,7 +1725,6 @@ JSObject *Backend::create(JSContext *cx, JS::HandleObject request) {

host_api::BackendConfig backend_config = default_backend_config.clone();

JS::RootedValue name(cx, JS::StringValue(name_js_str));
auto host_backend = set_backend(cx, backend, name);
if (!host_backend) {
return nullptr;
Expand All @@ -1744,6 +1746,7 @@ JSObject *Backend::create(JSContext *cx, JS::HandleObject request) {

auto use_ssl = origin.rfind("https://", 0) == 0;
if (use_ssl) {
backend_config.use_ssl = true;
if (!set_sni_hostname(cx, backend_config, name)) {
return nullptr;
}
Expand Down
Loading