Skip to content

Public Webforms: Deep-link handling and security - #1792

Open
nospame wants to merge 8 commits into
ejp/public-webforms-authfrom
ejp/public-webforms-confinement
Open

Public Webforms: Deep-link handling and security#1792
nospame wants to merge 8 commits into
ejp/public-webforms-authfrom
ejp/public-webforms-confinement

Conversation

@nospame

@nospame nospame commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Product Description

Public Web Apps Sessions let someone open a one-time link and fill a single, pre-designated form
without an HQ account. This PR is where that behavior is confined: a public session can reach only
the form-entry routes it needs, and is locked to the exact app, endpoint, and identity HQ bound the
link to — it cannot navigate to any other app or form.

Technical Summary

SAAS-19928, SAAS-19929, SAAS-19930

  • Second of three public webforms PRs in this repo; builds on Public Webforms: Authentication #1791. Adds the confinement layer:
    • WebSecurityConfig: restrictPublicSession(...) default-deny allowlist on /validate_form and
      anyRequest. A public session may reach only get_endpoint + the in-form actions; new-form
      and validate_form are denied.
    • get_endpoint/new-repeat: sessionid cookie binding relaxed to required=false (public
      sessions carry no Django cookie).
    • HqUserDetailsBean: HQ-authoritative app_build_id + endpoint_id.
    • PublicSessionLockAspect (ordered ahead of all other aspects): overrides client-supplied app,
      endpoint, endpoint args, and identity with HQ's values; fails closed if they're missing.
    • UserRestoreAspect#configureRestoreFactory: a public session restores strictly as its
      HQ-authenticated user (no client username / restore-as / case id).
    • MenuSessionRunnerService: public sessions use endpoint navigation without the
      SESSION_ENDPOINTS toggle - rather than building out a new method of navigation or
      requiring the toggle to be enabled in HQ.

Code and PR description written or co-written by AI and edited by human. Review by commit.

Safety Assurance

Safety story

The core safety property is default-deny: restrictPublicSession only ever removes access, and
only when the principal is a public session — regular sessions get exactly their prior decision. The
lock aspect and restore pinning both fail closed on missing authoritative values, and a public
session restores under its own synthetic user, so no real user's sandbox or identity is touched.
Aspect ordering (a subtle correctness requirement) is guarded by a dedicated weaving test after a
real ordering bug was caught there. Still inert in production until HQ issues links.

Automated test coverage

  • SessionAuthTests — allowlist: allowed routes not 403, new-form/validate_form denied, regular
    sessions unaffected.
  • PublicSessionLockAspectTest — app/endpoint/identity override + fail-closed cases.
  • PublicSessionLockAspectWeavingTest — proves the aspect actually weaves and is correctly ordered.
  • EndpointLaunchTest — public launch without the SESSION_ENDPOINTS toggle.
  • HqUserDetailsTests + test harness (@WithHqUser public flag).

QA Plan

Public Webforms will get end-to-end QA before its release.

Special deploy instructions

  • Cross-repo dependency: relies on HQ's session_details returning app_build_id + endpoint_id
    for public sessions. Safe to deploy formplayer first (feature stays dark until HQ issues links), but
    the feature must not be enabled on HQ until this is deployed.

Rollback instructions

  • This PR can be reverted after deploy with no further considerations.

Review

  • The set of people pinged as reviewers is appropriate for the level of risk of the change.

