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

luci-base: add hardening header #1555

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion modules/luci-base/luasrc/dispatcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ function dispatch(request)
return
end

http.header("Set-Cookie", 'sysauth=%s; path=%s' %{ sid, build_url() })
http.header("Set-Cookie", 'sysauth=%s; path=%s; HttpOnly; secure' %{ sid, build_url() })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The secure attribute should only be enabled if HTTPS is on, otherwise browsers will ignore Set-Cookie and users cannot login. It is indeed the case when I patched 17.01.04 armvirt qemu image to test this.

http.redirect(build_url(unpack(ctx.requestpath)))
end

Expand All @@ -418,6 +418,13 @@ function dispatch(request)
ctx.authsession = sid
ctx.authtoken = sdat.token
ctx.authuser = sdat.username

if http.getenv("HTTPS") == "on" then
local forcehsts = conf.main.forcehsts
if forcehsts then
http.header("Strict-Transport-Security", 'max-age=%s' % forcehsts)
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change should better go to uhttpd2

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yousong i do not know uhttpd2?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhttpd2 is the default HTTP server in OpenWrt. Since the certs, keys etc. required for https are configured on uhttpd, the hsts knob naturally should also go there.

[1] http://lxr.mein.io/source/uhttpd2/proc.c#L150

end

if c and require_post_security(c.target) then
Expand Down