Repository navigation
Conversation
|
Tested against a real site's data: master with this PR merged (84b6dc3), behind Apache httpd and a TLS-terminating proxy, with two
Not covered: remember-me with the box ticked, logout, AtomPub, XML-RPC, OIDC and a browser. |
b96e88c to
56f6948
Compare
bf53560 to
5548e1c
Compare
fea49d4 to
86b1d10
Compare
SecurityConfig replaces WEB-INF/security.xml and is loaded by the web application context that web.xml sets up. The filter chain keeps the same URL rules, form login, OpenID Connect login, remember-me, headers and static-file exceptions. A new SecurityConfigTest sends requests through the chain; its table was recorded from security.xml, and the two configurations gave the same result for every request except one: with remember-me off, a failed login no longer clears a remember-me cookie that was never set. RollerContext no longer looks up beans by the names the XML namespace generated. SecurityConfig sets the password encoder, the HTTPS-only login entry point and remember-me from roller.properties, and RollerContext shares the same encoder, now built by RollerPasswordEncoders. LDAP login is configured with new users.ldap.* properties instead of uncommented beans, and sites can add URL rules with security.access.<path>=<roles> properties, matched without regard to case. CHANGES and the install guide describe both.
Roller protects its own forms with the salt that LoadSaltFilter and ValidateSaltFilter check on every POST under /roller-ui, so Spring's CSRF protection stays off, as it was in security.xml. The login form posts to /roller_j_security_check, outside /roller-ui, so nothing protected it. SecurityConfig now requires Spring's CSRF token for that POST only, and Login.jsp sends it. The token is created only when the login page asks for it, so other pages still don't start a session. SecurityConfigTest logs in with the token from the login page and checks that a login post without it gets 403. CHANGES notes that scripts posting straight to /roller_j_security_check need the token.
The checkbox was still named _spring_security_remember_me, Spring Security 3's parameter. RollerRememberMeServices uses Spring's default parameter, remember-me, so ticking the box set no cookie on sites with rememberme.enabled=true. It also failed with security.xml. SecurityConfigTest now reads the checkbox name from Login.jsp, so the test fails if the page and the remember-me services disagree.
Rebased on apache#301, SecurityConfig gives the database login provider the user service as its UserDetailsPasswordService. SecurityConfigTest logs in through the filter chain as a user with an unsalted SHA-1 hash and checks that the stored password becomes {bcrypt}.
A login posted without a valid CSRF token, for example from a login page left open past the session timeout, from a second tab, or after a server restart, now redirects to the login page with a message to try again instead of showing the access-denied page. Other refused requests still get the 403 page.
…onfig Follow-ups from a review of the Java configuration: - security.access.* rules now add to Roller's own rules instead of replacing them: a request has to pass both, so a broad rule such as /**=member can't open the admin or authoring pages to other roles. The login page, the login and OAuth2 endpoints, logout and the files the login page loads are left out of these rules, so a rule for /** no longer locks everyone out. - When several rules match, the most specific one applies (PathPattern specificity instead of pattern length), and a rule with a path that can't be parsed stops the start with a message naming the property. - The request that needed a login is saved whatever its method, as security.xml did; configuring CSRF had made Spring save only GET requests. - Roller refuses to start while a WEB-INF/security.xml is still in place, so a customized copy isn't ignored without notice. - A blank users.ldap.defaultRole gives directory users only their Roller roles instead of stopping the start. - The remember-me signature override uses the method Spring Security 7 calls, and a directory user without a Roller account who ticks "Remember me" is logged in without a cookie instead of being shown a wrong-password message. - The LDAP test checks that the directory is the only provider that checks passwords, and the install guide and CHANGES describe the access-denied page, the LDAP-only login and the new rules.
… a POST after login - security.access.* rules now check REQUEST dispatches only, the paths visitors ask for. Roller forwards the login action to its JSP, and a rule for /** caught that forward, so the login page redirected to itself. Roller's own rules still apply to forwards as before. - The request cache is back to Spring's default, which saves only GET requests. Saving any method, as security.xml did, sent the browser back to a form's address after login with the old submission, which Roller's salt check refuses with an error page. - webjars and oauth2 are reserved like theme, so no weblog handle can share a path that security.access rules leave out. - The leftover security.xml message is also logged to Roller's log.
- "Remember me" isn't offered with LDAP login: the cookie is checked against Roller's database only, so it would keep working after the directory account changed or was removed. - security.access.* rules leave the install, upgrade, bootstrap-token and first-registration pages alone while Roller is being set up, so a rule for /** can't block installing or upgrading. - The login page's stylesheet and images (/roller-ui/styles, /roller-ui/images) are left out of the rules too. - Only /images skips the security filter chain; there are no /scripts or /styles directories at the root. - New weblogs can't take a reserved handle such as webjars or oauth2. - LDAP connections have connect and read timeouts (users.ldap.connectTimeout, users.ldap.readTimeout), and other JNDI settings can be given as users.ldap.env.* properties. - Each rule's authority check is built once, and the roller.properties comment says the rules add to Roller's own.
Roller renders a weblog's pages, feeds, resources, search results and comments at /roller-ui/rendering/<servlet>/<handle>/... as well as at /<handle>/.... security.access rules now apply to the first as if it were the second, so a rule for a weblog covers both. Uploaded media files are served by their ID, so the install guide notes that a rule doesn't hide a file from someone who has its address.
0a7cb55 to
2b8eece
Compare
…ached - A weblog's media addresses under /roller-ui/rendering/media-resources/<handle>/ are checked as if they were the weblog's own path, like its pages and feeds. With apache#308, a media file is only served at its own weblog's address, so the install guide no longer needs its note about media files. - Roller's own static files (/images, /theme, /webjars, /roller-ui/styles, /roller-ui/scripts, /roller-ui/images) skip the security filter chain, so they're served without Cache-Control: no-store and can be cached. Each path is under a reserved name.
snoopdave
left a comment
There was a problem hiding this comment.
Review of 0b95fdc0b: The Java configuration and tests cover the main login and URL behavior. Two verified gaps remain in how site access rules apply to rendering paths.
…d serve Roller UI theme files without the security chain A request under /roller-ui/rendering/<servlet>/<handle>/ is now checked only against the most specific security.access rule for the weblog's own path, so with /**=member and /fam/**=family a family user can read /roller-ui/rendering/page/fam/... just as they can read /fam/.... A new test covers those overlapping rules on public and rendering URLs. /roller-ui/theme/** joins the static paths that skip the security filter chain, so the front-page theme images can be cached and load without a login when a rule covers /**.
… address A rendering address such as /roller-ui/rendering/media-resources/fam/abc was matched as /fam/abc, so a rule for /fam/mediaresource/**, /fam/feed/**, /fam/resource/**, /fam/search or /fam/rsd did not apply to it. The path is now rebuilt the way WeblogRequestMapper maps it, including a locale before the feed or search element. A rendering path holding a line break the request firewall lets through, such as U+0085, no longer skips the weblog's rule. WeblogRequestMapper now ignores case when it checks a handle against the reserved names, so a weblog named webjars or oauth2 is not shown at /WebJars/ on a database that ignores case. SecurityConfigTest now removes a property that was unset before a test set it more than once.
snoopdave
left a comment
There was a problem hiding this comment.
Review of 035144498: The current diff covers the earlier review points. I found no new verified defects in the code or tests reviewed; this was a read-only review, with no build run.
Earlier comments: 4 of 4 resolved.
No new issues found.
# Conflicts: # app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerRememberMeServices.java
…emoves Spring Security 7 never called RollerRememberMeServices.makeTokenSignature, so this change removes the override and doesn't offer remember-me with LDAP login. The test that came from master with the merge exercised that override.
Replaces
WEB-INF/security.xmlwith a JavaSecurityConfig, loaded by the annotation-based web application context thatweb.xmlnow sets up. It removes a file admins edit, so it belongs in the major release, and Spring Security 7's MFA support is only available through Java config, which we want for 7.1.The filter chain keeps the same URL rules, form login, OpenID Connect login, remember-me, security headers and saved request after login. Roller's own static files (
/images,/theme,/webjars,/roller-ui/styles,/roller-ui/scripts,/roller-ui/images,/roller-ui/theme) skip the chain, so they can be cached; each is under a reserved name.security.xmllisted/scriptsand/stylestoo, which don't exist at the root.This also fixes the login page's "Remember me" checkbox. It was named
_spring_security_remember_me, Spring Security 3's parameter, while Roller's remember-me services read Spring's default,remember-me, so ticking it set no cookie. That was broken withsecurity.xmltoo.SecurityConfigTestreads the checkbox name fromLogin.jsp, so it fails if the two disagree again. "Remember me" isn't offered with LDAP login, since a remembered login is checked against Roller's database only and would outlive a change to the directory account; Roller's old LDAP signature override was never called by Spring Security 7 and is removed.One deliberate change: the login form now needs Spring Security's CSRF token. Roller protects its own forms with the salt that
LoadSaltFilterandValidateSaltFiltercheck on every POST under/roller-ui, so Spring's CSRF protection stays off elsewhere, as it was insecurity.xml. The login form posts to/roller_j_security_check, outside/roller-ui, so nothing protected it.SecurityConfignow requires the token for that POST only, andLogin.jspsends it. The token is created only when the login page asks for it, so other pages still don't start a session. A login posted without a valid token, for example from a login page left open past the session timeout, goes back to the login page with "The login page expired. Please try again." CHANGES notes that scripts posting straight to the login URL need to send the token.SecurityConfigTestsends requests through the chain built fromSecurityConfig. Its table was recorded fromsecurity.xmlfirst, before the login CSRF change. The two configurations gave the same status, redirect, response headers and session behaviour for every request, including FORWARD and ERROR dispatches, the saved request after login and the default request firewall, except one: with remember-me off, a failed login no longer sends a header clearing a remember-me cookie that was never set. It also covers overlapping/**and/fam/**rules on a weblog's public and rendering addresses.security.xmlsaved any method, so after logging in, a form submitted with an expired session was sent back to its address with the old submission, which Roller's salt check refused with an "Unexpected Exception" page (RC1 does this too). The login now goes to the start page instead, and CHANGES has a bug-fix entry.RollerContextno longer looks up beans by the names the XML namespace generated (DaoAuthenticationProvider#0,_formLoginEntryPointand the authentication manager).SecurityConfigsets the password encoder, the HTTPS-only login entry point (securelogin.enabled) and remember-me (rememberme.enabled) fromroller.properties, and each of these has a test. The encoder factory isRollerPasswordEncoders, andRollerContext.getPasswordEncoder()returns the same instance the login provider uses, which also upgrades passwords stored with an older encoding at login (Upgrade passwords stored with an older encoding at login #301).RollerRememberMeAuthenticationProvideris removed.rememberMe()creates a provider with the remember-me services' key, which is the key Roller's provider used.For sites that edited
security.xml:WEB-INF/security.xmlis still in place, with a message in Roller's log saying where its settings went, so a customized copy isn't ignored without notice.authentication.method=ldapand newusers.ldap.url,users.ldap.managerDn,users.ldap.managerPassword,users.ldap.userSearchBase,users.ldap.userSearchFilterandusers.ldap.defaultRoleproperties, which map one-to-one to the beans the XML asked admins to uncomment. A blankusers.ldap.defaultRolegives directory users only their Roller roles. Directory connections time out (users.ldap.connectTimeout,users.ldap.readTimeout), and other JNDI settings areusers.ldap.env.<name>properties. As with the XML, LDAP replaces the database login; a test checks that the directory is the only provider that checks passwords.security.access.<path>=<roles>properties, matched without regard to case. They add to Roller's own rules (a request has to pass both, so a broad rule can't open the admin pages), the most specific matching rule applies, and they check the paths visitors request, not Roller's internal forwards to JSPs and servlets. A weblog's rendering addresses (/roller-ui/rendering/<servlet>/<handle>/...for pages, feeds, resources, media files, search, RSD and comments) are checked against the rules for the weblog's own path, and the most specific of those decides, so with/**=memberand/fam/**=familya family user can read/roller-ui/rendering/page/fam/...just as they can read/fam/.... For media files this relies on Serve a media file only at its own weblog's address #308, now merged, which serves a media file only at its own weblog's address. The login page, the login and OAuth2 endpoints, logout and the files the login page loads are left out of them, and so are the install, upgrade and first-registration pages while Roller is being set up, so a rule for/**doesn't lock everyone out.webjarsandoauth2join the reserved names, asthemealready was, and creating a weblog with a reserved handle is refused. A rule whose path can't be parsed stops the start with a message naming the property.Testing:
mvn testpasses.security.accessproperties gave anonymous visitors the login page, non-members 403 and members 200 for the weblog and its feed in any casing; the more specific of two overlapping rules decided; a leftoversecurity.xmlstopped the start with the message above; and a 1,741-address sample matched RC1 in status,Location, cookie names,Content-TypeandCache-Control. A/**rule was then checked onjetty:run: the login page renders and other pages ask for a login.jetty:runwith database login and against the Docker Compose stack (Tomcat, PostgreSQL, Keycloak) withdb-oidc; CI runs the db, db-oidc and oidc suites.A further review pass added these fixes:
security.accessrule for one part of a weblog, such as/fam/mediaresource/**or/fam/feed/**, also covers that part's internal rendering address, and a line break in the address no longer skips the rule.