cityrp.imageHosts
Central allowlist of image hosts that are trusted for remote content.
Anything that loads a player-supplied image off the internet (billboards, the Material URL tool, 3D signs) validates against this one list. Adding or retiring a host here updates every consumer at once, including the host names shown in their UIs - there is deliberately nowhere else in the codebase that a host name should be written down.
Host matching is exact and case-insensitive against the URL's hostname. Subdomains are not implied: "i.ibb.co" does not permit "evil.i.ibb.co", so every host that should work must be listed in full.
Both http and https are accepted. Plain http means the image bytes can be tampered with in transit by anything between us and the host, but the host itself is still allowlisted and the result is only ever decoded as an image, which is an accepted trade-off here rather than an oversight - a good few of these links come in as http and rejecting them broke more than it protected. A URL with no scheme is assumed to be https.
- Sharedcityrp.imageHosts.getExtensionList(conjunction) → stringSource ☍
-
Get the accepted file extensions as one human-readable string.
Parameters
- conjunctionstring?Word to join the last extension with, defaults to "or".
Returns
- stringThe joined extensions, or "none" if there are none.
- Sharedcityrp.imageHosts.getHost(url) → string|nilSource ☍
-
Extract the hostname from a URL. Userinfo ("user@host") and explicit ports are rejected rather than parsed, so a crafted authority cannot be read as an allowed host by one parser and a different host by another.
Parameters
- urlstringThe URL to read the hostname from.
Returns
- string|nilThe lowercased hostname, or nil if it cannot be parsed safely.
- Sharedcityrp.imageHosts.getHostList(conjunction) → stringSource ☍
-
Get the enabled hostnames as one human-readable string, for prose shown to players. Use
getHosts()instead where the caller lays the hostnames out itself.Parameters
- conjunctionstring?Word to join the last hostname with, defaults to "or".
Returns
- stringThe joined hostnames, or "none" if every host is disabled.
- Sharedcityrp.imageHosts.getHosts() → string[]Source ☍
-
Get the currently enabled hostnames.
Returns
- string[]A copy of the enabled hostnames, in definition order.
- Sharedcityrp.imageHosts.hasAllowedExtension(url) → booleanSource ☍
-
Check a URL's file extension against the accepted image formats.
Parameters
- urlstringThe URL to check.
Returns
- booleanWhether the URL ends in an accepted image extension.
- Sharedcityrp.imageHosts.hasImagePath(url) → booleanSource ☍
-
Check for an accepted image extension, or none at all on an
extensionlesshost. The URL alone cannot prove the second case is an image; the consumer checks the download.Parameters
- urlstringThe URL to check.
Returns
- booleanWhether the URL's path is acceptable as an image.
- Sharedcityrp.imageHosts.isAllowed(url) → booleanSource ☍
-
Check a full URL against the allowlist.
Parameters
- urlstringThe URL to check.
Returns
- booleanWhether the URL points at an allowed host over https.
- Sharedcityrp.imageHosts.isAllowedHost(host) → booleanSource ☍
-
Check a bare hostname against the allowlist.
Parameters
- hoststringThe hostname to check, without scheme or path.
Returns
- booleanWhether the hostname is on the allowlist.
- Sharedcityrp.imageHosts.normalise(url) → string|nilSource ☍
-
Normalise a player-supplied URL into a full http or https URL. Bare "host/path" input is assumed to be https and other schemes are rejected. A trailing slash is kept: Steam user-content URLs end in one and 404 without it.
Parameters
- urlstringThe raw URL or host/path as the player typed it.
Returns
- string|nilThe normalised URL, or nil if it cannot be used at all.
- Sharedcityrp.imageHosts.refresh()Source ☍
-
Rebuild the lookup caches from the definition tables. Only needed if
definitionsorextensionsare edited at runtime. - Sharedcityrp.imageHosts.validate(url, requireExtension) → string?, string?Source ☍
-
Validate a player-supplied image URL against the allowlist.
Parameters
- urlstringThe raw URL as the player supplied it.
- requireExtensionboolean?Also require an image path, per
hasImagePath.
Returns
- 1string?The normalised URL, or nil if it was rejected.
- 2string?A player-facing reason, set only when the URL was rejected.
- Sharedcityrp.imageHosts.definitionsSource ☍
-
The canonical host list. Retired hosts stay here with
enabled = falseso the reason they were dropped survives; delete an entry only when the reason no longer needs recording. - Sharedcityrp.imageHosts.extensionsSource ☍
-
File extensions accepted by the systems that care about the image format.
- Sharedcityrp.imageHostsSource ☍
- SharedImageHostDefinition.enabledSource ☍
-
Whether the host is currently accepted.
- SharedImageHostDefinition.extensionlessSource ☍
-
The host serves images from paths with no file extension, so systems that require an image extension accept its extensionless URLs and check the downloaded file instead.
- SharedImageHostDefinition.hostSource ☍
-
The hostname players link to, matched exactly and case-insensitively.
- SharedImageHostDefinition.reasonSource ☍
-
Why the host is trusted, or why it is currently disabled.