Skip to content

Bug fix in python regex in malwaregen.AnyCode detector#1296

Merged
jmartin-tech merged 1 commit intoNVIDIA:mainfrom
aishwaryap:fix/malwaregen_python_regex
Jul 16, 2025
Merged

Bug fix in python regex in malwaregen.AnyCode detector#1296
jmartin-tech merged 1 commit intoNVIDIA:mainfrom
aishwaryap:fix/malwaregen_python_regex

Conversation

@aishwaryap
Copy link
Collaborator

Bug fix: The Python regex in the malwaregen.AnyCode detector has a sys. in the regex which causes it to match text words starting with sys such as "system". Changing this to sys\. makes it more specific to python.

Verification

List the steps needed to make sure this thing works

  • The best way to notice the difference is to run the new test test_detectors_malwaregen.py on main and the branch with the fix: python -m pytest tests/detectors/test_detectors_malwaregen.py. This fails without the change and succeeds after. Note that this test is currently fairly limited and needs more positive and negative examples to be comprehensive.
  • Also verified using the following garak config with the OpenAI generator that it doesn't affect running of the malwaregen probes. Note that a difference in ASR is to be expected as the detector is substantially changed by this.
run:
  generations: 5

plugins:
  probe_spec: malwaregen
  extended_detectors: true
  probes:
    encoding:
      payloads:
        - default
        - xss
        - slur_terms
  model_type: openai
  model_name: gpt-4o
  generators:
    openai:
      model: gpt-4o
      max_tokens: 1024
      use_chat: true

system:
  parallel_attempts: 32
  lite: false

This change should not depend on the choice of generator and should not affect other probes.

  • Run the tests and ensure they pass python -m pytest tests/
  • Verify the thing does what it should - Added an example in test_detectors_malwaregen.py (can be more comprehensive)
  • Verify the thing does not do what it should not - Added an example in test_detectors_malwaregen.py (can be more comprehensive)

Copy link
Collaborator

@erickgalinkin erickgalinkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch, imo. Thanks so much!

@jmartin-tech jmartin-tech merged commit e035f36 into NVIDIA:main Jul 16, 2025
19 of 21 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants