Compare commits

..

No commits in common. "1fba91f77281ebd4d24f28b5d135c3a29654157d" and "9eac364e0173e68986e2299945f8506244d6fb45" have entirely different histories.

7 changed files with 190 additions and 133 deletions

View file

@ -113,15 +113,9 @@ export default apiRoute((app) => {
"json", "json",
z z
.object({ .object({
shortcode: CustomEmojiSchema.shape.shortcode shortcode: CustomEmojiSchema.shape.shortcode.max(
.max(config.validation.emojis.max_shortcode_characters) config.validation.emojis.max_shortcode_characters,
.refine( ),
(s) =>
!config.validation.filters.emoji_shortcode.some(
(filter) => filter.test(s),
),
"Shortcode contains blocked words",
),
element: z element: z
.string() .string()
.url() .url()

View file

@ -45,15 +45,9 @@ export default apiRoute((app) =>
validator( validator(
"json", "json",
z.object({ z.object({
shortcode: CustomEmojiSchema.shape.shortcode shortcode: CustomEmojiSchema.shape.shortcode.max(
.max(config.validation.emojis.max_shortcode_characters) config.validation.emojis.max_shortcode_characters,
.refine( ),
(s) =>
!config.validation.filters.emoji_shortcode.some(
(filter) => filter.test(s),
),
"Shortcode contains blocked words",
),
element: z element: z
.string() .string()
.url() .url()

View file

@ -1,12 +1,6 @@
import { zodToJsonSchema } from "zod-to-json-schema"; import { zodToJsonSchema } from "zod-to-json-schema";
import { ConfigSchema } from "./schema.ts";
await import("~/config.ts"); const jsonSchema = zodToJsonSchema(ConfigSchema, {});
// This is an awkward way to avoid import cycles for some reason console.write(`${JSON.stringify(jsonSchema, null, 4)}\n`);
await (async () => {
const { ConfigSchema } = await import("./schema.ts");
const jsonSchema = zodToJsonSchema(ConfigSchema, {});
console.write(`${JSON.stringify(jsonSchema, null, 4)}\n`);
})();

View file

@ -500,14 +500,9 @@ export class Note extends BaseInterface<typeof Notes, NoteTypeWithRelations> {
); );
const emojis = await Promise.all( const emojis = await Promise.all(
extensions?.["pub.versia:custom_emojis"]?.emojis extensions?.["pub.versia:custom_emojis"]?.emojis.map((emoji) =>
.filter( Emoji.fetchFromRemote(emoji, instance),
(e) => ) ?? [],
!config.validation.filters.emoji_shortcode.some(
(filter) => filter.test(e.name),
),
)
.map((emoji) => Emoji.fetchFromRemote(emoji, instance)) ?? [],
); );
const mentions = ( const mentions = (

View file

@ -181,7 +181,9 @@ export class InboxProcessor {
try { try {
await new EntitySorter(this.body) await new EntitySorter(this.body)
.on(VersiaEntities.Note, (n) => InboxProcessor.processNote(n)) .on(VersiaEntities.Note, async (n) => {
await Note.fromVersia(n);
})
.on(VersiaEntities.Follow, (f) => .on(VersiaEntities.Follow, (f) =>
InboxProcessor.processFollowRequest(f), InboxProcessor.processFollowRequest(f),
) )
@ -197,7 +199,9 @@ export class InboxProcessor {
.on(VersiaEntities.Delete, (d) => .on(VersiaEntities.Delete, (d) =>
InboxProcessor.processDelete(d), InboxProcessor.processDelete(d),
) )
.on(VersiaEntities.User, (u) => InboxProcessor.processUser(u)) .on(VersiaEntities.User, async (u) => {
await User.fromVersia(u);
})
.on(VersiaEntities.Share, async (s) => .on(VersiaEntities.Share, async (s) =>
InboxProcessor.processShare(s), InboxProcessor.processShare(s),
) )
@ -209,66 +213,6 @@ export class InboxProcessor {
} }
} }
/**
* Handles Note entity processing
*
* @param {VersiaNote} note - The Note entity to process.
* @returns {Promise<void>}
*/
private static async processNote(note: VersiaEntities.Note): Promise<void> {
// If note has a blocked word
if (
Object.values(note.content?.data ?? {})
.flatMap((c) => c.content)
.some((content) =>
config.validation.filters.note_content.some((filter) =>
filter.test(content),
),
)
) {
// Drop silently
return;
}
await Note.fromVersia(note);
}
/**
* Handles User entity processing.
*
* @param {VersiaUser} user - The User entity to process.
* @returns {Promise<void>}
*/
private static async processUser(user: VersiaEntities.User): Promise<void> {
if (
config.validation.filters.username.some((filter) =>
filter.test(user.data.username),
) ||
(user.data.display_name &&
config.validation.filters.displayname.some((filter) =>
filter.test(user.data.display_name ?? ""),
))
) {
// Drop silently
return;
}
if (
Object.values(user.bio?.data ?? {})
.flatMap((c) => c.content)
.some((content) =>
config.validation.filters.bio.some((filter) =>
filter.test(content),
),
)
) {
// Drop silently
return;
}
await User.fromVersia(user);
}
/** /**
* Handles Follow entity processing. * Handles Follow entity processing.
* *

View file

@ -57,14 +57,27 @@
"default": "versia" "default": "versia"
} }
}, },
"required": ["host", "username"], "required": [
"host",
"port",
"username",
"password",
"database"
],
"additionalProperties": false "additionalProperties": false
}, },
"description": "Additional read-only replicas", "description": "Additional read-only replicas",
"default": [] "default": []
} }
}, },
"required": ["username"], "required": [
"host",
"port",
"username",
"password",
"database",
"replicas"
],
"additionalProperties": false, "additionalProperties": false,
"description": "PostgreSQL database configuration" "description": "PostgreSQL database configuration"
}, },
@ -93,6 +106,7 @@
"default": 0 "default": 0
} }
}, },
"required": ["host", "port", "password", "database"],
"additionalProperties": false, "additionalProperties": false,
"description": "A Redis database used for managing queues." "description": "A Redis database used for managing queues."
}, },
@ -118,11 +132,12 @@
"default": 1 "default": 1
} }
}, },
"required": ["host", "port", "password", "database"],
"additionalProperties": false, "additionalProperties": false,
"description": "A Redis database used for caching SQL queries. Optional." "description": "A Redis database used for caching SQL queries. Optional."
} }
}, },
"required": ["queue"], "required": ["queue", "cache"],
"additionalProperties": false, "additionalProperties": false,
"description": "Redis configuration. Used for queues and caching." "description": "Redis configuration. Used for queues and caching."
}, },
@ -150,11 +165,12 @@
"$ref": "#/properties/postgres/properties/password" "$ref": "#/properties/postgres/properties/password"
} }
}, },
"required": ["password"], "required": ["host", "port", "password"],
"additionalProperties": false, "additionalProperties": false,
"description": "Sonic database configuration" "description": "Sonic database configuration"
} }
}, },
"required": ["enabled", "sonic"],
"additionalProperties": false, "additionalProperties": false,
"description": "Search and indexing configuration" "description": "Search and indexing configuration"
}, },
@ -175,6 +191,7 @@
"description": "Message to show to users when registration is disabled" "description": "Message to show to users when registration is disabled"
} }
}, },
"required": ["allow", "require_approval", "message"],
"additionalProperties": false "additionalProperties": false
}, },
"http": { "http": {
@ -233,12 +250,20 @@
"description": "This value must be a file path" "description": "This value must be a file path"
} }
}, },
"required": ["key", "cert"], "required": ["key", "cert", "passphrase", "ca"],
"additionalProperties": false, "additionalProperties": false,
"description": "TLS configuration. You should probably be using a reverse proxy instead of this" "description": "TLS configuration. You should probably be using a reverse proxy instead of this"
} }
}, },
"required": ["base_url"], "required": [
"base_url",
"bind",
"bind_port",
"banned_ips",
"banned_user_agents",
"proxy_address",
"tls"
],
"additionalProperties": false "additionalProperties": false
}, },
"frontend": { "frontend": {
@ -250,7 +275,7 @@
}, },
"path": { "path": {
"type": "string", "type": "string",
"default": "frontend" "default": "/home/jessew/Dev/versia-server"
}, },
"routes": { "routes": {
"type": "object", "type": "object",
@ -277,6 +302,13 @@
"default": "/oauth/reset" "default": "/oauth/reset"
} }
}, },
"required": [
"home",
"login",
"consent",
"register",
"password_reset"
],
"additionalProperties": false "additionalProperties": false
}, },
"settings": { "settings": {
@ -285,7 +317,7 @@
"default": {} "default": {}
} }
}, },
"required": ["routes"], "required": ["enabled", "path", "routes", "settings"],
"additionalProperties": false "additionalProperties": false
}, },
"email": { "email": {
@ -319,10 +351,17 @@
"default": true "default": true
} }
}, },
"required": ["server", "username"], "required": [
"server",
"port",
"username",
"password",
"tls"
],
"additionalProperties": false "additionalProperties": false
} }
}, },
"required": ["send_emails", "smtp"],
"additionalProperties": false "additionalProperties": false
}, },
"media": { "media": {
@ -354,10 +393,15 @@
"default": false "default": false
} }
}, },
"required": [
"convert_images",
"convert_to",
"convert_vectors"
],
"additionalProperties": false "additionalProperties": false
} }
}, },
"required": ["conversion"], "required": ["backend", "uploads_path", "conversion"],
"additionalProperties": false "additionalProperties": false
}, },
"s3": { "s3": {
@ -381,19 +425,14 @@
"public_url": { "public_url": {
"$ref": "#/properties/http/properties/base_url", "$ref": "#/properties/http/properties/base_url",
"description": "Public URL that uploaded media will be accessible at" "description": "Public URL that uploaded media will be accessible at"
},
"path": {
"type": "string"
},
"path_style": {
"type": "boolean",
"default": true
} }
}, },
"required": [ "required": [
"endpoint", "endpoint",
"access_key", "access_key",
"secret_access_key", "secret_access_key",
"region",
"bucket_name",
"public_url" "public_url"
], ],
"additionalProperties": false "additionalProperties": false
@ -479,6 +518,18 @@
"default": 20 "default": 20
} }
}, },
"required": [
"max_displayname_characters",
"max_username_characters",
"max_bio_characters",
"max_avatar_bytes",
"max_header_bytes",
"disallowed_usernames",
"max_field_count",
"max_field_name_characters",
"max_field_value_characters",
"max_pinned_notes"
],
"additionalProperties": false "additionalProperties": false
}, },
"notes": { "notes": {
@ -519,6 +570,11 @@
"default": 16 "default": 16
} }
}, },
"required": [
"max_characters",
"allowed_url_schemes",
"max_attachments"
],
"additionalProperties": false "additionalProperties": false
}, },
"media": { "media": {
@ -1782,6 +1838,11 @@
] ]
} }
}, },
"required": [
"max_bytes",
"max_description_characters",
"allowed_mime_types"
],
"additionalProperties": false "additionalProperties": false
}, },
"emojis": { "emojis": {
@ -1803,6 +1864,11 @@
"default": 1000 "default": 1000
} }
}, },
"required": [
"max_bytes",
"max_shortcode_characters",
"max_description_characters"
],
"additionalProperties": false "additionalProperties": false
}, },
"polls": { "polls": {
@ -1829,6 +1895,12 @@
"default": 8640000 "default": 8640000
} }
}, },
"required": [
"max_options",
"max_option_characters",
"min_duration_seconds",
"max_duration_seconds"
],
"additionalProperties": false "additionalProperties": false
}, },
"emails": { "emails": {
@ -1847,6 +1919,7 @@
"default": [] "default": []
} }
}, },
"required": ["disallow_tempmail", "disallowed_domains"],
"additionalProperties": false "additionalProperties": false
}, },
"challenges": { "challenges": {
@ -1867,7 +1940,7 @@
"description": "You can use PATH:/path/to/file to load this value from a file" "description": "You can use PATH:/path/to/file to load this value from a file"
} }
}, },
"required": ["key"], "required": ["difficulty", "expiration", "key"],
"additionalProperties": false, "additionalProperties": false,
"description": "CAPTCHA challenge configuration. Challenges are disabled if not provided." "description": "CAPTCHA challenge configuration. Challenges are disabled if not provided."
}, },
@ -1910,6 +1983,13 @@
"default": [] "default": []
} }
}, },
"required": [
"note_content",
"emoji_shortcode",
"username",
"displayname",
"bio"
],
"additionalProperties": false, "additionalProperties": false,
"description": "Block content that matches these regular expressions" "description": "Block content that matches these regular expressions"
} }
@ -1921,6 +2001,7 @@
"emojis", "emojis",
"polls", "polls",
"emails", "emails",
"challenges",
"filters" "filters"
], ],
"additionalProperties": false "additionalProperties": false
@ -1935,14 +2016,13 @@
"type": "object", "type": "object",
"properties": { "properties": {
"public": { "public": {
"$ref": "#/properties/postgres/properties/password", "$ref": "#/properties/postgres/properties/password"
"description": "You can use PATH:/path/to/file to load this value from a file"
}, },
"private": { "private": {
"$ref": "#/properties/postgres/properties/password", "$ref": "#/properties/postgres/properties/password"
"description": "You can use PATH:/path/to/file to load this value from a file"
} }
}, },
"required": ["public", "private"],
"additionalProperties": false "additionalProperties": false
}, },
"subject": { "subject": {
@ -1950,11 +2030,12 @@
"description": "Subject field embedded in the push notification. Example: 'mailto:contact@example.com'" "description": "Subject field embedded in the push notification. Example: 'mailto:contact@example.com'"
} }
}, },
"required": ["vapid_keys"], "required": ["vapid_keys", "subject"],
"additionalProperties": false, "additionalProperties": false,
"description": "Web Push Notifications configuration. Leave out to disable." "description": "Web Push Notifications configuration. Leave out to disable."
} }
}, },
"required": ["push"],
"additionalProperties": false "additionalProperties": false
}, },
"defaults": { "defaults": {
@ -1981,6 +2062,13 @@
"description": "A style name from https://www.dicebear.com/styles" "description": "A style name from https://www.dicebear.com/styles"
} }
}, },
"required": [
"visibility",
"language",
"avatar",
"header",
"placeholder_style"
],
"additionalProperties": false "additionalProperties": false
}, },
"federation": { "federation": {
@ -2067,6 +2155,17 @@
"default": [] "default": []
} }
}, },
"required": [
"reports",
"deletes",
"updates",
"media",
"follows",
"likes",
"reactions",
"banners",
"avatars"
],
"additionalProperties": false "additionalProperties": false
}, },
"bridge": { "bridge": {
@ -2097,11 +2196,11 @@
"$ref": "#/properties/http/properties/proxy_address" "$ref": "#/properties/http/properties/proxy_address"
} }
}, },
"required": ["software", "token", "url"], "required": ["software", "allowed_ips", "token", "url"],
"additionalProperties": false "additionalProperties": false
} }
}, },
"required": ["discard"], "required": ["blocked", "followers_only", "discard", "bridge"],
"additionalProperties": false "additionalProperties": false
}, },
"queues": { "queues": {
@ -2120,6 +2219,10 @@
"default": 31536000 "default": 31536000
} }
}, },
"required": [
"remove_after_complete_seconds",
"remove_after_failure_seconds"
],
"additionalProperties": false "additionalProperties": false
}, },
"propertyNames": { "propertyNames": {
@ -2161,6 +2264,7 @@
"$ref": "#/properties/http/properties/proxy_address" "$ref": "#/properties/http/properties/proxy_address"
} }
}, },
"required": ["logo", "banner"],
"additionalProperties": false "additionalProperties": false
}, },
"languages": { "languages": {
@ -2385,7 +2489,7 @@
"description": "Longer version of the rule with additional information" "description": "Longer version of the rule with additional information"
} }
}, },
"required": ["text"], "required": ["text", "hint"],
"additionalProperties": false "additionalProperties": false
}, },
"default": [] "default": []
@ -2394,18 +2498,28 @@
"type": "object", "type": "object",
"properties": { "properties": {
"public": { "public": {
"$ref": "#/properties/postgres/properties/password", "$ref": "#/properties/postgres/properties/password"
"description": "You can use PATH:/path/to/file to load this value from a file"
}, },
"private": { "private": {
"$ref": "#/properties/postgres/properties/password", "$ref": "#/properties/postgres/properties/password"
"description": "You can use PATH:/path/to/file to load this value from a file"
} }
}, },
"required": ["public", "private"],
"additionalProperties": false "additionalProperties": false
} }
}, },
"required": ["branding", "languages", "contact"], "required": [
"name",
"description",
"extended_description_path",
"tos_path",
"privacy_policy_path",
"branding",
"languages",
"contact",
"rules",
"keys"
],
"additionalProperties": false "additionalProperties": false
}, },
"permissions": { "permissions": {
@ -2684,6 +2798,7 @@
] ]
} }
}, },
"required": ["anonymous", "default", "admin"],
"additionalProperties": false "additionalProperties": false
}, },
"logging": { "logging": {
@ -2715,6 +2830,7 @@
"type": "string" "type": "string"
} }
}, },
"required": ["level", "log_file_path"],
"additionalProperties": false "additionalProperties": false
} }
] ]
@ -2770,7 +2886,15 @@
"type": "string" "type": "string"
} }
}, },
"required": ["dsn"], "required": [
"dsn",
"debug",
"sample_rate",
"traces_sample_rate",
"trace_propagation_targets",
"max_breadcrumbs",
"environment"
],
"additionalProperties": false "additionalProperties": false
}, },
"log_file_path": { "log_file_path": {
@ -2778,7 +2902,7 @@
"default": "logs/versia.log" "default": "logs/versia.log"
} }
}, },
"required": ["types"], "required": ["types", "log_level", "sentry", "log_file_path"],
"additionalProperties": false "additionalProperties": false
}, },
"debug": { "debug": {
@ -2789,6 +2913,7 @@
"default": false "default": false
} }
}, },
"required": ["federation"],
"additionalProperties": false "additionalProperties": false
}, },
"plugins": { "plugins": {
@ -2816,6 +2941,7 @@
"default": [] "default": []
} }
}, },
"required": ["enabled", "disabled"],
"additionalProperties": false "additionalProperties": false
}, },
"config": { "config": {
@ -2823,7 +2949,7 @@
"additionalProperties": {} "additionalProperties": {}
} }
}, },
"required": ["overrides"], "required": ["autoload", "overrides", "config"],
"additionalProperties": false "additionalProperties": false
} }
}, },
@ -2836,6 +2962,7 @@
"frontend", "frontend",
"email", "email",
"media", "media",
"s3",
"validation", "validation",
"notifications", "notifications",
"defaults", "defaults",
@ -2844,6 +2971,7 @@
"instance", "instance",
"permissions", "permissions",
"logging", "logging",
"debug",
"plugins" "plugins"
], ],
"additionalProperties": false, "additionalProperties": false,

View file

@ -37,7 +37,7 @@
"format": "uri" "format": "uri"
} }
}, },
"required": ["name"], "required": ["name", "email", "url"],
"additionalProperties": false "additionalProperties": false
} }
}, },
@ -75,10 +75,18 @@
"format": "uri" "format": "uri"
} }
}, },
"required": ["type", "url"],
"additionalProperties": false "additionalProperties": false
} }
}, },
"required": ["name", "version", "description"], "required": [
"$schema",
"name",
"version",
"description",
"authors",
"repository"
],
"additionalProperties": false, "additionalProperties": false,
"$schema": "http://json-schema.org/draft-07/schema#" "$schema": "http://json-schema.org/draft-07/schema#"
} }