BUG: KeywordSelectionStrategy accepts a negative context, so SelectiveTextConverter duplicates or truncates the prompt
维护者通常 2 天内回复
评估
调研方向
Start in pyrit/converter/text_selection_strategy.py and compare KeywordSelectionStrategy with the other selection strategies that validate their bounds. Check the negative context and empty keyword cases from the issue’s reproducer, then verify they raise ValueError without changing valid selections.
由索引模型根据 Issue 内容生成。
描述
Describe the bug
KeywordSelectionStrategy in pyrit/converter/text_selection_strategy.py stores keyword, context_before and context_after without checking them, while the other character-level strategies (PositionSelectionStrategy, ProportionSelectionStrategy, RangeSelectionStrategy) and the word-level ones validate their bounds.
select_range then computes start = max(0, index - context_before) and end = min(len(text), index + len(keyword) + context_after), so a negative context produces a range that does not cover the keyword, or one whose end is before its start. SelectiveTextConverter uses that range as prompt[:start] + convert(prompt[start:end]) + prompt[end:], which:
- with
context_after=-10on"the secret plan"returns the range(4, 0), and the converter sends"the the secret plan": the text betweenendandstartis duplicated and nothing is converted. - with
context_before=-3returns(7, 10), so only"ret"is converted and the rest of the keyword is sent in plaintext ("the seccmV0 plan"withBase64Converter).
An empty keyword is also accepted; it matches at index 0, so the strategy selects the first context_after characters of every prompt instead of a keyword.
Steps/Code to Reproduce
import asyncio
from pyrit.converter import Base64Converter, SelectiveTextConverter
from pyrit.converter.text_selection_strategy import KeywordSelectionStrategy
prompt = "the secret plan"
for strategy in (
KeywordSelectionStrategy(keyword="secret", context_after=-10),
KeywordSelectionStrategy(keyword="secret", context_before=-3),
):
converter = SelectiveTextConverter(sub_converter=Base64Converter(), selection_strategy=strategy)
print(strategy.select_range(text=prompt), repr(asyncio.run(converter.convert_async(prompt=prompt)).output_text))
Expected Results
KeywordSelectionStrategy raises a ValueError for a negative or non-integer context_before/context_after and for an empty keyword, like the other selection strategies do for out-of-range values.
Actual Results
(4, 0) 'the the secret plan'
(7, 10) 'the seccmV0 plan'
Screenshots
N/A
Versions
- OS: Windows 11
- Python version: 3.11.9
- PyRIT version: installed from main (898b3bdc) in editable mode
- 主要语言
- Python
- 星标
- 4.6k
- 派生
- 962
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 417
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/PyRIT 的其他 Issue
-
BUG: Overlapping scorer-evaluation globs duplicate CSVs and change accuracy可能已有人在做 @its-amann 于 1 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
microsoft/PyRIT#3430 · 1 条评论 ·
维护者通常 2 天内回复
-
BUG: MarkdownInjectionScorer misses shortcut-reference images with path-based exfiltration, and raw HTML <img>可能已有人在做 @aatif101 于 3 天前认领。 未关闭Bug: triage
难度 2/5 1-3 小时 新手友好度 72/100
microsoft/PyRIT#3343 · 2 条评论 · 已指派 1 人 ·
维护者通常 2 天内回复
-
Detect Azure SAS tokens, SharedAccessKey connection strings, and Databricks PATs in CredentialLeakScorer可能已有人在做 @nithin42 今天认领。 未关闭
难度 3/5 1-2 天 新手友好度 68/100
维护者通常 2 天内回复
-
BUG: OpenAITTSTarget accepts any speed, so an out-of-range value is only sent to the API on every request可能已有人在做 @ShivamSharma43 于 1 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 25/100
microsoft/PyRIT#3445 · 1 条评论 · 已指派 1 人 ·
维护者通常 2 天内回复
-
BUG: LetterBijectionConverter accepts a negative fixed_size and then leaves the prompt unchanged可能已有人在做 @ShivamSharma43 于 1 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 35/100
microsoft/PyRIT#3434 · 已指派 1 人 ·
维护者通常 2 天内回复
相似的 Issue
-
[oblt-aw][autodoc] Update workflow docs for gh-aw v0.92.5 and detector permission scope可能已有人在做 @github-actions 今天认领。 未关闭
难度 1/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
roadmap-100
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
comp/tools P2 tool/browser tool/file type/bug
难度 2/5 1-3 小时 新手友好度 75/100
NousResearch/hermes-agent#143418 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
python-hyper/uritemplate#164 ·