Skip to content

Commit 953f252

Browse files
authoredApr 17, 2024
Update security documentation to include security scanning tools (#3084)
* Update security documentation to include security scanning tools * Add details about address configuration in SECURITY.md * Fix spellcheck
1 parent d654750 commit 953f252

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed
 

‎README.md

+3
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ Refer to [torchserve docker](docker/README.md) for details.
103103

104104
For [more examples](examples/README.md)
105105

106+
## 🛡️ TorchServe Security Policy
107+
[SECURITY.md](SECURITY.md)
108+
106109
## 🤓 Learn More
107110
https://pytorch.org/serve
108111

‎SECURITY.md

+19-8
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,33 @@ TorchServe as much as possible relies on automated tools to do security scanning
2020
1. HTTP - `8080`, `8081`, `8082`
2121
2. gRPC - `7070`, `7071`
2222

23-
These ports are accessible to `localhost` by default. The address can be configured by following the [guide](https://pytorch.org/serve/configuration.html#configure-torchserve-listening-address-and-port)
24-
TorchServe does not prevent users from configuring the address to be `0.0.0.0`. Please be aware of the security risks if you use `0.0.0.0`
25-
2. TorchServe's Docker image is configured to expose the ports `8080`, `8081`, `8082`, `7070`, `7071` to the host by [default](https://github.com/pytorch/serve/blob/master/docker/Dockerfile). When these ports are mapped to the host, make sure to use `localhost` or a specific ip address.
23+
These ports are accessible to `localhost` by default. The addresses can be configured by following the guides for
24+
[HTTP](https://github.com/pytorch/serve/blob/master/docs/configuration.md#configure-torchserve-listening-address-and-port) and
25+
[gRPC](https://github.com/pytorch/serve/blob/master/docs/configuration.md#configure-torchserve-grpc-listening-addresses-and-ports).
26+
TorchServe does not prevent users from configuring the address to be any value, including the wildcard address `0.0.0.0`.
27+
Please be aware of the security risks of configuring the address to be `0.0.0.0`, this will give all addresses(including publicly accessible addresses, if any)
28+
on the host, access to the TorchServer endpoints listening on the ports shown above.
29+
2. TorchServe's Docker image is configured to expose the ports `8080`, `8081`, `8082`, `7070`, `7071` to the host by [default](https://github.com/pytorch/serve/blob/master/docker/Dockerfile). When starting the container,
30+
make sure to map the ports exposed by the container to `localhost` ports or a specific IP address as shown in this [security guideline](https://github.com/pytorch/serve/blob/master/docker/README.md#security-guideline).
2631

2732
3. Be sure to validate the authenticity of the `.mar` file being used with TorchServe.
28-
1. A `.mar` file being downloaded from the internet from an untrustworthy source may have malicious code, compromising the integrity of your application
29-
2. TorchServe executes arbitrary python code packaged in the `mar` file. Make sure that you've either audited that the code you're using is safe and/or is from a source that you trust
30-
4. By default TorchServe allows you to register models from all URLs. Make sure to set `allowed_urls` parameter in config.properties to restrict this. You can find more details in the [configuration guide](https://pytorch.org/serve/configuration.html#other-properties)
31-
- `use_env_allowed_urls=true` is required in config.properties to read `allowed_urls` from environment variable
33+
1. A `.mar` file being downloaded from the internet from an untrustworthy source may have malicious code, compromising the integrity of your application.
34+
2. TorchServe executes arbitrary python code packaged in the `mar` file. Make sure that you've either audited that the code you're using is safe and/or is from a source that you trust.
35+
3. Torchserve supports custom [plugins](https://github.com/pytorch/serve/tree/master/plugins) and [handlers](https://github.com/pytorch/serve/blob/master/docs/custom_service.md).
36+
These can be utilized to extend TorchServe functionality to perform runtime security scanning using tools such as:
37+
- Clamd: https://pypi.org/project/clamd/
38+
- VirusTotal: https://virustotal.github.io/vt-py/
39+
- Fickling: https://github.com/trailofbits/fickling
40+
4. Running Torchserve inside a container environment and loading an untrusted `.mar` file does not guarantee isolation from a security perspective.
41+
4. By default TorchServe allows you to register models from all URLs. Make sure to set `allowed_urls` parameter in config.properties to restrict this. You can find more details in the [configuration guide](https://pytorch.org/serve/configuration.html#other-properties).
42+
- `use_env_allowed_urls=true` is required in config.properties to read `allowed_urls` from environment variable.
3243
5. Enable SSL:
3344

3445
TorchServe supports two ways to configure SSL:
3546
1. Using a keystore
3647
2. Using private-key/certificate files
3748

38-
You can find more details in the [configuration guide](https://pytorch.org/serve/configuration.html#enable-ssl)
49+
You can find more details in the [configuration guide](https://pytorch.org/serve/configuration.html#enable-ssl).
3950
6. Prepare your model against bad inputs and prompt injections. Some recommendations:
4051
1. Pre-analysis: check how the model performs by default when exposed to prompt injection (e.g. using [fuzzing for prompt injection](https://github.com/FonduAI/awesome-prompt-injection?tab=readme-ov-file#tools)).
4152
2. Input Sanitation: Before feeding data to the model, sanitize inputs rigorously. This involves techniques such as:

‎ts_scripts/spellcheck_conf/wordlist.txt

+5
Original file line numberDiff line numberDiff line change
@@ -1218,3 +1218,8 @@ venv
12181218
TorchInductor
12191219
Pytests
12201220
deviceType
1221+
Clamd
1222+
Fickling
1223+
TorchServer
1224+
VirusTotal
1225+
untrusted

0 commit comments

Comments
 (0)