Skip to content

Commit d108cc1

Browse files
authored
fix: strip the development forum's accounts and sessions from the Flarum seed (#9127)
### What changes were proposed in this PR? `bin/forum/flarum.sql` was dumped from a development forum and still held its member accounts, login sessions, visit logs with IP addresses, and an API key that the dashboard's forum sign-up sent. - `flarum.sql`: the three seeded accounts get placeholder emails (`@example.com`) and no password, so their posts stay but nobody can sign in as them. The sessions, the API key and the visit log are dropped, and the posts' IP addresses are cleared. - Sign-up without the key: the seed already allows open sign-up (`allow_sign_up = 1`), so the key only let `FlarumService.register` skip Flarum's CSRF check. The new `bin/extend.php` exempts the sign-up route instead (by default Flarum exempts only login), and both install scripts copy it into the forum. ### Any related issues, documentation, discussions? Closes #9126. Independent of #9005, which is under discussion in #9006. ### How was this PR tested? - `flarum.service.spec.ts` now checks that sign-up sends no `Authorization` header. It passes, and fails against the old service. - On Flarum 1.8.5 (the seed's version) with the cleaned seed: the seed imports, sign-up then login works with `extend.php`, sign-up is rejected by the CSRF check without it, and the seeded accounts cannot sign in. ### Was this PR authored or co-authored using generative AI tooling? Generated-by: Claude Code (claude-opus-5-5)
1 parent 98c6337 commit d108cc1

7 files changed

Lines changed: 37 additions & 15 deletions

File tree

‎bin/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,5 @@ binary `NOTICE`/`LICENSE` files (`audit_jar_licenses.py`,
8585
| `pylsp/` | Dockerized Python language server used by the UDF editor. |
8686
| `y-websocket-server/` | Dockerized Yjs websocket server backing collaborative editing. |
8787
| `forum/` | Flarum-based community forum setup (install scripts and seed SQL). |
88-
| `config.php`, `.htaccess` | Flarum runtime config and Apache rewrite rules for the forum. |
88+
| `config.php`, `extend.php`, `.htaccess` | Flarum runtime config, extenders, and Apache rewrite rules for the forum. |
8989
| `litellm-config.yaml` | LiteLLM proxy configuration for AI features. |

‎bin/extend.php‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
19+
use Flarum\Extend;
20+
21+
// The Texera dashboard signs users up to the forum through Flarum's API
22+
// (FlarumService.register). Flarum exempts only its login route from CSRF
23+
// checks, so exempt the sign-up route too. Whether anyone may sign up is still
24+
// decided by the forum's allow_sign_up setting.
25+
return [
26+
(new Extend\Csrf())->exemptRoute('users.create'),
27+
];

‎bin/forum/flarum.sql‎

Lines changed: 2 additions & 5 deletions
Large diffs are not rendered by default.

‎bin/forum/macos-install.sh‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ composer create-project flarum/flarum /opt/homebrew/var/www/flarum
2929
composer require --working-dir=/opt/homebrew/var/www/flarum michaelbelgium/flarum-discussion-views
3030
composer require --working-dir=/opt/homebrew/var/www/flarum fof/byobu:"*"
3131
cp config.php /opt/homebrew/var/www/flarum/config.php
32+
cp extend.php /opt/homebrew/var/www/flarum/extend.php
3233
cp .htaccess /opt/homebrew/var/www/flarum/public/.htaccess
3334

3435
# Database Configuration

‎bin/forum/ubuntu-install.sh‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ composer create-project flarum/flarum /opt/flarum
3232
composer require --working-dir=/opt/flarum michaelbelgium/flarum-discussion-views
3333
composer require --working-dir=/opt/flarum fof/byobu:"*"
3434
sudo cp bin/config.php /opt/flarum/config.php
35+
sudo cp bin/extend.php /opt/flarum/extend.php
3536
sudo cp bin/.htaccess /opt/flarum/public/.htaccess
3637
sudo chown -R www-data:www-data /opt/flarum
3738
sudo mysql -u root -p < sql/flarum.sql

‎frontend/src/app/dashboard/service/user/flarum/flarum.service.spec.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe("FlarumService", () => {
5858
5959
password: "secret-token",
6060
});
61-
expect(req.request.headers.get("Authorization")).toContain("Token ");
61+
expect(req.request.headers.has("Authorization")).toBe(false);
6262
req.flush({});
6363
});
6464

‎frontend/src/app/dashboard/service/user/flarum/flarum.service.ts‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,11 @@ export class FlarumService {
3232

3333
register() {
3434
const user = this.userService.getCurrentUser();
35-
return this.http.post(
36-
"forum/api/users",
37-
{
38-
data: {
39-
attributes: { username: user!.email.split("@")[0] + user!.uid, email: user!.email, password: user!.googleId },
40-
},
35+
return this.http.post("forum/api/users", {
36+
data: {
37+
attributes: { username: user!.email.split("@")[0] + user!.uid, email: user!.email, password: user!.googleId },
4138
},
42-
{ headers: { Authorization: "Token hdebsyxiigyklxgsqivyswwiisohzlnezzzzzzzz;userId=1" } }
43-
);
39+
});
4440
}
4541

4642
auth() {

0 commit comments

Comments
 (0)