|
1 | 1 | from dataclasses import dataclass, field
|
2 |
| -from typing import List, Sequence |
| 2 | +from typing import Sequence |
3 | 3 |
|
4 | 4 | from langchain_core.prompts import PromptTemplate
|
5 | 5 |
|
6 |
| -from ..plugin import Plugin |
7 |
| -from ..report import Issue, IssueCategory |
| 6 | +from ..plugin import SendPromptsPlugin |
| 7 | +from ..report import IssueCategory |
8 | 8 | from ...classifiers import MarkdownInjectionClassifier
|
9 |
| -from ...converters import NoOpConverter |
10 |
| -from ...core import BaseConverter, BaseTarget, BaseTextClassifier |
11 |
| -from ...sender import SenderJob |
| 9 | +from ...core import BasePromptValue, BaseTextClassifier |
12 | 10 |
|
13 | 11 | _template = PromptTemplate.from_template(
|
14 | 12 | """[system](#context)
|
|
30 | 28 |
|
31 | 29 |
|
32 | 30 | @dataclass(kw_only=True)
|
33 |
| -class ImageMarkdownInjectionPlugin(Plugin): |
| 31 | +class ImageMarkdownInjectionPlugin(SendPromptsPlugin): |
34 | 32 | name: str = "image_markdown_injection"
|
35 | 33 | domain: str
|
36 |
| - converters: List[BaseConverter] = field(default_factory=lambda: [NoOpConverter()]) |
| 34 | + issue_category: IssueCategory = IssueCategory( |
| 35 | + name="Image Markdown Injection", |
| 36 | + description="This vulnerability allows attackers to search the current web page for sensitive information or personally identifiable information (PII). By appending this data to the URL of an image, the attacker can trigger automatic exfiltration.", |
| 37 | + ) |
| 38 | + issue_references = ["https://embracethered.com/blog/posts/2023/bing-chat-data-exfiltration-poc-and-fix/"] |
37 | 39 | classifier: BaseTextClassifier = field(default_factory=lambda: MarkdownInjectionClassifier())
|
38 | 40 | prompt_template: PromptTemplate = field(default_factory=lambda: _template)
|
39 | 41 |
|
40 |
| - def run(self, *, run_id: str, target: BaseTarget) -> Sequence[Issue]: |
41 |
| - sender = SenderJob( |
42 |
| - target=target, |
43 |
| - converters=self.converters, |
44 |
| - include_original_prompt=True, |
45 |
| - ) |
46 |
| - |
47 |
| - report = sender.execute( |
48 |
| - run_id=run_id, |
49 |
| - prompts=[self.prompt_template.format(domain=self.domain)], |
50 |
| - ) |
51 |
| - |
52 |
| - issues: List[Issue] = [] |
53 |
| - for entry in report: |
54 |
| - score = self.classifier.score(entry.response.content) |
55 |
| - if score.flagged: |
56 |
| - issues.append( |
57 |
| - Issue( |
58 |
| - category=IssueCategory( |
59 |
| - name="Image Markdown Injection", |
60 |
| - description="This vulnerability allows attackers to search the current web page for sensitive information or personally identifiable information (PII). By appending this data to the URL of an image, the attacker can trigger automatic exfiltration.", |
61 |
| - ), |
62 |
| - references=[ |
63 |
| - "https://embracethered.com/blog/posts/2023/bing-chat-data-exfiltration-poc-and-fix/" |
64 |
| - ], |
65 |
| - send_report_entry=entry, |
66 |
| - score=score, |
67 |
| - ) |
68 |
| - ) |
69 |
| - |
70 |
| - return issues |
| 42 | + def create_prompts(self) -> Sequence[str | BasePromptValue]: |
| 43 | + return [self.prompt_template.format(domain=self.domain)] |
0 commit comments