hedra 1.0.1 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7ead36ae675253cd990b46928a4ce3cfa7046dde55e2353c6101b53953edd18
4
- data.tar.gz: 3c5361c38a9393ca66310eb19809a9a770b4ef91476d21010c56cccb5d76fec3
3
+ metadata.gz: 29f821e98e18bbcc4bcf7fbc46ee4fa54f064c64b270af72e16311ab41c751e3
4
+ data.tar.gz: bbe84abcc44aa9e0329a5fac5537465fae853b6f29a0b7a07725f3eb2b9f6b65
5
5
  SHA512:
6
- metadata.gz: 4505267cfc8111cc24680a5962941786edeae9bbd133d75d9ab7bbc61c7ea32ca2dd4281bd655d090cf8513f1951232fa074edd64ba33b4544e9bd425294566c
7
- data.tar.gz: 36616c7e22a2fd223d1d5c760a96bfa6c09c5a06392073c836d4b8414f81a272896ec96f57f348e8c78f65cc9f45481c930dbdeceb899d2b26afd5a9663b7e68
6
+ metadata.gz: 1bea6171146693b87f815945d6c572d0336b3035d56eafeb382406f8e74578f408b4c2a1282e6cb3dc2a131d4e03d9606733173f669a5a8f9d1993ae15cb84b5
7
+ data.tar.gz: 0b14d12d73cfa5037ab5481d722ddbf399dbc8a634f9b856748d6b9411d282af66c1ffb14afcafebb7ea695fa92a25dc348bfc793bdee1fba8f04633acfc360b
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 BlackStack
3
+ Copyright (c) 2025 bl4ckstack
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,147 +1,461 @@
1
- # Hedra 🛡️
1
+ # Hedra
2
2
 
