Repository navigation
gguf-radar 0.1.5
Security
- Strings that a test on message content only requires to be absent, such as
'took 'in'took ' not in content, are no longer listed as trigger words ofconditional_logic_bomb, unless theifhas aneliforelsepart, which runs when the string is present.not,not in,!=,andandorare followed, so double negations and De Morgan forms are read correctly. The finding and the verdict do not change. The description of a finding changes only where such a string is left out of the listtrigger literal(s): [...], which happens only for anifwithouteliforelseparts, and no sentence was added to any description. Every finding in the JSON report now has the keystrigger_literals,absent_literals,branch_textandknown_template, which are empty for findings of other categories, so stored reports gain these fields. The printed output shows the strings and the text below a finding of this kind.branch_textholds up to 200 characters of the fixed text written in the branch itself, with the text ofelifandelseparts labelled.compare-templatecompares findings by severity, category and description, as before, and ignores the new fields. - A short list of known community templates, matched by the SHA-256 hash of the whole template text, in
src/gguf_radar/known_templates.py. It holds 18 templates: the 16 template files offroggeric/Qwen-Fixed-Chat-Templatesfrom v17 to v22.2 at revision855bffc, and the chat template of NVIDIA Nemotron Nano v2 in the version of the NVIDIA repository and in the copy in llama.cpp. A template is listed only when the only effect of its reported branches is a warning inside the tool response, an empty thinking block that switches reasoning off for one reply, or a documented switch of the vendor. froggeric v15 and v16 are not listed, because they write text in the voice of the assistant at the start of its reply. Every reported branch in the listed templates, and every place that uses what the branch sets, is described next to the list. For a listed template, these branches give the new noteknown_template_branchinstead ofconditional_logic_bomb, and they do not change the verdict. All other findings apply in full. Only CRLF line ends and one trailing newline more or less are accepted as differences, so a modified copy staysSUSPICIOUS.scripts/known_template_hashes.pychecks the hashes against the upstream files. On the two files of the report, the unmodified v21.3 template innerun/OxCoder-9B-i1-MTP-GGUFnow givesCLEANwith a note, and the copy inpeculiar-ragdoll/Nail-Qwen3.6-35B-A3B-GGUF-MTP, which has a system prompt added to the template, staysSUSPICIOUS. Thanks to @nerun for the report in #25. - Scanning and
sanitizecover named chat templates. A GGUF file can holdtokenizer.chat_template.<name>next to the default template, and llama.cpp uses a named template when a request needs it or when the default is empty. Before,scanread only the default key, so a payload intokenizer.chat_template.tool_usegaveCLEAN, andsanitizeleft the named keys in the file. Thanks to @agentik-os for the report in #21 and to @shiwng for the fix in #23.
Changed
- The findings of every analyzed chat template are reported. Each finding has a new field
template_keywith the key of its template, and the printed findings name it. The result has a new fieldtemplate_keywith the key of the template with the highest risk score. The verdict is still the one of the worst finding. No field was renamed or removed. - The templates of a GGUF file are collected by one function,
gguf_template_texts, whichcompare-templateuses as well.compare-templatenow keeps a named template calleddefaultapart from the real default template, so the named one no longer replaces it. scanreads the object form ofchat_templateintokenizer_config.json, a mapping from names to templates, as it already read the list form. A list item without a name is read too.sanitize --replace-templatewrites the new text undertokenizer.chat_template, adds the key if the file had none, and removes all named templates.--strip-templateremoves the default and all named templates. Both options also remove the arraytokenizer.chat_templates, so it never lists a name without a template. The summary lists the removed keys in the new fieldsnamed_templates_removedandtemplate_names_removed.- The default template and the template named
tool_useare the two that llama.cpp reads, so a scan always analyzes them. A file that holds thousands of named templates or a very long template cannot make a scan slow, because the work is limited. Besides these two, a scan analyzes at most 16 named templates with at most 1,048,576 characters in total, and of any template it analyzes the first 1,048,576 characters. A file beyond a limit gets the findingtoo_many_chat_templatesorchat_template_too_largeand the verdictSUSPICIOUS. The fingerprint is still that of the whole template. - In
tokenizer_config.json, the template nameddefaultis the default template, and two entries with the same name, or a nameless entry whose position equals another name, no longer replace each other. The Transformers library uses the last entry of a repeated name, and other runtimes may use the first, so every entry nameddefaultortool_useis always analyzed, up to 4 entries for each name. For a name with more entries, the first 3 and the last one are analyzed, and the entries in between count against the limits for the other templates. - The scan of a repository and of a directory reads the files
additional_chat_templates/<name>.jinja, which version 5 of the Transformers library loads as named templates. The filesdefault.jinjaandfile.jinjaset the default template in that library, and llama.cpp asks fortool_use, so these three files are always read. Of the other files, at most 16 are read, and a folder with more files gets the findingtoo_many_chat_templates. Their findings name the keychat_template.<name>, orchat_templatefordefault.jinjaandfile.jinja. Only regular files are read, so a directory namedx.jinjais skipped, and a file in the folder that is also found by the directory scan is scanned once. - A local file that is not a regular file, such as a symbolic link to
/dev/zeroor a named pipe, givesERRORinscan,compare-templateandsanitize, and does not exhaust memory or wait forever. A.jinjatemplate file is read up to 4 MiB, and a JSON template file up to 16 MiB, in a local scan and in a scan of a repository alike. A longer file gets the findingchat_template_too_largeand the verdictSUSPICIOUS, so a payload after the limit is not reported asCLEAN. The list file ofscan -l, the replacement template ofsanitizeand a local base file ofcompare-templateare read only if they are regular files, so a named pipe gives an error and does not wait forever. Files are opened in binary mode on Windows, and the tests run on Windows in CI. tests/test_performance.pyhas scan-time tests for a file with many metadata entries and named templates, a file with a tensor section of 48 MB and templates at and beyond the limits. The tests of the limits compare a scan with the limits to a scan without them. The other tests use bounds that are several times the time on a development machine.- The reading of a template list or mapping in a JSON file is bounded. Only the first three and the last entry named
default, the first three and the last entry namedtool_use, and the first 16 other entries are kept, and all other entries are counted in onetoo_many_chat_templatesfinding without storing their text. The time to read such a file grows in proportion to the number of entries. The JSON limit is 16 MiB, because 16 MiB of small objects need about 500 MB of memory while they are parsed.
Full changelog: v0.1.4...v0.1.5