From 48b1f0d0673c927dd873af07191697dd6a6a39e4 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Wed, 4 Nov 2020 12:04:24 +0100 Subject: [PATCH] tighten if-else and add empty skylink protection --- docker/nginx/conf.d/client.conf | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docker/nginx/conf.d/client.conf b/docker/nginx/conf.d/client.conf index f2a35c8b..7ea0c288 100644 --- a/docker/nginx/conf.d/client.conf +++ b/docker/nginx/conf.d/client.conf @@ -159,9 +159,7 @@ server { if skylink == nil then skylink, skylink_rest = string.match(hnsres_json.skylink, "/?([^/?]+)(.*)") end - end - - if hnsres_json.registry then + elseif hnsres_json.registry then local publickey = hnsres_json.registry.publickey local datakey = hnsres_json.registry.datakey @@ -183,6 +181,11 @@ server { skylink = data end + -- fail with a generic 404 if skylink has not been extracted from a valid /hnsres response for some reason + if not skylink then + ngx.exit(ngx.HTTP_NOT_FOUND) + end + ngx.var.skylink = skylink if request_uri_rest == "/" and skylink_rest ~= "" and skylink_rest ~= "/" then ngx.var.rest = skylink_rest