Skip to content

Commit

Permalink
fix: set SSL properly for created dynamic backends (#1016)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford authored Oct 21, 2024
1 parent 4c5c083 commit 616e898
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
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

0 comments on commit 616e898

Please sign in to comment.