Skip to content

Commit

Permalink
secrets scanning docs
Browse files Browse the repository at this point in the history
  • Loading branch information
lbeurerkellner committed Jun 14, 2024
1 parent 914e8ef commit 61f37b4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ This section provides a detailed overview of the analyzer's components, includin
* [Prompt Injection Detection](docs/STDLIB.md#prompt-injection-detection)
* [Moderation Violation Detection](docs/STDLIB.md#moderation-violation-detection)
* [Code Analysis And Secrets Scanning](docs/STDLIB.md#code-analysis-and-secrets-scanning)
* [Secrets Scanning](docs/STDLIB.md#secrets-scanning)
* [Custom Checkers](docs/STDLIB.md#custom-checkers)
- [Development](docs/DEVELOPMENT.md#development)
* [Testing](docs/DEVELOPMENT.md#testing)
Expand Down
16 changes: 16 additions & 0 deletions docs/STDLIB.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ raise PolicyViolation("must not use 'os' module in generated code", out=msg) if:

For instance, this rule checks that the assistant does not generate code that imports the `os` module, which could be used to execute unsafe operations. The standard library function `python_code` automatically parses a string as Python code and extracts information about the code, such as imports, function calls, and more.

### Secrets Scanning

If an AI agent interacts with external services or systems, it is important to ensure that the agent does not leak any sensitive information, such as API keys, passwords, or other secrets. The standard library includes checkers for detecting secrets in agent messages or tool outputs.

The available checkers are defined in [`invariant/stdlib/detectors/secrets.py`](../invariant/stdlib/invariant/detectors/secrets.py). For example, it can be used to analyze agent traces for secret leaks:

```python
from invariant.detectors import secrets

raise PolicyViolation("found secrets", msg) if:
(msg: Message)
"AWS_ACCESS_KEY" in secrets(msg)
```

The `secrets` function can be used to detect common secret patterns in messages, such as `AWS_ACCESS`. For the list of supported secret patterns, see `SECRETS_PATTERNS` in [this file](../invariant/runtime/utils/secrets.py).

### Custom Checkers

Lastly, you can also provide your own custom checking functions to the analyzer. This can be useful if you have specific security requirements or need to check for custom patterns or conditions that are not covered by the built-in checkers.
Expand Down

0 comments on commit 61f37b4

Please sign in to comment.