fix(stateadmin): drop the default users collection and pin the sqlite driver
PocketBase creates a "users" auth collection on first bootstrap whose createRule is open, so an unauthenticated caller could POST a record and write a row into the State Store's database file. This surface authenticates superusers only and has no notion of end users, so the collection is deleted rather than given a tighter rule: one that is absent cannot be loosened again by a later PocketBase default. Also re-applies the modernc pin. It was applied while developing the previous commit but a concurrent go.mod resolution reverted it before that commit was taken, so the tree has been running 1.59.0/1.77.1 against a PocketBase built and tested on 1.57.0/1.74.4, printing the mismatch warning on every start. Note for future dependency work: go get -u will undo this pin, and modernc.org/libc does not follow semver, which is why PocketBase checks. The claim in the previous commit message that the pin landed there is wrong.
This commit is contained in:
4 files changed
+59
-2
No files matched your search
@@ -107,6 +107,9 @@ func New(cfg Config) (*Server, error) {
|
||||
if err := app.RunAllMigrations(); err != nil {
|
||||
return nil, fmt.Errorf("stateadmin: run migrations: %w", err)
|
||||
}
|
||||
if err := removeDefaultAuthCollection(app); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := registerViews(app); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -144,6 +147,25 @@ func registerViews(app core.App) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// removeDefaultAuthCollection deletes the "users" collection PocketBase
|
||||
// creates on first bootstrap.
|
||||
//
|
||||
// Its createRule is open, so leaving it in place lets an unauthenticated
|
||||
// caller POST a record and write a row into the State Store's database file.
|
||||
// This surface authenticates superusers only and has no notion of end users,
|
||||
// so the collection is deleted rather than given a tighter rule: a collection
|
||||
// that is not there cannot be loosened again by a later PocketBase default.
|
||||
func removeDefaultAuthCollection(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("users")
|
||||
if err != nil {
|
||||
return nil // already absent, including on every restart after the first
|
||||
}
|
||||
if err := app.Delete(collection); err != nil {
|
||||
return fmt.Errorf("stateadmin: remove default users collection: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// refuseWritePaths answers every refusedPrefixes route with 404.
|
||||
func refuseWritePaths(r *router.Router[*core.RequestEvent]) {
|
||||
r.BindFunc(func(e *core.RequestEvent) error {
|
||||
|
||||
Reference in new issue
Block a user