Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

BUG: KeywordSelectionStrategy accepts a negative context, so SelectiveTextConverter duplicates or truncates the prompt

Cerrado
#3,444 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

@ShivamSharma43 ya está trabajando en esto.

Desde el 21/10/2026.

  • #3446 de @ShivamSharma43 — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
python
Área
backend

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=-10 on "the secret plan" returns the range (4, 0), and the converter sends "the the secret plan": the text between end and start is duplicated and nothing is converted.
  • with context_before=-3 returns (7, 10), so only "ret" is converted and the rest of the keyword is sent in plaintext ("the seccmV0 plan" with Base64Converter).

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

Abrir en Codespaces

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

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de microsoft/PyRIT

Todos los issues de microsoft/PyRIT

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.