Downloads · 30 days
0
pragnyanramtha/flax-subfolder-shard-traversal-poc
flax-subfolder-shard-traversal-poc is a machine learning model from pragnyanramtha. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for transformers. The card lists the license as mit.
Downloads · 30 days
0
Access
Public
Updated May 12, 2026
Repo size
3.7 KB
Likes
0
Public
Click a slice to open those files.
.json13.7 KB · 34%
From the Hugging Face model README
Medium, 6.7/10.
Rationale: this is artifact-carried model weight and inference-output
manipulation through a normal FlaxBertModel.from_pretrained(..., subfolder="model") load path. It is not arbitrary code execution, and it is
scoped to the deprecated-but-still-used Transformers 4.x Flax/JAX loader line,
but the uploaded model artifact is self-contained and the loader reads a shard
outside the requested model subfolder.
This repository contains a benign proof of concept for a Transformers 4.x Flax sharded checkpoint path traversal.
The intended load target is the model/ subfolder:
FlaxBertModel.from_pretrained(source, subfolder="model")
That subfolder contains config.json, flax_model.msgpack.index.json, and a
decoy shard:
model/config.json
model/flax_model.msgpack.index.json
model/decoy_inside_shard.msgpack
However, the index maps every weight to ../outside_shard.msgpack:
"embeddings/LayerNorm/bias": "../outside_shard.msgpack"
The runtime follows that relative shard path and loads the root-level shard:
outside_shard.msgpack
The decoy shard inside the requested subfolder contains marker value
-31337.0. The escaped root-level shard contains marker value 4242.0. Runtime
loads 4242.0, proving the loader read outside the requested subfolder.
No code execution payload is included. The PoC only demonstrates deterministic model weight and output manipulation.
FlaxBertModel.from_pretrained(source, subfolder="model").3.46409 between the in-subfolder decoy parameters and the
runtime-loaded escaped-shard parameters.3.12.3transformers==4.57.6huggingface_hub==0.36.2flax==0.12.7jax==0.10.0jaxlib==0.10.0modelscan==0.8.8picklescan==1.0.4Transformers v5 has removed the JAX/Flax backend. This report is therefore scoped to the latest tested 4.x Flax-capable loader, not the v5 API line.
outside_shard.msgpack
Root-level Flax msgpack shard with marker value 4242.0.
model/config.json
Tiny Flax BERT config loaded from the requested subfolder.
model/flax_model.msgpack.index.json
Sharded Flax checkpoint index inside the requested subfolder. It maps all
weights to ../outside_shard.msgpack.
model/decoy_inside_shard.msgpack
In-subfolder decoy shard with marker value -31337.0.
verify_flax_subfolder_shard_traversal_poc.py
End-to-end verifier. Supports both local paths and direct Hugging Face repo
IDs as --source.
scripts/build_flax_shard_traversal.py
Original artifact builder.
scripts/original_inference_effect.py
Original lab script showing inference output change.
evidence/fresh_verify.json
Fresh local verification output from this staged repository.
evidence/hub_direct_verify.json
Verification output after upload using the public Hugging Face repo ID as the
verifier source.
evidence/lab_marker_verify.json
Original lab marker-value verification.
evidence/lab_inference_effect.json
Original lab inference-output verification.
evidence/sha256.txt
Hashes for uploaded files.
Install matching dependencies in an isolated environment:
pip install "transformers==4.57.6" "huggingface_hub==0.36.2" "flax==0.12.7" "jax==0.10.0" "jaxlib==0.10.0" "modelscan==0.8.8" "picklescan==1.0.4"
Run against a local checkout:
python verify_flax_subfolder_shard_traversal_poc.py
Or run directly against the uploaded Hugging Face repo:
python verify_flax_subfolder_shard_traversal_poc.py --source pragnyanramtha/flax-subfolder-shard-traversal-poc
Expected output highlights:
{
"subfolder": "model",
"target_key": "embeddings/LayerNorm/bias",
"weight_map_unique_values": ["../outside_shard.msgpack"],
"decoy_marker_value": -31337.0,
"outside_marker_value": 4242.0,
"runtime_loaded_marker_value": 4242.0,
"first_8_max_abs_delta_decoy_vs_runtime": 3.464094400405884,
"verified": true
}
The critical observation is that runtime_loaded_marker_value comes from
outside_shard.msgpack, even though the caller requested subfolder="model".
ModelScan 0.8.8 reports zero issues for the requested model/ subfolder:
{
"total_issues": 0,
"scanned": {"total_scanned": 0},
"skipped": {
"total_skipped": 3,
"skipped_files": [
{"source": "decoy_inside_shard.msgpack"},
{"source": "flax_model.msgpack.index.json"},
{"source": "config.json"}
]
}
}
ModelScan also reports zero issues for the repository root in this environment, and PickleScan reports zero infected files and zero dangerous globals.
This scanner output is supporting context. The core issue is the runtime loader following model-controlled shard paths outside the requested subfolder and using those tensors for inference.
The Flax sharded checkpoint index is read from the requested subfolder, but the
weight_map shard filenames are joined with the requested model path without
enforcing that the normalized result stays inside the requested subfolder.
In this PoC:
requested model directory:
model/
index location:
model/flax_model.msgpack.index.json
index shard filename:
../outside_shard.msgpack
runtime-used shard:
outside_shard.msgpack
This lets a model artifact make the loader consume parameters outside the subfolder the caller intended to load.
Local research did not find an obvious published advisory for this specific
Flax sharded checkpoint subfolder traversal. This is distinct from generic
unsafe pickle loading because the payload is a Flax msgpack shard and the
behavior is triggered by flax_model.msgpack.index.json.