Skip to content

Fix the /web demo on instances that do not serve site remark - #2264

Open
paskal wants to merge 3 commits into
masterfrom
fix-web-demo-site
Open

paskal wants to merge 3 commits into
masterfrom
fix-web-demo-site

Conversation

@paskal

@paskal paskal commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator

Previously, the binary served the demo, counter and last-comments pages for site remark, as the build emits them; only the docker image replaced that with the configured site. On any other site the demo's API requests failed with "site not found", and opening it signed the reader out of their real site: its widget asked for the user on site remark, the server answered 403 because the session belongs to another site, and the frontend cleared the auth cookies on that 403.

After this change, the file server fills the first configured site into those pages as the docker image does, and includes it in the cache validator. The frontend keeps the session on 403, since permission failures come with a valid session, and logout always forgets the local session, including when an expired header token makes it answer 403. The release build now checks that the demo pages keep the site_id:"remark" literal the server replaces and the docker image's pattern expects.

Tests cover the demo site substitution, cache invalidation, site selection, the session kept on 403 and the logout cleanup; each fails with its change reverted. A browser check of a build serving only --site=myblog confirmed that /web/ used that site and kept the reader signed in.

Resolves #2251.

@paskal
paskal requested a review from umputun as a code owner October 11, 2026 06:44
Copilot AI balanced review requested due to automatic review settings October 11, 2026 06:44
@codecov

codecov Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.98%. Comparing base (529621e) to head (6cdc1a2).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2264      +/-   ##
==========================================
+ Coverage   74.56%   74.98%   +0.41%     
==========================================
  Files         129      129              
  Lines        3751     3754       +3     
  Branches      829      829              
==========================================
+ Hits         2797     2815      +18     
+ Misses        948      933      -15     
  Partials        6        6              
Flag Coverage Δ
unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

size-limit report 📦

Path Size
public/embed.mjs 2.05 KB (0%)
public/remark.mjs 53.83 KB (+0.03% 🔺)
public/remark.css 7 KB (+0.02% 🔺)
public/last-comments.mjs 17.36 KB (-0.04% 🔽)
public/last-comments.css 3.22 KB (0%)
public/deleteme.mjs 2.98 KB (-0.23% 🔽)
public/counter.mjs 731 B (0%)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Logout rejection still leaves UI state uncleared, and another Go 1.27 lint workflow remains on an incompatible version.

2 open findings
What changed in this PR

Fixes /web demos for non-default sites while preserving valid sessions on 403 responses.

Changes:

  • Substitutes the first configured site into demo pages and cache validators.
  • Retains sessions on 403 and clears credentials during logout.
  • Updates release checks, tests, and backend lint tooling.
File Description
scripts/​prepare-release-assets.sh Validates demo site literals.
frontend/​apps/​remark42/​app/​components/​auth/​auth.api.ts Clears credentials on logout.
frontend/​apps/​remark42/​app/​components/​auth/​auth.api.spec.ts Tests logout cleanup.
frontend/​apps/​remark42/​app/​common/​fetcher.ts Retains sessions on 403.
frontend/​apps/​remark42/​app/​common/​fetcher.test.ts Tests 401/403 handling.
backend/​app/​rest/​api/​webfiles.go Substitutes demo site IDs.
backend/​app/​rest/​api/​webfiles_test.go Tests substitution and ETags.
backend/​app/​rest/​api/​rest.go Configures site-aware web serving.
backend/​app/​rest/​api/​rest_test.go Updates file-server tests.
backend/​app/​cmd/​server.go Selects the demo site.
backend/​app/​cmd/​server_test.go Tests site selection.
.github/​workflows/​ci-backend.yml Updates golangci-lint.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread .github/workflows/ci-backend.yml
*/
export function logout(): Promise<void> {
return authFetcher.get('/logout');
return authFetcher.get<void>('/logout').finally(dropSession);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in a9dc97a: logout() now ignores the request failure once the session is dropped, so the signout action goes on to clear the signed-in user and the profile resets its signing-out state. The logout test now expects resolution, and a new store test checks that signout sets the user to null after a refused logout.

umputun
umputun previously approved these changes Oct 11, 2026

@umputun umputun left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

lgtm. #2262 went in first and changes the same places in backend/app/cmd/server.go and server_test.go, so this one conflicts now and needs a rebase.

The build emits the demo, counter and last-comments pages for site
remark. The docker image replaces that with the first configured site
at container start, but the binary served them as built, so on an
instance serving another site the demo's API requests failed with
"site not found" and its widget asked about a site the reader was not
signed in to.

The file server now fills in the first configured site the same way,
in the html files the docker image rewrites, and the site is part of
the cache validator so a changed SITE is not answered with 304. The
release build fails if those pages lose the site_id:"remark" literal
the server replaces and the docker image's pattern expects.
The fetcher cleared the auth cookies on 403 as well as 401. The server
answers 403 to a valid session that may not do something, such as one
issued for another site served from the same remark42 host, an
anonymous user, or a non-admin. Clearing the shared XSRF cookie then
could sign the reader out of the other sites using those cookies too.

Cookies are now cleared only on 401, which is what an invalid session
gets. Logout is the one place a 403 can mean the session is over: an
expired token sent as a header is refused there, so logout now forgets
the local session whatever the server answers.
The logout request dropped the local session and then rejected, and
the signout action clears the signed-in user only after it resolves,
so a refused logout, such as an expired header token answered with 403,
left the widget showing the reader as signed in without credentials.
The request failure is now ignored once the session is dropped.
@paskal

paskal commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased onto master. demoSiteID now sits next to tokenAudiences and servesAudience in server.go, and its test next to theirs in server_test.go; nothing else changed. The golangci-lint commit dropped out, as master already has it.

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.

/web/ Malfunction

3 participants