BUG: KeywordSelectionStrategy accepts a negative context, so SelectiveTextConverter duplicates or truncates the prompt
Los mantenedores suelen responder en 2 días
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 35/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- Python
- Estrellas
- 4.6k
- Forks
- 962
- Merge medio
- 2 d 13 h
- PR fusionados (30 d)
- 423
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Sin guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de microsoft/PyRIT
-
BUG: AzureBlobStorageTarget returns a URL with // when the container URL ends with a slashPosiblemente ocupada @ShivamSharma43 la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 2 días
-
BUG: OpenAIImageTarget uploads edited images under a generated local path instead of their file namePosiblemente ocupada @ShivamSharma43 la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
Los mantenedores suelen responder en 2 días
-
BUG: PathTraversalOutputScorer misses canonical Windows target windows/win.ini and IIS web.configPosiblemente ocupada @Kaap10 la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 2 días
-
BUG: XXEOutputScorer misses direct external DTD references and Java netdoc: / gopher: URI schemesPosiblemente ocupada @Kaap10 la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 2 días
-
BUG: StaticPromptInjectionScorer misses modern LLM chat template tokens (Meta Llama 3+, Google Gemma, Microsoft Phi-3/4)Posiblemente ocupada @Kaap10 la tomó hoy. Abierto
Dificultad 1/5 1-3 horas Aptitud para principiantes 84/100
Los mantenedores suelen responder en 2 días
Todos los issues de microsoft/PyRIT
Issues similares
-
good first issue infrastructure
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
kuznia-rdzeni/coreblocks#1135 ·
-
good first issue server
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
documentation priority: high
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
a-lex-s/mealie-telegram-bot#54 ·
Los mantenedores suelen responder en 1 día
-
type/test
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
SaltedTan/virgil-language-server#218 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
btclib-org/btclib-wallet#541 ·
Los mantenedores suelen responder en 1 día