Sign-in:
- Google, GitHub, Microsoft and any OpenID Connect provider, set up in the
admin panel (secrets are write-only). PocketBase talks to the provider,
and docwell-server keeps the state and PKCE verifier. Accounts a
provider creates follow the sign-up switch and the domain list; refused
ones are removed again.
- Two-step sign-in with an authenticator app (TOTP), set up under "Your
account", with ten single-use recovery codes. After any first factor
(password, email code, provider) the session is held behind a
five-minute challenge: five tries, each code works once. Turning it off
needs a code. Managers can reset it for someone who lost their phone.
Both the web app and the admin panel ask for the code.
Integrations:
- Personal API tokens ("dw_…") that act as their owner, read-only or
read-write, with optional expiry. Only a hash is stored, and the token is
shown once. Tokens cannot manage tokens or two-step sign-in. Admins see
and can revoke their organization's tokens.
- Workspace webhooks for page, comment and space events. Deliveries are
HMAC-SHA256 signed and retried (10 s, 1 min, 5 min), with a 30-day log
and a test button. Loopback and link-local addresses are refused
(DOCWELL_WEBHOOKS_ALLOW_LOCAL is for development).
Audit log: sign-ins (including failures and second steps, filed under the
account's organization) and every successful change request, by route and
path ids, never bodies. Superadmins see everything and org admins their
organization. It is searchable and exportable as CSV in the admin panel's
new Security page, and kept for DOCWELL_AUDIT_RETENTION_DAYS (365).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
39 lines
1.3 KiB
Go
39 lines
1.3 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
package webhooks
|
|
|
|
import (
|
|
"net"
|
|
"testing"
|
|
)
|
|
|
|
func TestGuard(t *testing.T) {
|
|
strict := guard(false)
|
|
for _, addr := range []string{"127.0.0.1:80", "[::1]:443", "169.254.169.254:80", "0.0.0.0:80", "[fe80::1]:80", "224.0.0.1:80"} {
|
|
if err := strict("tcp", addr, nil); err == nil {
|
|
t.Errorf("%s should be blocked", addr)
|
|
}
|
|
}
|
|
for _, addr := range []string{"93.184.216.34:443", "10.0.0.5:8080", "192.168.1.10:80", "[2606:4700::1]:443"} {
|
|
if err := strict("tcp", addr, nil); err != nil {
|
|
t.Errorf("%s should be allowed: %v", addr, err)
|
|
}
|
|
}
|
|
if err := guard(true)("tcp", net.JoinHostPort("127.0.0.1", "80"), nil); err != nil {
|
|
t.Errorf("AllowLocal should allow loopback: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestSignAndEvents(t *testing.T) {
|
|
// The well-known HMAC-SHA256 example.
|
|
if got := Sign("key", []byte("The quick brown fox jumps over the lazy dog")); got != "sha256=f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8" {
|
|
t.Fatalf("Sign = %q", got)
|
|
}
|
|
if !ValidEvent("page.created") || !ValidEvent("*") || ValidEvent("page.exploded") {
|
|
t.Fatal("ValidEvent")
|
|
}
|
|
if !subscribed([]string{"page.created"}, "page.created") || !subscribed([]string{"*"}, "x") || subscribed([]string{"page.created"}, "page.deleted") {
|
|
t.Fatal("subscribed")
|
|
}
|
|
}
|