@nospame nospame mentioned this pull request Jul 28, 2026
2 tasks
@nospame
nospame changed the base branch from ejp/public-webforms-auth to ejp/public-webforms-base July 28, 2026 17:52
@nospame
nospame force-pushed the ejp/public-webforms-confinement branch from 3207aa0 to eecb372 Compare July 28, 2026 17:55
@nospame
nospame marked this pull request as ready for review August 11, 2026 16:24
@nospame
nospame marked this pull request as draft August 11, 2026 16:25
@nospame
nospame changed the base branch from ejp/public-webforms-base to ejp/public-webforms-auth August 11, 2026 16:25
@nospame
nospame marked this pull request as ready for review August 11, 2026 16:26
nospame and others added 7 commits August 11, 2026 09:34
A public web apps session authenticates with the public_form_session_key
cookie, not the Django sessionid, so the required sessionid @CookieValue on
MenuController.navigateToEndpoint (get_endpoint) rejected it at request
binding (400) before the handler. Relax that cookie to required=false, as
answer/submit-all already do. A cookie-less non-public request is still rejected
upstream by the session auth request matcher.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add a default-deny route allowlist for public web apps sessions, enforced
in the Spring Security authorization layer. getPublicSessionAuthManager
grants a request if it is authenticated AND either the principal is not a
public session or the path is one of specified form-navigation routes.
Every other route is denied with the app's standard 403 before any controller
or aspect runs.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
For a public web apps session, HQ's session_details response carries the
app id and session endpoint that the one-time link is bound to. Add
publicAppId (@JsonProperty "commcare_app_id") and publicEndpointId
(@JsonProperty "endpoint_id") to the bean. Reference types, so they default
to null for non-public responses that omit them.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Both app_id and endpoint_id in a get_endpoint request are client-supplied, so
a valid public session key could otherwise open any app/form in the domain.
PublicSessionLockAspect, for a public session, replaces the request's app_id
and endpoint_id with the HMAC-authenticated values HQ returned
(HqUserDetailsBean.publicAppId/publicEndpointId) and clears endpoint args,
confining the session to its one designated form. It fails closed if HQ did
not supply those authoritative values rather than trusting the client.

Runs before AppInstallAspect (which keys the sandbox DB off the request's
app_id), so storage, the MenuSession build, and endpoint navigation all use
the authoritative app.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The lock aspect silently returned if the first handler arg was not an
InstallRequestBean, which for a public session would let the request
proceed without pinning it to the authoritative app/endpoint. Unreachable today (every allowlisted @appinstall route takes a
SessionNavigationBean), but preserves the fail-closed contract for any
future allowlisted route with a different request bean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
A public web apps session is a one-time deep link into a single endpoint,
so endpoint navigation is intrinsic to it. For public sessions, bypass thegate via a new RequestUtils.isPublicSession() predicate.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
A public session's username is never validated (isAuthorized skips it),
and configureRestoreFactory took username/restoreAs/restoreAsCaseId
straight from the client request bean.
Instead, configure the restore for a public session from the HMAC-authenticated principal only, ignoring all client-supplied
identity fields.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@nospame
nospame force-pushed the ejp/public-webforms-confinement branch from eecb372 to 7251404 Compare August 11, 2026 16:37
@nospame
nospame requested review from dannyroberts and removed request for shubham1g5 August 11, 2026 16:41
Verify ownership at the single load chokepoint, FormSessionFactory: a
public session may only build a live session whose stored username and
domain match its HMAC-authenticated principal; otherwise throw
FormNotFoundException.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@nospame
nospame force-pushed the ejp/public-webforms-confinement branch from 7251404 to ca819c9 Compare August 11, 2026 17:58
@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.95652% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.45%. Comparing base (0388456) to head (ca819c9).

Files with missing lines Patch % Lines
...re/formplayer/aspects/PublicSessionLockAspect.java 83.33% 1 Missing and 4 partials ⚠️
...re/formplayer/configuration/WebSecurityConfig.java 88.88% 0 Missing and 2 partials ⚠️
...commcare/formplayer/aspects/UserRestoreAspect.java 80.00% 0 Missing and 1 partial ⚠️
...ava/org/commcare/formplayer/util/RequestUtils.java 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@                      Coverage Diff                       @@
##             ejp/public-webforms-auth    #1792      +/-   ##
==============================================================
+ Coverage                       70.28%   70.45%   +0.17%     
- Complexity                       2046     2079      +33     
==============================================================
  Files                             259      260       +1     
  Lines                            8039     8103      +64     
  Branches                          767      790      +23     
==============================================================
+ Hits                             5650     5709      +59     
+ Misses                           2104     2099       -5     
- Partials                          285      295      +10     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant