treewide: improve handling of page redirections in uci change views

Instead of passing the full LuCI request url, pass the relative resolved
request path instead and filter the received value through the lookup()
dispatcher function to only allow paths to actual internal pages.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich 2018-04-05 22:37:37 +02:00
parent 7b04d0bbcf
commit 731ed77c0b
7 changed files with 14 additions and 13 deletions

View file

@ -5,8 +5,7 @@
module("luci.controller.admin.uci", package.seeall) module("luci.controller.admin.uci", package.seeall)
function index() function index()
local redir = luci.http.formvalue("redir", true) or local redir = luci.http.formvalue("redir", true) or table.concat(disp.context.request, "/")
luci.dispatcher.build_url(unpack(luci.dispatcher.context.request))
entry({"admin", "uci"}, nil, _("Configuration")) entry({"admin", "uci"}, nil, _("Configuration"))
entry({"admin", "uci", "changes"}, call("action_changes"), _("Changes"), 40).query = {redir=redir} entry({"admin", "uci", "changes"}, call("action_changes"), _("Changes"), 40).query = {redir=redir}

View file

@ -16,9 +16,9 @@
<% end %> <% end %>
<div class="cbi-page-actions"> <div class="cbi-page-actions">
<% local r = luci.http.formvalue("redir"); if r and #r > 0 then %> <% local node, url = luci.dispatcher.lookup(luci.http.formvalue("redir")); if url then %>
<div style="float:left"> <div style="float:left">
<form class="inline" method="get" action="<%=luci.util.pcdata(r)%>"> <form class="inline" method="get" action="<%=luci.util.pcdata(url)%>">
<input class="cbi-button cbi-button-link" style="float:left; margin:0" type="submit" value="<%:Back%>" /> <input class="cbi-button cbi-button-link" style="float:left; margin:0" type="submit" value="<%:Back%>" />
</form> </form>
</div> </div>

View file

@ -18,10 +18,12 @@
<p><strong><%:There are no pending changes to revert!%></strong></p> <p><strong><%:There are no pending changes to revert!%></strong></p>
<% end %> <% end %>
<% local node, url = luci.dispatcher.lookup(luci.http.formvalue("redir")); if url then %>
<div class="cbi-page-actions"> <div class="cbi-page-actions">
<form class="inline" method="get" action="<%=luci.util.pcdata(luci.http.formvalue("redir"))%>"> <form class="inline" method="get" action="<%=luci.util.pcdata(url)%>">
<input class="cbi-button cbi-button-link" style="margin:0" type="submit" value="<%:Back%>" /> <input class="cbi-button cbi-button-link" style="margin:0" type="submit" value="<%:Back%>" />
</form> </form>
</div> </div>
<% end %>
<%+footer%> <%+footer%>

View file

@ -147,7 +147,7 @@
if ucichanges > 0 then if ucichanges > 0 then
write('<a class="label notice" href="%s?redir=%s">%s: %d</a>' %{ write('<a class="label notice" href="%s?redir=%s">%s: %d</a>' %{
url(category, 'uci/changes'), url(category, 'uci/changes'),
http.urlencode(http.formvalue('redir') or REQUEST_URI), http.urlencode(http.formvalue('redir') or table.concat(disp.context.request, "/")),
translate('Unsaved Changes'), translate('Unsaved Changes'),
ucichanges ucichanges
}) })

View file

@ -205,7 +205,7 @@ if tree.nodes[category] and tree.nodes[category].ucidata then
-%> -%>
<div id="savemenu"> <div id="savemenu">
<% if ucic > 0 then %> <% if ucic > 0 then %>
<a class="warning" href="<%=controller%>/<%=category%>/uci/changes/?redir=<%=http.urlencode(http.formvalue("redir") or REQUEST_URI)%>"><%:Unsaved Changes%>: <%=ucic%></a> <a class="warning" href="<%=controller%>/<%=category%>/uci/changes/?redir=<%=http.urlencode(http.formvalue('redir') or table.concat(disp.context.request, "/"))%>"><%:Unsaved Changes%>: <%=ucic%></a>
<% end -%> <% end -%>
</div> </div>
<% end %> <% end %>

View file

@ -172,7 +172,7 @@
if ucichanges > 0 then if ucichanges > 0 then
write('<a class="label notice" href="%s?redir=%s">%s: %d</a>' %{ write('<a class="label notice" href="%s?redir=%s">%s: %d</a>' %{
url(category, 'uci/changes'), url(category, 'uci/changes'),
http.urlencode(http.formvalue('redir') or REQUEST_URI), http.urlencode(http.formvalue('redir') or table.concat(disp.context.request, "/")),
translate('Unsaved Changes'), translate('Unsaved Changes'),
ucichanges ucichanges
}) })

View file

@ -104,7 +104,7 @@
if ucic > 0 then if ucic > 0 then
write('<a class="warning" href="%s?redir=%s">%s: %d</a>' %{ write('<a class="warning" href="%s?redir=%s">%s: %d</a>' %{
url(category, 'uci/changes'), url(category, 'uci/changes'),
http.urlencode(http.formvalue('redir') or REQUEST_URI), http.urlencode(http.formvalue('redir') or table.concat(disp.context.request, "/")),
translate('Unsaved Changes'), translate('Unsaved Changes'),
ucic ucic
}) })