8000 Factor sync_advisories into its own file · hardBox/rubysec.github.com@ef3af8e · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ef3af8e

Browse files
committed
Factor sync_advisories into its own file
1 parent 7522631 commit ef3af8e

File tree

2 files changed

+68
-66
lines changed

2 files changed

+68
-66
lines changed

Rakefile

Lines changed: 3 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ require "rubygems"
22
require "bundler/setup"
33
require "stringex"
44

5+
# Load Rake tasks from the tasks/ directory
6+
Dir["tasks/**/*.rake"].each { |task| load task }
7+
58
## -- Rsync Deploy config -- ##
69
# Be sure your public key is listed in your server's ~/.ssh/authorized_keys file
710
ssh_user = "user@domain.com"
@@ -380,70 +383,4 @@ desc "list tasks"
380383
task :list do
381384
puts "Tasks: #{(Rake::Task.tasks - [Rake::Task[:list]]).join(', ')}"
382385
puts "(type rake -T for more detail)\n\n"
383-
end
384-
385-
#############################
386-
# Rebuild advisory Markdown #
387-
#############################
388-
require 'net/http'
389-
390-
desc "sync with ruby-advisory-db and rebuild Markdown files"
391-
task :sync_advisories do
392-
sh "git submodule update"
393-
394-
Rake::FileList["ruby-advisory-db/gems/**/*.yml"].each do |advisory|
395-
yaml = YAML.load_file(advisory)
396-
397-
cve = "CVE-" + yaml['cve']
398-
title = yaml['title'].gsub(/\s+/m, ' ')
399-
400-
title = "#{cve}: #{title}"
401-
slug = title.downcase.gsub(/[^\w]+/, '-')
402-
403-
puts "Processing: #{title}"
404-
405-
if yaml['url']['osvdb.org']
406-
osvdb_entry = Net::HTTP.get URI(yaml['url'])
407-
date = osvdb_entry[/(\d{4}-\d{2}-\d{2})\<\/td/, 1]
408-
else
409-
nvd_entry = Net::HTTP.get URI("http://web.nvd.nist.gov/view/vuln/detail?vulnId=#{cve}")
410-
matches = nvd_entry.match(/(\d{2})\/(\d{2})\/(\d{4})\<\/div/)
411-
412-
if matches
413-
date = sprintf("%04d-%02d-%02d", Integer(matches[3]), Integer(matches[1]), Integer(matches[2]))
414-
else
415-
puts "Can't determine date for: #{title}"
416-
date = "#{yaml['cve'][/\d{4}/]}-01-01"
417-
end
418-
end
419-
420-
filename = "#{date}-#{slug}.markdown"
421-
contents = <<-MARKDOWN
422-
---
423-
layout: post
424-
title: "#{title}"
425-
date: #{date}
426-
comments: false
427-
categories: [#{yaml['gem']}#{",#{yaml['framework']}" if yaml['framework']}]
428-
---
429-
430-
### CVE ID
431-
432-
* #{yaml['url'] ? "[#{cve}](#{yaml['url']})" : cve}
433-
434-
### GEM NAME
435-
436-
* #{yaml['gem']}
437-
#{"\n### FRAMEWORK\n\n* #{yaml['framework']}\n" if yaml['framework']}
438-
### PATCHED VERSIONS
439-
440-
#{yaml['patched_versions'].map { |v| "* \`#{v}\`"}.join("\n")}
441-
442-
### DESCRIPTION
443-
444-
#{yaml['description']}
445-
MARKDOWN
446-
447-
File.open("source/_posts/#{filename}", "w") { |file| file << contents }
448-
end
449386
end

tasks/sync_advisories.rake

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#############################
2+
# Rebuild advisory Markdown #
3+
#############################
4+
require 'net/http'
5+
6+
desc "sync with ruby-advisory-db and rebuild Markdown files"
7+
task :sync_advisories do
8+
sh "git submodule update"
9+
10+
Rake::FileList["ruby-advisory-db/gems/**/*.yml"].each do |advisory|
11+
yaml = YAML.load_file(advisory)
12+
13+
cve = "CVE-" + yaml['cve']
14+
title = yaml['title'].gsub(/\s+/m, ' ')
15+
16+
title = "#{cve}: #{title}"
17+
slug = title.downcase.gsub(/[^\w]+/, '-')
18+
19+
puts "Processing: #{title}"
20+
21+
if yaml['url']['osvdb.org']
22+
osvdb_entry = Net::HTTP.get URI(yaml['url'])
23+
date = osvdb_entry[/(\d{4}-\d{2}-\d{2})\<\/td/, 1]
24+
else
25+
nvd_entry = Net::HTTP.get URI("http://web.nvd.nist.gov/view/vuln/detail?vulnId=#{cve}")
26+
matches = nvd_entry.match(/(\d{2})\/(\d{2})\/(\d{4})\<\/div/)
27+
28+
if matches
29+
date = sprintf("%04d-%02d-%02d", Integer(matches[3]), Integer(matches[1]), Integer(matches[2]))
30+
else
31+
puts "Can't determine date for: #{title}"
32+
date = "#{yaml['cve'][/\d{4}/]}-01-01"
33+
end
34+
end
35+
36+
filename = "#{date}-#{slug}.markdown"
37+
contents = <<-MARKDOWN
38+
---
39+
layout: post
40+
title: "#{title}"
41+
date: #{date}
42+
comments: false
43+
categories: [#{yaml['gem']}#{",#{yaml['framework']}" if yaml['framework']}]
44+
---
45+
46+
### CVE ID
47+
48+
* #{yaml['url'] ? "[#{cve}](#{yaml['url']})" : cve}
49+
50+
### GEM NAME
51+
52+
* #{yaml['gem']}
53+
#{"\n### FRAMEWORK\n\n* #{yaml['framework']}\n" if yaml['framework']}
54+
### PATCHED VERSIONS
55+
56+
#{yaml['patched_versions'].map { |v| "* \`#{v}\`"}.join("\n")}
57+
58+
### DESCRIPTION
59+
60+
#{yaml['description']}
61+
MARKDOWN
62+
63+
File.open("source/_posts/#{filename}", "w") { |file| file << contents }
64+
end
65+
end

0 commit comments

Comments
 (0)
0