Skip to content

Commit 9eb37ff

Browse files
committed
cisagov#758; Work in Progress for google threat intelligence
1 parent 889c688 commit 9eb37ff

File tree

3 files changed

+113
-4
lines changed

3 files changed

+113
-4
lines changed

dashboards/scripts/index-refresh.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,9 @@ def main():
403403
'urlTemplate'
404404
] = f'{args.netboxUrl}/search/?q={{{{value}}}}&obj_types=dcim.site&lookup=iexact'
405405

406-
# TODO: this doesn't actually work, because it has to be relative to the dashboards app...
407-
# elif field['name'].endswith('.reference'):
408-
# fieldFormatInfo['params']['urlTemplate'] = '{{value}}'
406+
elif field['name'].endswith('.reference'):
407+
# TODO: this doesn't actually work, because it has to be relative to the dashboards app...
408+
fieldFormatInfo['params']['urlTemplate'] = '/refred/{{value}}'
409409

410410
elif field['name'] == 'zeek.files.extracted_uri':
411411
fieldFormatInfo['params']['urlTemplate'] = '/{{value}}'

nginx/nginx.conf

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ http {
159159
include /etc/nginx/nginx_proxy_forward_headers.conf;
160160
}
161161

162-
163162
# extracted file download
164163
location ~* ^/extracted-files\b(.*) {
165164
include /etc/nginx/nginx_auth_rt.conf;
@@ -232,6 +231,61 @@ http {
232231
include /etc/nginx/nginx_proxy_forward_headers.conf;
233232
}
234233

234+
# references (like from virustotal, etc.) to redirect to external site
235+
# (because Dashboards is prepending its own prefix, we have to handle it)
236+
location /dashboards/app/refred/ {
237+
content_by_lua_block {
238+
local ngx = ngx
239+
240+
-- Get everything after the prefix
241+
local raw_url = ngx.var.uri:sub(#"/dashboards/app/refred/" + 1)
242+
243+
-- Decode any URL-encoded characters
244+
local decoded_url = ngx.unescape_uri(raw_url)
245+
246+
-- Fix missing slash after http:/ or https:/ (if nginx collapsed it)
247+
decoded_url = decoded_url:gsub("^(https?:)/([^/])", "%1//%2")
248+
249+
-- Append the original query string if present
250+
if ngx.var.args and #ngx.var.args > 0 then
251+
if decoded_url:find("?", 1, true) then
252+
decoded_url = decoded_url .. "&" .. ngx.var.args
253+
else
254+
decoded_url = decoded_url .. "?" .. ngx.var.args
255+
end
256+
end
257+
258+
-- Safety check: only allow http or https
259+
if not decoded_url:match("^https?://") then
260+
ngx.status = ngx.HTTP_BAD_REQUEST
261+
ngx.say("Invalid URL: " .. decoded_url)
262+
return ngx.exit(ngx.HTTP_BAD_REQUEST)
263+
end
264+
265+
-- Serve a small HTML page with JS confirmation for external redirect
266+
ngx.header.content_type = "text/html"
267+
ngx.say([[
268+
<!DOCTYPE html>
269+
<html>
270+
<head>
271+
<meta charset="UTF-8">
272+
<title>Redirecting...</title>
273+
</head>
274+
<body>
275+
<script>
276+
if (confirm("You are being redirected to an external site. Continue?")) {
277+
window.location.href = "]] .. decoded_url .. [[";
278+
} else {
279+
window.history.back();
280+
}
281+
</script>
282+
<p><a href="]] .. decoded_url .. [[">Click here</a> to be redirected to <br>]] .. decoded_url .. [[</p>
283+
</body>
284+
</html>
285+
]])
286+
}
287+
}
288+
235289
# OpenSearch dashboards (or Kibana)
236290
location /dashboards {
237291
include /etc/nginx/nginx_dashboards_rewrite_rt.conf;

nginx/nginx_readonly.conf

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,61 @@ http {
216216
include /etc/nginx/nginx_proxy_forward_headers.conf;
217217
}
218218

219+
# references (like from virustotal, etc.) to redirect to external site
220+
# (because Dashboards is prepending its own prefix, we have to handle it)
221+
location /dashboards/app/refred/ {
222+
content_by_lua_block {
223+
local ngx = ngx
224+
225+
-- Get everything after the prefix
226+
local raw_url = ngx.var.uri:sub(#"/dashboards/app/refred/" + 1)
227+
228+
-- Decode any URL-encoded characters
229+
local decoded_url = ngx.unescape_uri(raw_url)
230+
231+
-- Fix missing slash after http:/ or https:/ (if nginx collapsed it)
232+
decoded_url = decoded_url:gsub("^(https?:)/([^/])", "%1//%2")
233+
234+
-- Append the original query string if present
235+
if ngx.var.args and #ngx.var.args > 0 then
236+
if decoded_url:find("?", 1, true) then
237+
decoded_url = decoded_url .. "&" .. ngx.var.args
238+
else
239+
decoded_url = decoded_url .. "?" .. ngx.var.args
240+
end
241+
end
242+
243+
-- Safety check: only allow http or https
244+
if not decoded_url:match("^https?://") then
245+
ngx.status = ngx.HTTP_BAD_REQUEST
246+
ngx.say("Invalid URL: " .. decoded_url)
247+
return ngx.exit(ngx.HTTP_BAD_REQUEST)
248+
end
249+
250+
-- Serve a small HTML page with JS confirmation for external redirect
251+
ngx.header.content_type = "text/html"
252+
ngx.say([[
253+
<!DOCTYPE html>
254+
<html>
255+
<head>
256+
<meta charset="UTF-8">
257+
<title>Redirecting...</title>
258+
</head>
259+
<body>
260+
<script>
261+
if (confirm("You are being redirected to an external site. Continue?")) {
262+
window.location.href = "]] .. decoded_url .. [[";
263+
} else {
264+
window.history.back();
265+
}
266+
</script>
267+
<p><a href="]] .. decoded_url .. [[">Click here</a> to be redirected to <br>]] .. decoded_url .. [[</p>
268+
</body>
269+
</html>
270+
]])
271+
}
272+
}
273+
219274
# OpenSearch dashboards (or Kibana)
220275
location /dashboards {
221276
include /etc/nginx/nginx_dashboards_rewrite_rt.conf;

0 commit comments

Comments
 (0)