Repository navigation
Conversation
…-Security-Project#25) The GGUF reader already parses the header over HTTP Range requests and maps architecture, quantization and hyperparameters, but left the tokenizer chat template as a TODO. The template travels with the weights and can be altered without touching them, so record an integrity signal: - extract tokenizer.chat_template (and named tokenizer.chat_template.<n>) - emit presence, SHA-256 hash, provenance (file + key) and a static heuristic scan result (dunder/introspection access, URLs, encoded payloads, hidden characters, oversized template). The template text is never copied into the AIBOM and a clean scan is not an attestation - compare the template across GGUF variants (first shard of up to 8 files, fetched concurrently, headers only) and report consistent / inconsistent / not-comparable, with per-file hashes when inconsistent - surface everything as owasp:aibom:chatTemplate:* modelCard properties and register hash, security status and consistency as GGUF-only registry fields so they appear in the Field Checklist without penalising other formats Tests use synthetic GGUF bytes and a stubbed HTTP client. Fixes GenAI-Security-Project#25 Signed-off-by: Raghuvar Karthik Durga <177662415+drk-ram@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #25.
mainalready has a safe GGUF header reader (gguf_metadata.py: magic/version/tensor_count/kv_count,general.architecture,general.name, quantization, tokenizer model, HTTP Range fetching of only the header, size/sanity limits) and maps architecture/hyperparameters/quantization into the AIBOM. The remaining gap from the issue was the chat template (# TODO: add chat template field mapping) and the cross-variant consistency signal. This PR adds those.What is added
tokenizer.chat_templateand named templates (tokenizer.chat_template.<name>).true/false)sha256:<hex>of the templategguf:<filename>#tokenizer.chat_templateno-indicators-found/indicators-found(+ indicator ids) from a static heuristic scan for dunder/introspection access, URLs, long encoded blobs, hidden/bidi characters and oversized templates. This is a heuristic, not an attestation, and is documented as such; the template text itself is never copied into the AIBOM.consistent/inconsistent/not-comparable, plus examined/total counts, and per-file hashes when inconsistent. A template present in only some variants counts as inconsistent. An unreadable extra variant is skipped and reflected in the counts; an unreadable primary file still yields no GGUF metadata as before.components[0].modelCard.propertiesentries inowasp:aibom:chatTemplate:*(present,hash,source,securityStatus,securityIndicators,consistency,variantsExamined,variantsTotal,variantHashes). Same custom-namespace approach asowasp:aibom:distribution:*, since the officialgenai:aibomtaxonomy forbids unofficial names.chat_template_hash,chat_template_security_status,chat_template_consistencyregistered as GGUF-only supplementary fields (counted only when present), so they show in the Field Checklist and do not lower scores for non-GGUF models. The issue's third point (report vs registry-driven scoring) is already handled by the current scoring code.Checked against real data: the scanner reports no indicators on the chat templates of Qwen2.5, Mistral-7B-v0.3, Phi-3, OpenHermes, Zephyr, Hermes-2-Pro, DeepSeek-R1-Distill and Gemma-2, and a live run against
bartowski/Llama-3.2-1B-Instruct-GGUF(18 files) read 8 headers in ~14s and reportedconsistent.Behaviour change to note
GGUFFileExtractornow fetches extra variant headers (bounded byMAX_GGUF_VARIANTS_EXAMINED = 8), so GGUF repos take longer to process. The existing testtest_extract_metadata_selects_first_gguf_fileasserted that only the first file is fetched; it now asserts the first file is the primary source, since the others are intentionally read for the comparison.Tests
tests/test_gguf_chat_template.py(new, synthetic GGUF bytes fromtests/fixtures, no network):bytes=0-63, growth requests follow, never reads past the headerValidation
pytest --no-cov(Python 3.11): 218 passed