This threat model covers the Appsheet.DotNetFrameworkUriEscaping repository (sso://gnocchi-internal/third_party/dot-net-framework-uri-escaping), a C# shared library targeting .NET Standard 2.0. The repository contains a custom fork of Microsoft .NET Framework 4.6.2 Reference Source (NetFrameworkUri.cs) configured to execute in legacy V2 quirks mode (RFC 2396). It provides NetFrameworkUri.EscapeDataString() to escape query parameters identically to legacy .NET Framework (notably preserving unreserved characters such as ( and )), which is utilized by AppSheet to verify cryptographic signatures on legacy image URLs generated prior to AppSheet's migration to .NET Core.
unsafe pointer operations, stack allocations (stackalloc), raw buffer copying (Buffer.BlockCopy), and custom Unicode surrogate/UTF-8 byte processing on untrusted external URL strings.NetFrameworkUri.EscapeString and NetFrameworkUri.EnsureDestinationSize. Check for potential off-by-one or integer overflow vulnerabilities when indexing characters, calculating surrogate pair offsets (pStr[i + count - 1]), or converting UTF-8 bytes (Encoding.UTF8.GetBytes).stackalloc byte[160] (c_MaxUnicodeCharsReallocate * c_MaxUTF_8BytesPerUnicodeChar) and verify whether input strings with surrogate pairs or long sequences of non-ASCII characters can cause buffer overruns in Encoding.UTF8.GetBytes(pStr + i, count, bytes, 160).0xD800 to 0xDBFF) for malformed Unicode inputs (e.g., truncated high surrogates, unpaired surrogates, non-shortest form UTF-8) to ensure UriFormatException is reliably thrown without memory corruption or infinite loops (for (; count < maxSize && pStr[i + count] > '\x7f'; ++count)).| Entry Point | Type | Trusted? | Validation |
|---|---|---|---|
| `NetFrameworkUri.EscapeDataString(string | Public | No | Validates null, |
| : stringToEscape)` : C# : (Untrusted : empty string, : | |||
| : : Static : query : surrogate pairs, : | |||
| : : Method : parameters : UTF-8 encodability, : | |||
| : : : and URLs : and enforces : | |||
: : : from : c_MaxUriBufferSize : | |||
| : : : external : (65,520 chars) : | |||
| : : : users) : : | |||
NetFrameworkUri.EscapeString(...) | Internal | No (Raw | Enforces `end - |
| : : Unsafe : string and : start < : | |||
| : : Static : substring : c_MaxUriBufferSize`; : | |||
| : : Method : bounds) : validates high/low : | |||
| : : : : surrogates and UTF-8 : | |||
| : : : : byte conversion : |
NetFrameworkUri.EscapeDataString → Signature validator / image storage fetcher.| Data Type | Source | Destination | Protection |
|---|---|---|---|
| Customer | External | NetFrameworkUri.EscapeDataString | In-memory |
| : image URLs : client : -> Signature verification hash / : processing; input : | |||
| : & query : requests : HMAC engine : size limited by : | |||
: parameters : : : c_MaxUriBufferSize : | |||
| Image URL | External | Signature verification comparison | Processed in string |
| : signatures : client : logic : / character buffers : | |||
| : & HMAC : requests : : : | |||
| : tokens : : : : |
| Action | Location | Guard |
|---|---|---|
| Unsafe stack | NetFrameworkUri.EscapeString | Fixed allocation size |
| : allocation : : (`c_MaxUnicodeCharsReallocate * : | ||
: (stackalloc) : : c_MaxUTF_8BytesPerUnicodeChar` : | ||
| : : : = 160 bytes); bounded by : | ||
: : : maxSize calculation : | ||
| Direct pointer | NetFrameworkUri.EscapeString, | Fixed pointer pins (`fixed |
: dereferencing & : NetFrameworkUri.EnsureDestinationSize : (char* pStr = input)`); bounded : | ||
: traversal (char*, : : loop index and prevInputPos : | ||
: byte*) : : tracking : | ||
| Raw buffer copy | NetFrameworkUri.EnsureDestinationSize | Reallocation logic with |
: (Buffer.BlockCopy) : : destPos << 1 byte count : |
NetFrameworkUri.EscapeString and NetFrameworkUri.EnsureDestinationSize under edge cases (e.g. repeated resizing, maximum buffer size, mixed ASCII and non-ASCII sequences).count == 1 || count == end - i).RFC2396UnreservedMarks (-_.~*'()!) vs RFC3986UnreservedMarks (-_.~) and ensure signature calculations in AppSheet cannot be desynchronized between .NET Framework and .NET Core.c_MaxUriBufferSize = 0xFFF0) can cause high CPU usage or excessive garbage collection.