3
- [![Ruby](https://img.shields.io/badge/ruby-%3E%3D%203.0-ruby.svg)](https://www.ruby-lang.org/)
4
- [![CI](https://github.com/blackstack/hedra/workflows/CI/badge.svg)](https://github.com/blackstack/hedra/actions)
5
- [![Gem Version](https://badge.fury.io/rb/hedra.svg)](https://badge.fury.io/rb/hedra)
6
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
3
+ [![Ruby](https://img.shields.io/badge/Ruby-3.0%2B-CC342D?style=flat&logo=ruby)](https://www.ruby-lang.org/)
4
+ [![Gem Version](https://img.shields.io/gem/v/hedra?style=flat&logo=rubygems&color=E9573F)](https://rubygems.org/gems/hedra)
5
+ [![License](https://img.shields.io/badge/License-MIT-00A98F?style=flat)](LICENSE)
6
+ [![Downloads](https://img.shields.io/gem/dt/hedra?style=flat&color=blue)](https://rubygems.org/gems/hedra)
7
7
 
8
- A comprehensive security header analyzer for modern web applications.
8
+ > Security header analyzer with SSL/TLS validation, baseline tracking, and CI/CD integration.
9
9
 
10
- ## Installation
10
+ <p align="center">
11
+ <img src="logo.png" width="380" alt="Hedra Logo"/>
12
+ </p>
11
13
 
14
+ ## Installation
12
15
  ```bash
13
16
  gem install hedra
14
17
  ```
15
18
 
16
- ## Usage
19
+ ## Quick Start
20
+ ```bash
21
+ hedra scan https://github.com
22
+ hedra audit https://stripe.com --json
23
+ hedra scan -f urls.txt --format html --output report.html
24
+ ```
17
25
 
18
- ### Scan a URL
26
+ ## Commands
19
27
 
28
+ ### scan
29
+
30
+ Scan URLs for security headers with flexible output options.
20
31
  ```bash
21
- hedra scan https://example.com
32
+ hedra scan https://github.com
33
+ hedra scan -f urls.txt --concurrency 20
34
+ hedra scan https://stripe.com --cache --rate 10/s
22
35
  ```
23
36
 
24
- ### Detailed Audit
25
-
37
+ **Key Options:**
38
+ - `-f, --file FILE` • Read URLs from file
39
+ - `-c, --concurrency N` • Concurrent requests (default: 10)
40
+ - `-t, --timeout N` • Request timeout in seconds (default: 10)
41
+ - `--rate RATE` • Rate limit: 10/s, 100/m, 1000/h
42
+ - `--cache` • Enable response caching
43
+ - `--cache-ttl N` • Cache TTL in seconds (default: 3600)
44
+ - `-o, --output FILE` • Output file
45
+ - `--format FORMAT` • table, json, csv, html (default: table)
46
+ - `--proxy URL` • HTTP/SOCKS proxy
47
+ - `--user-agent STRING` • Custom User-Agent
48
+ - `--save-baseline NAME` • Save results as baseline
49
+ - `--[no-]progress` • Show/hide progress bar
50
+ - `--[no-]check-certificates` • SSL checks (default: enabled)
51
+ - `--[no-]check-security-txt` • RFC 9116 checks
52
+
53
+ ### audit
54
+
55
+ Deep security audit with detailed recommendations.
26
56
  ```bash
27
- hedra audit https://example.com
57
+ hedra audit https://github.com
58
+ hedra audit https://api.stripe.com --json --output report.json
28
59
  ```
29
60
 
30
- ### Export as JSON
61
+ **Options:**
62
+ - `--json` • JSON output format
63
+ - `-o, --output FILE` • Output file
64
+ - `--proxy URL` • HTTP/SOCKS proxy
65
+ - `--user-agent STRING` • Custom User-Agent
66
+ - `-t, --timeout N` • Request timeout
67
+ - `--[no-]check-certificates` • SSL/TLS validation
68
+ - `--[no-]check-security-txt` • security.txt checks
31
69
 
70
+ ### watch
71
+
72
+ Monitor security headers periodically.
32
73
  ```bash
33
- hedra audit https://example.com --json --output report.json
74
+ hedra watch https://myapp.com --interval 3600
34
75
  ```
35
76
 
36
- ### Scan Multiple URLs
77
+ **Options:**
78
+ - `--interval N` • Check interval in seconds (default: 3600)
79
+
80
+ ### compare
37
81
 
82
+ Compare security headers between environments.
38
83
  ```bash
39
- # Create urls.txt with one URL per line
40
- hedra scan -f urls.txt --concurrency 20
84
+ hedra compare https://staging.myapp.com https://myapp.com
41
85
  ```
42
86
 
43
- ### Monitor Over Time
87
+ ### ci_check
44
88
 
89
+ CI/CD-friendly check with exit codes and thresholds.
45
90
  ```bash
46
- hedra watch https://example.com --interval 3600
91
+ hedra ci_check https://myapp.com --threshold 85
92
+ hedra ci_check -f urls.txt --fail-on-critical
47
93
  ```
48
94
 
49
- ### Compare Headers
95
+ **Options:**
96
+ - `-f, --file FILE` • Read URLs from file
97
+ - `--threshold N` • Minimum score threshold (default: 80)
98
+ - `--fail-on-critical` • Fail on critical issues (default: true)
50
99
 
100
+ **Exit Codes:**
101
+ - `0` • All checks passed
102
+ - `1` • Score below threshold or critical issues found
103
+
104
+ ### baseline
105
+
106
+ Track security posture changes over time.
51
107
  ```bash
52
- hedra compare https://staging.example.com https://prod.example.com
108
+ hedra baseline list
109
+ hedra baseline compare production-v1 -f urls.txt
110
+ hedra baseline delete production-v1
53
111
  ```
54
112
 
55
- ## Security Headers Checked
113
+ ### cache
56
114
 
57
- - **Content-Security-Policy (CSP)** - Prevents XSS attacks
58
- - **Strict-Transport-Security (HSTS)** - Enforces HTTPS
59
- - **X-Frame-Options** - Prevents clickjacking
60
- - **X-Content-Type-Options** - Prevents MIME-sniffing
61
- - **Referrer-Policy** - Controls referrer information
62
- - **Permissions-Policy** - Controls browser features
63
- - **Cross-Origin-Opener-Policy (COOP)**
64
- - **Cross-Origin-Embedder-Policy (COEP)**
65
- - **Cross-Origin-Resource-Policy (CORP)**
115
+ Manage response cache for faster repeated scans.
116
+ ```bash
117
+ hedra cache clear
118
+ hedra cache clear-expired
119
+ ```
66
120
 
67
- ## Options
121
+ ### plugin
68
122
 
123
+ Extend functionality with custom security checks.
69
124
  ```bash
70
- # Concurrent scanning
71
- hedra scan -f urls.txt --concurrency 20 --timeout 15
125
+ hedra plugin list
126
+ hedra plugin install path/to/plugin.rb
127
+ hedra plugin remove plugin_name
128
+ ```
72
129
 
73
- # Through a proxy
74
- hedra scan https://example.com --proxy http://127.0.0.1:8080
130
+ ## Security Checks
75
131
 
76
- # Custom User-Agent
77
- hedra scan https://example.com --user-agent "MyBot/1.0"
132
+ ### HTTP Headers Analyzed
78
133
 
79
- # Follow redirects
80
- hedra scan https://example.com --follow-redirects
134
+ | Header | Weight | Purpose |
135
+ |--------|--------|---------|
136
+ | Content-Security-Policy | 25 pts | Prevent XSS and injection attacks |
137
+ | Strict-Transport-Security | 25 pts | Enforce HTTPS connections |
138
+ | X-Frame-Options | 15 pts | Prevent clickjacking |
139
+ | X-Content-Type-Options | 10 pts | Stop MIME-type sniffing |
140
+ | Referrer-Policy | 10 pts | Control referrer information |
141
+ | Permissions-Policy | 5 pts | Manage browser features |
142
+ | Cross-Origin-Opener-Policy | 5 pts | Isolate browsing context |
143
+ | Cross-Origin-Embedder-Policy | 3 pts | Enable cross-origin isolation |
144
+ | Cross-Origin-Resource-Policy | 2 pts | Control resource loading |
81
145
 
82
- # Export as CSV
83
- hedra scan -f urls.txt --output results.csv --format csv
84
- ```
146
+ ### Additional Validations
147
+
148
+ **SSL/TLS Checks:**
149
+ - Certificate expiry dates
150
+ - Signature algorithm strength
151
+ - Key size validation
152
+ - Chain verification
153
+
154
+ **RFC 9116:**
155
+ - security.txt file presence and format
156
+
157
+ ### Scoring System
158
+
159
+ **Base:** 100 points from header weights
160
+
161
+ **Penalties:**
162
+ - Critical issue: -20 points
163
+ - Warning: -10 points
164
+ - Info: -5 points
85
165
 
86
166
  ## Configuration
87
167
 
88
168
  Create `~/.hedra/config.yml`:
89
-
90
169
  ```yaml
170
+ # HTTP settings
91
171
  timeout: 10
92
172
  concurrency: 10
93
- user_agent: "Hedra/1.0.0"
94
- output_format: table
173
+ user_agent: "Hedra/2.0.0"
174
+ follow_redirects: true
175
+ max_retries: 3
176
+
177
+ # Performance
178
+ cache_enabled: false
179
+ cache_ttl: 3600
180
+ rate_limit: "10/s"
181
+
182
+ # Security checks
183
+ check_certificates: true
184
+ check_security_txt: false
185
+
186
+ # Output
187
+ output_format: "table"
188
+ progress_bar: true
189
+
190
+ # Circuit breaker
191
+ circuit_breaker_threshold: 5
192
+ circuit_breaker_timeout: 60
95
193
  ```
96
194
 
97
195
  ## Custom Rules
98
196
 
99
- Create `~/.hedra/rules.yml`:
100
-
197
+ Define organization-specific policies in `~/.hedra/rules.yml`:
101
198
  ```yaml
102
199
  rules:
103
200
  - header: "X-Custom-Security"
104
201
  type: missing
105
202
  severity: warning
106
203
  message: "Custom security header is missing"
107
- fix: "Add X-Custom-Security header"
204
+ fix: "Add X-Custom-Security: enabled"
205
+
206
+ - header: "Server"
207
+ type: pattern
208
+ pattern: "^(Apache|nginx)"
209
+ severity: info
210
+ message: "Server header exposes software version"
211
+ fix: "Remove or obfuscate Server header"
108
212
  ```
109
213
 
110
- ## Plugins
214
+ **Rule Types:**
215
+ - `missing` • Header should be present
216
+ - `pattern` • Header value must match regex
217
+
218
+ **Severity Levels:**
219
+ - `critical` • -20 points, immediate action required
220
+ - `warning` • -10 points, should be addressed
221
+ - `info` • -5 points, best practice
111
222
 
112
- Create custom header checks:
223
+ ## Plugin System
113
224
 
225
+ Create custom checks in `~/.hedra/plugins/`:
114
226
  ```ruby
115
- # ~/.hedra/plugins/my_plugin.rb
227
+ # ~/.hedra/plugins/corporate_policy.rb
116
228
  module Hedra
117
- class MyPlugin < Plugin
229
+ class CorporatePolicyPlugin < Plugin
118
230
  def self.check(headers)
119
231
  findings = []
120
- unless headers.key?('x-my-header')
232
+
233
+ # Enforce corporate header
234
+ unless headers.key?('x-corp-security')
235
+ findings << {
236
+ header: 'x-corp-security',
237
+ issue: 'Corporate security header missing',
238
+ severity: :critical,
239
+ recommended_fix: 'Add X-Corp-Security: v2'
240
+ }
241
+ end
242
+
243
+ # Check version disclosure
244
+ if headers['server']&.match?(/\d+\.\d+/)
121
245
  findings << {
122
- header: 'x-my-header',
123
- issue: 'Custom header missing',
246
+ header: 'server',
247
+ issue: 'Server version exposed',
124
248
  severity: :warning,
125
- recommended_fix: 'Add X-My-Header'
249
+ recommended_fix: 'Remove version from Server header'
126
250
  }
127
251
  end
252
+
128
253
  findings
129
254
  end
130
255
  end
131
256
  end
132
257
  ```
133
258
 
134
- Install plugin:
135
-
259
+ **Management:**
136
260
  ```bash
137
- hedra plugin install ~/.hedra/plugins/my_plugin.rb
261
+ hedra plugin install ~/.hedra/plugins/corporate_policy.rb
138
262
  hedra plugin list
263
+ hedra plugin remove corporate_policy
139
264
  ```
140
265
 
141
- ## Development
266
+ ## CI/CD Integration
267
+
268
+ ### GitHub Actions
269
+ ```yaml
270
+ name: Security Headers Check
271
+
272
+ on: [push, pull_request]
273
+
274
+ jobs:
275
+ security-scan:
276
+ runs-on: ubuntu-latest
277
+ steps:
278
+ - uses: actions/checkout@v3
279
+
280
+ - name: Setup Ruby
281
+ uses: ruby/setup-ruby@v1
282
+ with:
283
+ ruby-version: '3.2'
284
+
285
+ - name: Install Hedra
286
+ run: gem install hedra
287
+
288
+ - name: Run Security Check
289
+ run: hedra ci_check ${{ secrets.APP_URL }} --threshold 85
290
+
291
+ - name: Generate HTML Report
292
+ if: always()
293
+ run: hedra scan ${{ secrets.APP_URL }} --output report.html --format html
294
+
295
+ - name: Upload Report
296
+ if: always()
297
+ uses: actions/upload-artifact@v3
298
+ with:
299
+ name: security-report
300
+ path: report.html
301
+ ```
302
+
303
+ ### GitLab CI
304
+ ```yaml
305
+ security_headers:
306
+ image: ruby:3.2
307
+ script:
308
+ - gem install hedra
309
+ - hedra ci_check $APP_URL --threshold 85
310
+ - hedra scan $APP_URL --output report.json --format json
311
+ artifacts:
312
+ reports:
313
+ junit: report.json
314
+ paths:
315
+ - report.json
316
+ only:
317
+ - merge_requests
318
+ - main
319
+ ```
320
+
321
+ ### Jenkins Pipeline
322
+ ```groovy
323
+ pipeline {
324
+ agent any
325
+
326
+ stages {
327
+ stage('Security Headers') {
328
+ steps {
329
+ sh 'gem install hedra'
330
+ sh 'hedra ci_check ${APP_URL} --threshold 85'
331
+ }
332
+ }
333
+ }
334
+
335
+ post {
336
+ always {
337
+ sh 'hedra scan ${APP_URL} --output report.html --format html'
338
+ publishHTML([
339
+ reportDir: '.',
340
+ reportFiles: 'report.html',
341
+ reportName: 'Security Report'
342
+ ])
343
+ }
344
+ }
345
+ }
346
+ ```
347
+
348
+ ## Export Formats
349
+
350
+ ### Table (Default)
351
+ ```bash
352
+ hedra scan https://github.com
353
+ ```
354
+
355
+ Clean, colored terminal output with scores and recommendations.
356
+
357
+ ### JSON
358
+ ```bash
359
+ hedra scan https://stripe.com --output report.json --format json
360
+ ```
361
+
362
+ Structured data for automation and parsing.
142
363
 
364
+ ### CSV
143
365
  ```bash
144
- # Clone and install
366
+ hedra scan -f urls.txt --output report.csv --format csv
367
+ ```
368
+
369
+ Import into spreadsheets for analysis and tracking.
370
+
371
+ ### HTML
372
+ ```bash
373
+ hedra scan -f urls.txt --output report.html --format html
374
+ ```
375
+
376
+ Interactive report with sorting, filtering, and charts.
377
+
378
+ ## Real-World Examples
379
+
380
+ ### Basic Security Audit
381
+ ```bash
382
+ hedra scan https://myapp.com
383
+ ```
384
+
385
+ ### Production Deployment Check
386
+ ```bash
387
+ # Save baseline after deployment
388
+ hedra scan -f production-urls.txt --save-baseline prod-v2.1.0
389
+
390
+ # Compare before next deployment
391
+ hedra baseline compare prod-v2.1.0 -f production-urls.txt
392
+ ```
393
+
394
+ ### High-Volume Scanning
395
+ ```bash
396
+ # Scan 1000 URLs with rate limiting and caching
397
+ hedra scan -f large-list.txt \
398
+ --concurrency 50 \
399
+ --rate 20/s \
400
+ --cache \
401
+ --output results.json \
402
+ --format json
403
+ ```
404
+
405
+ ### Continuous Monitoring
406
+ ```bash
407
+ # Check every hour
408
+ hedra watch https://api.myapp.com --interval 3600
409
+ ```
410
+
411
+ ### Environment Comparison
412
+ ```bash
413
+ hedra compare https://staging.myapp.com https://myapp.com
414
+ ```
415
+
416
+ ### Proxy-Based Testing
417
+ ```bash
418
+ # Route through Burp Suite
419
+ hedra scan https://target.com --proxy http://127.0.0.1:8080
420
+ ```
421
+
422
+ ### Custom User-Agent
423
+ ```bash
424
+ hedra scan https://myapp.com --user-agent "Mozilla/5.0 (iPhone; CPU iPhone OS 14_0)"
425
+ ```
426
+
427
+ ## Performance Tuning
428
+
429
+ ### Caching Strategy
430
+ ```bash
431
+ # Enable caching for repeated scans
432
+ hedra scan -f urls.txt --cache --cache-ttl 7200
433
+
434
+ # Clear cache when needed
435
+ hedra cache clear
436
+ ```
437
+
438
+ ### Rate Limiting
439
+ ```bash
440
+ # Conservative approach
441
+ hedra scan -f urls.txt --rate 10/s --concurrency 5
442
+
443
+ # Aggressive scanning
444
+ hedra scan -f urls.txt --rate 100/s --concurrency 50
445
+ ```
446
+
447
+ ### Timeout Configuration
448
+ ```bash
449
+ # Fast scan for responsive servers
450
+ hedra scan -f urls.txt --timeout 5
451
+
452
+ # Patient scan for slow servers
453
+ hedra scan -f urls.txt --timeout 30
454
+ ```
455
+
456
+ ## Development
457
+ ```bash
458
+ # Clone and setup
145
459
  git clone https://github.com/blackstack/hedra.git
146
460
  cd hedra
147
461
  bundle install
@@ -149,67 +463,45 @@ bundle install
149
463
  # Run tests
150
464
  bundle exec rspec
151
465
 
152
- # Run linter
466
+ # Check code style
153
467
  bundle exec rubocop
154
468
 
155
469
  # Build gem
156
470
  rake build
471
+ gem install pkg/hedra-*.gem
157
472
  ```
158
473
 
159
- ## Output Examples
160
-
161
- ### Table Format
474
+ ## Troubleshooting
162
475
 
476
+ ### SSL Certificate Errors
477
+ ```bash
478
+ # Skip certificate validation
479
+ hedra scan https://self-signed.badssl.com --no-check-certificates
163
480
  ```
164
- https://example.com
165
- Score: 75/100
166
- Timestamp: 2025-11-12T10:30:00Z
167
481
 
168
- ┌─────────────────────────────┬──────────────────────────────┬──────────────┐
169
- │ Header │ Issue │ Severity │
170
- ├─────────────────────────────┼──────────────────────────────┼──────────────┤
171
- x-frame-options │ Header is missing │ WARNING │
172
- │ referrer-policy │ Header is missing │ ● INFO │
173
- └─────────────────────────────┴──────────────────────────────┴──────────────┘
482
+ ### Rate Limiting Issues
483
+ ```bash
484
+ # Reduce load on target server
485
+ hedra scan -f urls.txt --concurrency 1 --rate 1/s
174
486
  ```
175
487
 
176
- ### JSON Format
177
-
178
- ```json
179
- {
180
- "url": "https://example.com",
181
- "timestamp": "2025-11-12T10:30:00Z",
182
- "score": 75,
183
- "headers": {
184
- "content-security-policy": "default-src 'self'",
185
- "strict-transport-security": "max-age=31536000"
186
- },
187
- "findings": [
188
- {
189
- "header": "x-frame-options",
190
- "issue": "X-Frame-Options header is missing",
191
- "severity": "warning",
192
- "recommended_fix": "Add X-Frame-Options: DENY or SAMEORIGIN"
193
- }
194
- ]
195
- }
488
+ ### Timeout Problems
489
+ ```bash
490
+ # Increase timeout for slow servers
491
+ hedra scan https://slow-server.com --timeout 60
196
492
  ```
197
493
 
198
- ## Contributing
494
+ ## Resources
199
495
 
200
- 1. Fork the repository
201
- 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
202
- 3. Write tests for your changes
203
- 4. Ensure tests pass (`bundle exec rspec`)
204
- 5. Ensure linting passes (`bundle exec rubocop`)
205
- 6. Commit your changes (`git commit -am 'Add amazing feature'`)
206
- 7. Push to the branch (`git push origin feature/amazing-feature`)
207
- 8. Open a Pull Request
496
+ **GitHub:** https://github.com/blackstack/hedra
497
+ **RubyGems:** https://rubygems.org/gems/hedra
498
+ **Issues:** https://github.com/blackstack/hedra/issues
499
+ **OWASP Headers:** https://owasp.org/www-project-secure-headers/
208
500
 
209
501
  ## License
210
502
 
211
- MIT License - see [LICENSE](LICENSE) file for details.
503
+ MIT License - see [LICENSE](LICENSE) for details.
212
504
 
213
505
  ---
214
506
 
215
- Built by [BlackStack](https://github.com/bl4ckstack)
507
+ **Built by [BlackStack](https://github.com/bl4ckstack)** • Securing the web, one header at a time.