mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-01 17:38:41 +00:00
Sanitize formspec fields server-side (#14878)
This commit is contained in:
parent
ab7af5d15a
commit
c6ef5ab259
5 changed files with 99 additions and 5 deletions
|
@ -1351,15 +1351,22 @@ static bool pkt_read_formspec_fields(NetworkPacket *pkt, StringMap &fields)
|
|||
u16 field_count;
|
||||
*pkt >> field_count;
|
||||
|
||||
u64 length = 0;
|
||||
size_t length = 0;
|
||||
for (u16 k = 0; k < field_count; k++) {
|
||||
std::string fieldname;
|
||||
std::string fieldname, fieldvalue;
|
||||
*pkt >> fieldname;
|
||||
fields[fieldname] = pkt->readLongString();
|
||||
fieldvalue = pkt->readLongString();
|
||||
|
||||
length += fieldname.size();
|
||||
length += fields[fieldname].size();
|
||||
fieldname = sanitize_untrusted(fieldname, false);
|
||||
// We'd love to strip escapes here but some formspec elements reflect data
|
||||
// from the server (e.g. dropdown), which can contain translations.
|
||||
fieldvalue = sanitize_untrusted(fieldvalue);
|
||||
|
||||
length += fieldname.size() + fieldvalue.size();
|
||||
|
||||
fields[std::move(fieldname)] = std::move(fieldvalue);
|
||||
}
|
||||
|
||||
// 640K ought to be enough for anyone
|
||||
return length < 640 * 1024;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue