Skip to content

Commit

Permalink
feat(policies): initial Rails JWT leaks (#182)
Browse files Browse the repository at this point in the history
* feat: initial Rails JWT leaks

* chore: update snapshot
  • Loading branch information
elsapet authored Dec 1, 2022
1 parent c5c2118 commit cc94a7b
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
data_types:
- name: Email Address
detectors:
- name: detect_rails_jwt
locations:
- filename: testdata/ruby/detect_rails_jwt.rb
line_number: 12
- name: ruby
locations:
- filename: testdata/ruby/detect_rails_jwt.rb
line_number: 12
- name: Physical Address
detectors:
- name: detect_rails_jwt
locations:
- filename: testdata/ruby/detect_rails_jwt.rb
line_number: 10
- name: ruby
locations:
- filename: testdata/ruby/detect_rails_jwt.rb
line_number: 10
risks:
- detector_id: detect_rails_jwt
data_types:
- name: Email Address
stored: false
locations:
- filename: testdata/ruby/detect_rails_jwt.rb
line_number: 12
parent:
line_number: 10
content: JWT.encode user.address, nil, "none"
- name: Physical Address
stored: false
locations:
- filename: testdata/ruby/detect_rails_jwt.rb
line_number: 10
parent:
line_number: 10
content: JWT.encode user.address, nil, "none"
components: []


--

1 change: 1 addition & 0 deletions integration/custom_detectors/custom_detectors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func TestCustomDetectors(t *testing.T) {
newScanTest("ruby", "detect_ruby_logger", "detect_ruby_logger.rb"),
newScanTest("ruby", "ruby_file_detection", "ruby_file_detection.rb"),
newScanTest("ruby", "detect_rails_session", "detect_rails_session.rb"),
newScanTest("ruby", "detect_rails_jwt", "detect_rails_jwt.rb"),
}

testhelper.RunTests(t, tests)
Expand Down
12 changes: 12 additions & 0 deletions integration/custom_detectors/testdata/ruby/detect_rails_jwt.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
payload = {
user: {
first_name: "John",
last_name: "Doe",
}
}

token1 = JWT.encode payload, nil, "none"

token2 = JWT.encode user.address, nil, "none"

token3 = JWT.encode(user.email, nil, "none")
14 changes: 14 additions & 0 deletions integration/flags/.snapshots/TestInitCommand-init
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ scan:
root_lowercase: true
metavars: {}
stored: false
detect_rails_jwt:
disabled: false
type: risk
languages:
- ruby
patterns:
- |
JWT.encode(<$ARGUMENT>)
param_parenting: false
processors: []
root_singularize: false
root_lowercase: false
metavars: {}
stored: false
detect_rails_logger:
disabled: false
type: risk
Expand Down
7 changes: 7 additions & 0 deletions pkg/commands/process/settings/custom_detector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ detect_rails_session:
session[...] = $ANYTHING
languages:
- ruby
detect_rails_jwt:
type: "risk"
patterns:
- |
JWT.encode(<$ARGUMENT>)
languages:
- ruby
detect_encrypted_ruby_class_properties:
type: "verifier"
patterns:
Expand Down
10 changes: 10 additions & 0 deletions pkg/commands/process/settings/policies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ session_leaks:
modules:
- path: policies/leakage.rego
name: bearer.leakage
jwt_leaks:
description: "JWT leaks detected"
name: "JWT leaking"
id: "detect_rails_jwt"
query: |
critical = data.bearer.leakage.critical
high = data.bearer.leakage.high
modules:
- path: policies/leakage.rego
name: bearer.leakage
application_level_encryption_missing:
description: "Application level encryption missing"
name: "Application level encryption missing"
Expand Down

0 comments on commit cc94a7b

Please sign in to comment.