Skip to content

Commit 662f923

Browse files
Merge pull request #113 from projectdiscovery/dwisiswant0/docs/add-encrypting-secrets-spec
docs: add encrypting secrets spec
2 parents f8c02d2 + f5e0467 commit 662f923

File tree

1 file changed

+68
-7
lines changed

1 file changed

+68
-7
lines changed

tools/nuclei/authenticated-scans.mdx

Lines changed: 68 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Since authentication can be done in multiple ways, for example, using 3rd party
3131
### Dealing with Dynamic Authentication
3232

3333
Implementing and managing Static Authentication is easy, but dealing with Dynamic Authentication is a bit complex due to multiple entities and secrets and the flow of authentication being involved. Some might require a browser guided authentication while some might be achievable with auth flow.
34-
A common solution for this is to capture and generate a login flow/sequence using a browser and then feed that script to app handling the authentication._createMdxContent
34+
A common solution for this is to capture and generate a login flow/sequence using a browser and then feed that script to app handling the authentication.
3535

3636
To focus on making this process easy, familiar, and scalable (users should be able to scan thousands of targets with authentication without much hassle), we leverage the existing rich ecosystem of `nuclei-templates`. These are written in YAML, are scalable, and comes with a powerful engine.
3737

@@ -53,15 +53,76 @@ Since authentication can be done in multiple ways, for example, using 3rd party
5353
We have not imposed the need to hardcode secrets in the `Secret File` configuration, and support the use of third-party secret management systems to templatize and manage secrets.
5454

5555

56-
### Integrations with Secret Management Systems
56+
### Encrypting Secrets
5757

58-
We are currently exploring integrations with popular secret management systems for easy and secure management of secrets
58+
To make it easy to manage and encrypt your secrets, Nuclei integrates with [SOPS](https://github.com/getsops/sops). It's a tool designed specifically for encrypting and decrypting files, allowing you to store sensitive information like API keys or passwords in a secure format. By integrating SOPS into your workflow, you can ensure your sensitive data is encrypted at rest while still being accessible to Nuclei during runtime.
5959

60-
We are prioritizng support for:
60+
<Note>
61+
This feature is available in Nuclei **vX.Y.Z**.
62+
</Note>
6163

62-
- **1Password**
63-
- **Hashicorp Vault**
64-
- **AWS Secrets Manager**
64+
#### Recommended SOPS Configuration
65+
66+
To simplify the encryption process, you can set up a [`.sops.yaml`](https://github.com/projectdiscovery/nuclei/blob/dev/.sops.yaml) file with rules that automatically encrypt specific [fields](/tools/nuclei/authenticated-scans#secret-file-fields) in your files. Here's a recommended configuration:
67+
68+
```yaml
69+
creation_rules:
70+
- encrypted_regex: ^(password|username|token|value|key|raw)$
71+
```
72+
73+
With this setup, SOPS will automatically encrypt [fields](/tools/nuclei/authenticated-scans#secret-file-fields) that match common sensitive patterns such as password, username, token, and similar keys whenever you create or update your files. This reduces the chances of accidentally exposing sensitive information in plaintext.
74+
75+
Here's a simple guide to help you create and use encrypted secret files with Nuclei:
76+
77+
1. [Define your secret file](/tools/nuclei/authenticated-scans#secret-file-formats)
78+
2. Encrypt the Secret File with SOPS
79+
80+
Use SOPS to encrypt the plaintext file. Run the following command in your terminal:
81+
82+
```bash
83+
sops encrypt --output secret-file.enc.yaml secret-file.yaml
84+
```
85+
86+
This command generates an encrypted version of your file called `secret-file.enc.yaml`. The original plaintext file (`secret-file.yaml`) should be deleted afterward to avoid accidentally exposing your sensitive data.
87+
88+
<Note>
89+
Please refer to the [SOPS documentation](https://getsops.io/docs/) for encrypting with AWS KMS, GCP KMS, Azure Key Vault, age, or PGP.
90+
</Note>
91+
92+
3. Verify the Encrypted Secret File
93+
94+
Open the encrypted file (`secret-file.enc.yaml`) to confirm that all sensitive fields have been encrypted. You should see unreadable ciphertext that looks something like this:
95+
96+
```yaml
97+
username: ENC[AES256_GCM,data:...,iv:...,tag:...]
98+
password: ENC[AES256_GCM,data:...,iv:...,tag:...]
99+
api_key: ENC[AES256_GCM,data:...,iv:...,tag:...]
100+
```
101+
102+
This means your secrets are now securely encrypted.
103+
104+
4. Use the Encrypted Secret File with Nuclei
105+
106+
Configure Nuclei to use the encrypted secret file (`secret-file.enc.yaml`) with `-secret-file`/`-sf` flag during execution. Nuclei will automatically decrypt the file at runtime, ensuring the secrets are accessible only when needed without ever exposing them in plaintext. This keeps your sensitive data secure both at rest and in use.
107+
108+
#### Why Use Encrypted Secret Files?
109+
110+
Using encrypted secret files ensures that your sensitive information is always stored securely, whether it's in your local environment or being shared across systems. It prevents accidental leaks of confidential data and aligns with best practices for secure application development. Plus, since Nuclei handles decryption on the fly, you don't need to worry about manually decrypting files or exposing plaintext values in your configuration.
111+
112+
#### `.gitignore` Configuration
113+
114+
To prevent sensitive files from being accidentally committed to your Git repository, it's important to update your `.gitignore` file. Here's a recommended configuration:
115+
116+
```yaml
117+
# Ignore all YAML files except encrypted files and SOPS config
118+
*.yaml
119+
!*.enc.yaml
120+
!.sops.yaml
121+
```
122+
123+
This setup ignores all YAML files by default, ensuring that plaintext secret files like `secret-file.yaml` are never tracked in your repo. However, it makes an exception for encrypted files (`*.enc.yaml`) and the SOPS configuration file (`.sops.yaml`), allowing you to safely store and share these files.
124+
125+
By following these steps and best practices, you can effectively secure your secrets while keeping them accessible for use with Nuclei. This approach ensures your sensitive information stays safe and your workflow remains smooth and efficient.
65126

66127
### Skipping Secret File
67128

0 commit comments

Comments
 (0)