Add authentication policy setting
This commit is contained in:
@@ -263,12 +263,18 @@ export const MESSAGE_KINDS = [...CONTENT_KINDS, MESSAGE]
|
||||
|
||||
export const SETTINGS = "flotilla/settings"
|
||||
|
||||
export enum RelayAuthMode {
|
||||
Aggressive = "aggressive",
|
||||
Conservative = "conservative",
|
||||
}
|
||||
|
||||
export type SettingsValues = {
|
||||
show_media: boolean
|
||||
hide_sensitive: boolean
|
||||
trusted_relays: string[]
|
||||
report_usage: boolean
|
||||
report_errors: boolean
|
||||
relay_auth: RelayAuthMode
|
||||
send_delay: number
|
||||
font_size: number
|
||||
play_notification_sound: boolean
|
||||
@@ -280,12 +286,13 @@ export type Settings = {
|
||||
values: SettingsValues
|
||||
}
|
||||
|
||||
export const defaultSettings = {
|
||||
export const defaultSettings: SettingsValues = {
|
||||
show_media: true,
|
||||
hide_sensitive: true,
|
||||
trusted_relays: [],
|
||||
report_usage: true,
|
||||
report_errors: true,
|
||||
relay_auth: RelayAuthMode.Conservative,
|
||||
send_delay: 0,
|
||||
font_size: 1.1,
|
||||
play_notification_sound: true,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {on, always, call, dissoc, assoc, uniq} from "@welshman/lib"
|
||||
import {get} from "svelte/store"
|
||||
import {on, call, dissoc, assoc, uniq} from "@welshman/lib"
|
||||
import {RelayMode} from "@welshman/util"
|
||||
import type {Socket, RelayMessage, ClientMessage} from "@welshman/net"
|
||||
import {
|
||||
@@ -20,9 +21,27 @@ import {
|
||||
getSetting,
|
||||
relaysPendingTrust,
|
||||
relaysMostlyRestricted,
|
||||
RelayAuthMode,
|
||||
NOTIFIER_RELAY,
|
||||
userSpaceUrls,
|
||||
} from "@app/core/state"
|
||||
|
||||
export const authPolicy = makeSocketPolicyAuth({sign, shouldAuth: always(true)})
|
||||
export const authPolicy = makeSocketPolicyAuth({
|
||||
sign,
|
||||
shouldAuth: (socket: Socket) => {
|
||||
const $pubkey = pubkey.get()
|
||||
const mode = getSetting<RelayAuthMode>("relay_auth")
|
||||
|
||||
if (!$pubkey) return false
|
||||
if (socket.url === NOTIFIER_RELAY) return true
|
||||
if (mode === RelayAuthMode.Aggressive) return true
|
||||
if (get(userSpaceUrls).includes(socket.url)) return true
|
||||
if (getPubkeyRelays($pubkey).includes(socket.url)) return true
|
||||
if (getPubkeyRelays($pubkey, RelayMode.Messaging).includes(socket.url)) return true
|
||||
|
||||
return false
|
||||
},
|
||||
})
|
||||
|
||||
export const blockPolicy = (socket: Socket) => {
|
||||
const previousOpen = socket.open
|
||||
|
||||
Reference in New Issue
Block a user