Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reapply "Add rules for pytorch config best practices" #64

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions generic/pytorch-allowed-urls.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
rules:
- id: pytorch-allowed-urls
message: Allowing URLs via environment variables is enabled
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why is this bad? What is more secure alternative?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We set impact to medium, but I don't see exploit scenario

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If it's not always exploitable maybe let's set category to best-practice?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed, category should be best practice here; that was my intention with this rule but I didn't realize it was an available option. I'll make this change — in fact I think it applies to some other rules in here as well.

languages: [generic]
severity: WARNING
metadata:
category: security
subcategory: [audit]
technology: [shell]
confidence: HIGH
likelihood: MEDIUM
impact: MEDIUM
references:
- https://pytorch.org/serve/configuration.html
paths:
include:
- 'config.properties'
pattern: "use_env_allowed_urls=true"
19 changes: 19 additions & 0 deletions generic/pytorch-auto-install-deps.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
rules:
- id: pytorch-auto-install-deps
message: Automatic installation of model dependencies is enabled
languages: [generic]
severity: WARNING
metadata:
category: security
subcategory: [audit]
technology: [shell]
confidence: HIGH
likelihood: MEDIUM
impact: MEDIUM
references:
- https://pytorch.org/serve/configuration.html
paths:
include:
- 'config.properties'
pattern: "install_py_dep_per_model=true"
"
19 changes: 19 additions & 0 deletions generic/pytorch-bound-to-all-interfaces.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
rules:
- id: pytorch-bound-to-all-interfaces
message: Pytorch binds to all interfaces
languages: [generic]
severity: ERROR
metadata:
category: security
subcategory: [audit]
technology: [shell]
confidence: HIGH
likelihood: MEDIUM
impact: HIGH
references:
- https://pytorch.org/serve/configuration.html
paths:
include:
- 'config.properties'
pattern-either:
- pattern-regex: (grpc_)?(inference|management|metrics)_address=https?://0\.0\.0\.0:\d+
19 changes: 19 additions & 0 deletions generic/pytorch-cors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
rules:
- id: pytorch-cors
message: CORS settings are specified but all origins are allowed
languages: [generic]
severity: WARNING
metadata:
category: security
subcategory: [audit]
technology: [shell]
confidence: HIGH
likelihood: MEDIUM
impact: MEDIUM
references:
- https://pytorch.org/serve/configuration.html
paths:
include:
- 'config.properties'
pattern-not:
- pattern: "cors_allowed_origin=*"
21 changes: 21 additions & 0 deletions generic/pytorch-defaults-job-queue-size.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
rules:
- id: pytorch-defaults-job-queue-size
message: No specified job queue size in Pytorch config (default 100)
languages: [generic]
severity: WARNING
metadata:
category: security
subcategory: [audit]
technology: [shell]
confidence: HIGH
likelihood: MEDIUM
impact: MEDIUM
references:
- https://pytorch.org/serve/configuration.html
paths:
include:
- 'config.properties'
patterns:
- pattern-regex: |
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is a strange bug that this rule will find issue in the following:

inference_address=https://127.0.0.1:8443




job_queue_size=2

May be semgrep's issue we may report

(?s)(.*)
- pattern-not-regex: .*job_queue_size=
21 changes: 21 additions & 0 deletions generic/pytorch-defaults-max-request-size.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
rules:
- id: pytorch-defaults-max-request-size
message: No specified maximum request size in Pytorch config
languages: [generic]
severity: WARNING
metadata:
category: security
subcategory: [audit]
technology: [shell]
confidence: HIGH
likelihood: MEDIUM
impact: MEDIUM
references:
- https://pytorch.org/serve/configuration.html
paths:
include:
- 'config.properties'
patterns:
- pattern-regex: |
(?s)(.*)
- pattern-not-regex: .*max_request_size=
21 changes: 21 additions & 0 deletions generic/pytorch-defaults-max-response-size.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
rules:
- id: pytorch-defaults-max-response-size
message: No specified maximum response size in Pytorch config
languages: [generic]
severity: WARNING
metadata:
category: security
subcategory: [audit]
technology: [shell]
confidence: HIGH
likelihood: MEDIUM
impact: MEDIUM
references:
- https://pytorch.org/serve/configuration.html
paths:
include:
- 'config.properties'
patterns:
- pattern-regex: |
(?s)(.*)
- pattern-not-regex: .*max_response_size=
21 changes: 21 additions & 0 deletions generic/pytorch-defaults-number-of-gpu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
rules:
- id: pytorch-defaults-number-of-gpu
message: No GPU usage limits in Pytorch config (defaults to all available)
languages: [generic]
severity: WARNING
metadata:
category: security
subcategory: [audit]
technology: [shell]
confidence: HIGH
likelihood: MEDIUM
impact: MEDIUM
references:
- https://pytorch.org/serve/configuration.html
paths:
include:
- 'config.properties'
patterns:
- pattern-regex: |
(?s)(.*)
- pattern-not-regex: .*number_of_gpu=
18 changes: 18 additions & 0 deletions generic/pytorch-limit-max-image-pixels.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
rules:
- id: pytorch-limit-max-image-pixels
message: Image size limit disabled in Pytorch config
languages: [generic]
severity: WARNING
metadata:
category: security
subcategory: [audit]
technology: [shell]
confidence: HIGH
likelihood: MEDIUM
impact: MEDIUM
references:
- https://pytorch.org/serve/configuration.html
paths:
include:
- 'config.properties'
pattern: "limit-max-image-pixels=false"
19 changes: 19 additions & 0 deletions generic/pytorch-unsecured-http.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
rules:
- id: pytorch-unsecured-http
message: Pytorch interface is exposed without TLS
languages: [generic]
severity: WARNING
metadata:
category: security
subcategory: [audit]
technology: [shell]
confidence: HIGH
likelihood: MEDIUM
impact: HIGH
references:
- https://pytorch.org/serve/configuration.html
paths:
include:
- 'config.properties'
pattern-either:
- pattern-regex: (grpc_)?(inference|management|metrics)_address=http://
Loading