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時間
- マージ済み PR(30日)
- 423
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/PyRIT のほかの issue
-
BUG: Overlapping scorer-evaluation globs duplicate CSVs and change accuracy対応中かも @its-amann が 2 日前に担当しました。 オープン
難易度 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 が 1 日前に担当しました。 オープン
難易度 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 日以内に返信
microsoft/PyRIT の issue をすべて見る
似ている issue
-
bug
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
sergey-miryanov/gcmon#230 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Azure-Samples/azure-search-openai-demo#3249 ·
メンテナーはふだん 1 日以内に返信
-
[BUG] Failed archive extraction deletes the dataset cache対応中かも @dajiaohuang が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
alibaba/GraphScope#4674 ·