{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/arxiv-2607-19957","title":"HijackKV: New Threat in Position-Independent KV Cache Reuse","arxiv_id":"2607.19957","date":"2026-07-22","proceeding":null,"authors":["Yichi Zhang","Zhiqi Wang","Huan Zhang","Yuchen Yang"],"abstract":"Key-Value (KV) cache reduces inference latency in large language models (LLMs). Traditional prefix-based reuse has low cache hit rates across inference requests because it requires exact token and position matches. To improve efficiency, recent system optimizations introduce position-independent KV reuse, allowing KV cache to be reused whenever identical text chunks appear, regardless of their position in the sequence. We show this design introduces a new threat, KV Cache Hijacking. Since KV caches are retrieved by token match but encode the context in which they were originally computed, the KV tied to a benign-looking token chunk may encode an attacker-controlled prefix. When later reused in a victim query, this contaminated KV silently hijacks the model's behavior, even if no attacker-controlled text appears in the input. We introduce HIJACKKV, the first attack framework that systematically exploits this vulnerability, demonstrating its severity and practicality. HIJACKKV optimizes an attacker-controlled prefix, so that the KV computed for a subsequent common benign text encodes the attacker's goal, while the text remains unchanged for future cache hits. HIJACKKV achieves an average 94% success rate in a single attempt, remains effective under realistic constraints including low hit rates (10%) and frequent recomputation (50%), persists over multi-turn interactions, and transfers across models in black-box settings. We further provide design insights for building secure KV reuse systems.","url_abs":"https://arxiv.org/abs/2607.19957","url_pdf":"https://arxiv.org/pdf/2607.19957","source":{"archive":null,"snapshot":"2025-07-28","note":"not in the Papers with Code archive (frozen at the snapshot)","row_kind":"graph","title_abstract_authors_date":"arXiv metadata, CC0 1.0 (https://info.arxiv.org/help/license)"},"code_links":[],"tasks":[],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2607.19957","atlas_url":"https://app.syntology.ai/?focus=2607.19957","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2607.19957"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-25T09:33:49+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"mentioned_in_github":null,"is_official":null,"provenance":"deterministic:regex_extraction","mentioned_in_paper":null,"url":"https://github.com/YichiCS/KV-Cache-Hijack","reach":null}],"summary":{"ran":2,"ran_draft_wrong":3,"ran_honours":3,"ran_fixture":1,"unverified":10},"by_repo_kind":{"found_in_text":{"samples":19,"ran":9,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"27f464382c95bbe9","entry":"_MutableFullCache","repo":"YichiCS/KV-Cache-Hijack","repo_kind":"found_in_text","path":"src/funcs/attack.py","file_url":"https://github.com/YichiCS/KV-Cache-Hijack/blob/HEAD/src/funcs/attack.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"27f464382c95bbe9"}},{"code_sha256_prefix":"0313706e553c8f30","entry":"_MutableFullLayer","repo":"YichiCS/KV-Cache-Hijack","repo_kind":"found_in_text","path":"src/funcs/attack.py","file_url":"https://github.com/YichiCS/KV-Cache-Hijack/blob/HEAD/src/funcs/attack.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"0313706e553c8f30"}},{"code_sha256_prefix":"9eafdc121e816f89","entry":"_build_full_cache","repo":"YichiCS/KV-Cache-Hijack","repo_kind":"found_in_text","path":"src/funcs/attack.py","file_url":"https://github.com/YichiCS/KV-Cache-Hijack/blob/HEAD/src/funcs/attack.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"9eafdc121e816f89"}},{"code_sha256_prefix":"2aa84fa801ebda6f","entry":"_finalize_cache","repo":"YichiCS/KV-Cache-Hijack","repo_kind":"found_in_text","path":"src/funcs/attack.py","file_url":"https://github.com/YichiCS/KV-Cache-Hijack/blob/HEAD/src/funcs/attack.py","link_basis":"first_harvest_node","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"2aa84fa801ebda6f"}},{"code_sha256_prefix":"ad7c723c05f6ed99","entry":"_get_attention_fn","repo":"YichiCS/KV-Cache-Hijack","repo_kind":"found_in_text","path":"src/funcs/attack.py","file_url":"https://github.com/YichiCS/KV-Cache-Hijack/blob/HEAD/src/funcs/attack.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"ad7c723c05f6ed99"}},{"code_sha256_prefix":"1b82f10788b29034","entry":"_get_backend","repo":"YichiCS/KV-Cache-Hijack","repo_kind":"found_in_text","path":"src/funcs/attack.py","file_url":"https://github.com/YichiCS/KV-Cache-Hijack/blob/HEAD/src/funcs/attack.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"1b82f10788b29034"}},{"code_sha256_prefix":"0ef78dc731489619","entry":"_get_input_embeds","repo":"YichiCS/KV-Cache-Hijack","repo_kind":"found_in_text","path":"src/funcs/attack.py","file_url":"https://github.com/YichiCS/KV-Cache-Hijack/blob/HEAD/src/funcs/attack.py","link_basis":"first_harvest_node","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"0ef78dc731489619"}},{"code_sha256_prefix":"85cf61aa657f9f92","entry":"_next_layer_budget","repo":"YichiCS/KV-Cache-Hijack","repo_kind":"found_in_text","path":"src/funcs/attack.py","file_url":"https://github.com/YichiCS/KV-Cache-Hijack/blob/HEAD/src/funcs/attack.py","link_basis":"first_harvest_node","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"85cf61aa657f9f92"}},{"code_sha256_prefix":"c16829860cf83849","entry":"build_kv_cache","repo":"YichiCS/KV-Cache-Hijack","repo_kind":"found_in_text","path":"src/funcs/attack.py","file_url":"https://github.com/YichiCS/KV-Cache-Hijack/blob/HEAD/src/funcs/attack.py","link_basis":"first_harvest_node","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"c16829860cf83849"}},{"code_sha256_prefix":"67b072230d538728","entry":"HijackKV","repo":"YichiCS/KV-Cache-Hijack","repo_kind":"found_in_text","path":"src/funcs/attack.py","file_url":"https://github.com/YichiCS/KV-Cache-Hijack/blob/HEAD/src/funcs/attack.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"67b072230d538728"}},{"code_sha256_prefix":"7bcda97c37330638","entry":"cache_clone","repo":"YichiCS/KV-Cache-Hijack","repo_kind":"found_in_text","path":"src/funcs/attack.py","file_url":"https://github.com/YichiCS/KV-Cache-Hijack/blob/HEAD/src/funcs/attack.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"7bcda97c37330638"}},{"code_sha256_prefix":"d49bca247e704a2e","entry":"cache_concat","repo":"YichiCS/KV-Cache-Hijack","repo_kind":"found_in_text","path":"src/funcs/attack.py","file_url":"https://github.com/YichiCS/KV-Cache-Hijack/blob/HEAD/src/funcs/attack.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"d49bca247e704a2e"}},{"code_sha256_prefix":"939411491cb64117","entry":"cache_expand","repo":"YichiCS/KV-Cache-Hijack","repo_kind":"found_in_text","path":"src/funcs/attack.py","file_url":"https://github.com/YichiCS/KV-Cache-Hijack/blob/HEAD/src/funcs/attack.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"939411491cb64117"}},{"code_sha256_prefix":"c32ce06ab3210d82","entry":"cache_recomputation","repo":"YichiCS/KV-Cache-Hijack","repo_kind":"found_in_text","path":"src/funcs/attack.py","file_url":"https://github.com/YichiCS/KV-Cache-Hijack/blob/HEAD/src/funcs/attack.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"c32ce06ab3210d82"}},{"code_sha256_prefix":"35caf9168740a681","entry":"cache_split","repo":"YichiCS/KV-Cache-Hijack","repo_kind":"found_in_text","path":"src/funcs/attack.py","file_url":"https://github.com/YichiCS/KV-Cache-Hijack/blob/HEAD/src/funcs/attack.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"35caf9168740a681"}},{"code_sha256_prefix":"0424505ffacd2f28","entry":"recompute_cacheblend","repo":"YichiCS/KV-Cache-Hijack","repo_kind":"found_in_text","path":"src/funcs/attack.py","file_url":"https://github.com/YichiCS/KV-Cache-Hijack/blob/HEAD/src/funcs/attack.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"0424505ffacd2f28"}},{"code_sha256_prefix":"a48916c9da6b4420","entry":"recompute_epic","repo":"YichiCS/KV-Cache-Hijack","repo_kind":"found_in_text","path":"src/funcs/attack.py","file_url":"https://github.com/YichiCS/KV-Cache-Hijack/blob/HEAD/src/funcs/attack.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"a48916c9da6b4420"}},{"code_sha256_prefix":"504da673b0116fb9","entry":"recompute_random","repo":"YichiCS/KV-Cache-Hijack","repo_kind":"found_in_text","path":"src/funcs/attack.py","file_url":"https://github.com/YichiCS/KV-Cache-Hijack/blob/HEAD/src/funcs/attack.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"504da673b0116fb9"}},{"code_sha256_prefix":"f97a2afd9fcd1dfa","entry":"recompute_vanilla","repo":"YichiCS/KV-Cache-Hijack","repo_kind":"found_in_text","path":"src/funcs/attack.py","file_url":"https://github.com/YichiCS/KV-Cache-Hijack/blob/HEAD/src/funcs/attack.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"f97a2afd9fcd1dfa"}}]},"arxiv_metadata":{"licence":"arXiv metadata, CC0 1.0 (https://info.arxiv.org/help/license)","fields":["title","abstract","authors","date"],"primary_category":"cs.LG","source":"arxiv_2026.jsonl"},"syntology_extracted_results":{"kind":"leaderboard_placements","source":"Syntology's leaderboard-shaped extractor over the paper's own arXiv-HTML tables: a model pointed at a cell, the number was read from that cell and checked against the board's metric, dataset, split and scale, and an independent check accepted the entry; not reviewed by the paper's authors or the archive's editors","extractor_model":"global.anthropic.claude-sonnet-4-5-20250929-v1:0","verifier_model":null,"prompt_sha":"fa63d4bb9d755694","coverage":{"sentence":"Syntology has checked 6,885 of the 9,623 papers on this site that are newer than the archive; results from the others appear after they are checked.","papers_newer_than_archive":9623,"papers_checked":6885},"entries":[],"not_placed":{"boards":2,"rejected_by_independent_check":0,"refused_by_a_rule":2,"check_did_not_answer":0,"proposed_without_a_cell":0,"declined_by_site":0}}}