hedra 1.0.1 → 2.0.0

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