跳到正文
arXiv:cs.AI· Wenbin Chen, Jiexin Wang, Guanting Wu, Jiaxi Liang, Yi Cai·· 22 小时前

SpecCloak:用工程规格模板探测 LLM 有害代码生成

SpecCloak: Probing Harmful Code Generation through Engineering Specifications

AI 导读

研究提出 PseudoSpec 模板,将编程需求改写为工程规格,可显著降低五个开源权重模型对恶意代码生成的拒绝率,即使保留风险关键词也有效。基于此构建的黑盒红队框架 SpecCloak 结合判别器引导优化,在 RedCode-Gen 上对八个目标模型的平均可执行验证攻击成功率达 28.91%。

正文

View PDF HTML (experimental)

Abstract:The code generation capabilities of large language models (LLMs) can equally be misused to implement harmful functionality, underscoring the need to understand their safety behavior in response to programming requests. While request phrasing is known to influence refusal, it remains unclear whether the form in which coding task requirements are stated affects the refusal process for malicious code generation. We introduce PseudoSpec, a template that organizes functional requirements as engineering specifications, and investigate its effects through controlled comparisons, representation analysis, and activation interventions. Across five open-weight models, removing explicit risk keywords only partially reduces refusal, whereas specification prompting substantially lowers refusal even when these keywords are retained. This reduction accompanies consistent shifts toward code-output-related representations, and interventions along condition-difference directions alter refusal behavior. Output analysis further distinguishes code-related responses from generation degeneration. Building on these findings, we propose SpecCloak, a black-box red-teaming framework combining PseudoSpec with discriminator-guided optimization, achieving an average execution-verified attack success rate of 28.91\% across eight target models on RedCode-Gen. We also introduce SpecReveal, a defense prototype combining natural-language intent reconstruction with dual-view detection without target-model fine-tuning. It achieves a 96.88\% attack detection rate in a separate prompt-detection evaluation, with false positives assessed on benign programming and specification-style inputs. These results connect specification-induced response differences to practical security consequences and identify intent reconstruction as a complementary detection approach.
Comments: 9 pages, 7 figures
Subjects: Software Engineering (cs.SE); Artificial Intelligence (cs.AI)
Cite as: arXiv:2610.17907 [cs.SE]
  (or arXiv:2610.17907v1 [cs.SE] for this version)
  https://doi.org/10.48550/arXiv.2610.17907

arXiv-issued DOI via DataCite (pending registration)

Submission history

From: Wenbin Chen [view email]
[v1] Tue, 13 Oct 2026 07:59:02 UTC (6,850 KB)

来源:arXiv:cs.AI · arxiv.org