Adding a config value with a map makes AdminFE crash HARD
So I added this to my config file:
# Non-RFC HTTP status codes
config :plug, :statuses, %{
# Cloudflare
# https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#Cloudflare
520 => "Web Server Returned an Unknown Error",
521 => "Web Server Is Down",
522 => "Connection Timed Out",
523 => "Origin Is Unreachable",
524 => "A Timeout Occurred",
525 => "SSL Handshake Failed",
526 => "Invalid SSL Certificate",
527 => "Railgun Error"
}
Suddenly, AdminFE became unconfigurable. It refused to import config anymore and became greyed out.
I traced it back to this code: https://git.pleroma.social/pleroma/admin-fe/-/blob/4406dce589546797d670391fd1cc524fc1f8f718/src/store/modules/normalizers.js#L227-239
export const valueHasTuples = (key, value) => {
const valueIsArrayOfNonObjects = Array.isArray(value) && value.length > 0 && value.every(el => typeof el !== 'object')
return key === ':meta' ||
key === ':types' ||
key === ':backends' ||
key === ':compiled_template_engines' ||
key === ':compiled_format_encoders' ||
typeof value === 'string' ||
typeof value === 'number' ||
typeof value === 'boolean' ||
value === null ||
valueIsArrayOfNonObjects
}
Apart from this function doing the exact opposite of what its name implies (eg it returns false if the value has tuples), it is whitelisting config values that are maps by name. There are a few problems with this:
-
It doesn't even check the group, it only checks the key. What if there are two different groups with the same key and a different type of value?
-
It makes adding new config values with maps impossible without modifying AdminFE.
-
It does not have to be this way. Detecting if the value is a tuple is easy. Just check that it's an object containing a key called "tuple".