rails_cve 0.0.1 → 0.0.2
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 +4 -4
- data/README.md +77 -28
- data/app/models/concerns/rails_cve/entry/references.rb +23 -10
- data/app/models/concerns/rails_cve/entry/search.rb +11 -4
- data/lib/rails_cve/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee33e9208ca227aaa6caceead83033303a54fc79
|
4
|
+
data.tar.gz: c3631d55f3581dc8998df794fe81541b08796c26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73903c5d2356ad202bdd45dbdb5c76ab879ee380e8255bd2dca97f97dab7e45c97b099a06a22143b52582fd44459e750745bb030d09717b653428ff2015cc2d4
|
7
|
+
data.tar.gz: 1dd6b542fb355d3a06d3b97051efc1ee9168c02dd7f4bf259719bcb9ea821912d71eb0f109e0fbabf86dcba1d5a9e17eaace7848fce185cdade3865dfdef0354
|
data/README.md
CHANGED
@@ -9,51 +9,82 @@ tasks, notably searching the CVE descriptions:
|
|
9
9
|
```ruby
|
10
10
|
# in `rails console`
|
11
11
|
|
12
|
-
list = RailsCVE::Entry.
|
13
|
-
|
14
|
-
#
|
15
|
-
#
|
12
|
+
list = RailsCVE::Entry.search_plain 'ruby gem'
|
13
|
+
#=> SELECT "rails_cve_entries".*
|
14
|
+
# FROM "rails_cve_entries"
|
15
|
+
# WHERE (to_tsvector('english', description) @@ plainto_tsquery('ruby gem'))
|
16
|
+
# ORDER BY "rails_cve_entries"."id" ASC
|
16
17
|
|
17
18
|
list.count
|
18
|
-
#=>
|
19
|
+
#=> 41
|
19
20
|
|
20
|
-
list.
|
21
|
-
|
22
|
-
# id:
|
23
|
-
# name: "CVE-
|
24
|
-
#
|
21
|
+
list.first
|
22
|
+
#=> #<RailsCVE::Entry
|
23
|
+
# id: 48583,
|
24
|
+
# name: "CVE-2011-0739",
|
25
|
+
# description: "The deliver function in the sendmail delivery agent...",
|
25
26
|
# references: [
|
26
|
-
# "
|
27
|
-
# "
|
28
|
-
# "
|
29
|
-
# "
|
30
|
-
#
|
31
|
-
# "
|
32
|
-
# "
|
27
|
+
# "MISC:https://github.com/mikel/mail/raw/master/patches/20110126_sendmail.patch",
|
28
|
+
# "CONFIRM:http://groups.google.com/group/mail-ruby/browse_thread/thread/e93bbd05706478dd?pli=1",
|
29
|
+
# "BID:46021",
|
30
|
+
# "URL:http://www.securityfocus.com/bid/46021",
|
31
|
+
# "OSVDB:70667",
|
32
|
+
# "URL:http://osvdb.org/70667",
|
33
|
+
# "SECUNIA:43077",
|
34
|
+
# "URL:http://secunia.com/advisories/43077",
|
35
|
+
# "VUPEN:ADV-2011-0233",
|
36
|
+
# "URL:http://www.vupen.com/english/advisories/2011/0233",
|
37
|
+
# "XF:ruby-mail-deliver-command-execution(65010)",
|
38
|
+
# "URL:http://xforce.iss.net/xforce/xfdb/65010"
|
33
39
|
# ]>
|
40
|
+
|
41
|
+
list.first.reference_uris
|
42
|
+
#=> [
|
43
|
+
# "https://github.com/mikel/mail/raw/master/patches/20110126_sendmail.patch",
|
44
|
+
# "http://groups.google.com/group/mail-ruby/browse_thread/thread/e93bbd05706478dd?pli=1",
|
45
|
+
# "http://www.securityfocus.com/bid/46021",
|
46
|
+
# "http://osvdb.org/70667",
|
47
|
+
# "http://secunia.com/advisories/43077",
|
48
|
+
# "http://www.vupen.com/english/advisories/2011/0233",
|
49
|
+
# "http://xforce.iss.net/xforce/xfdb/65010"
|
50
|
+
# ]
|
34
51
|
```
|
35
52
|
|
36
53
|
## Full text search capabilities
|
37
54
|
|
38
|
-
As you can see in the example above, we take advantage of PostgreSQL's text
|
39
|
-
search features. Hence, you will need to migrate to PostgreSQL unless you
|
40
|
-
haven't already.
|
41
55
|
|
42
|
-
|
43
|
-
|
56
|
+
There exist two distinct search queries, which both are using Postgres'
|
57
|
+
advanced [text search capabilities][2]:
|
58
|
+
|
59
|
+
- `RailsCVE::Entry.search_plain(str)` and
|
60
|
+
- `RailsCVE::Entry.search_ranked(str)`
|
61
|
+
|
62
|
+
While `#search_plain` does not predefine an order on the result set (except
|
63
|
+
from ActiveRecord's default order), `#search_ranked` calculates a matching
|
64
|
+
rank and uses this as sort criteria.
|
65
|
+
|
66
|
+
Keep in mind that creating a ranked search result requires a little more
|
67
|
+
processing time and restricts the ActiveRecord query chaining possibilities:
|
44
68
|
|
45
69
|
```ruby
|
46
|
-
#
|
47
|
-
|
48
|
-
```
|
70
|
+
# possible, does not reorder the query:
|
71
|
+
RailsCVE::Entry.search_ranked('ruby rails').first
|
49
72
|
|
50
|
-
|
51
|
-
|
73
|
+
# not possible, tries but fails to reorder by ascending rank:
|
74
|
+
RailsCVE::Entry.search_ranked('ruby rails').last
|
52
75
|
|
76
|
+
# not possible:
|
77
|
+
RailsCVE::Entry.search_ranked('ruby rails').search_ranked('windows')
|
78
|
+
|
79
|
+
# use this instead:
|
80
|
+
RailsCVE::Entry.search_ranked('ruby rails & windows')
|
81
|
+
```
|
53
82
|
|
54
83
|
## Installation
|
55
84
|
|
56
|
-
|
85
|
+
**This engine requires a PostgreSQL database!**
|
86
|
+
|
87
|
+
Add `rails-cve` to your Gemfile and run `bundle install`:
|
57
88
|
|
58
89
|
```ruby
|
59
90
|
gem 'rails-cve'
|
@@ -72,6 +103,24 @@ writing):
|
|
72
103
|
rake rails_cve:seed
|
73
104
|
```
|
74
105
|
|
106
|
+
Repeat the last step if you'd like to rebuild the entire CVE database.
|
107
|
+
|
108
|
+
|
109
|
+
## Schema format
|
110
|
+
|
111
|
+
As you can see in the example above, we take advantage of PostgreSQL's text
|
112
|
+
search features. Hence, you will need to migrate to PostgreSQL unless you
|
113
|
+
haven't already.
|
114
|
+
|
115
|
+
I should mention, that it is **strongly recommended** to change your schema
|
116
|
+
format from Ruby to SQL, like so:
|
117
|
+
|
118
|
+
```ruby
|
119
|
+
# in config/application.rb
|
120
|
+
config.active_record.schema_format = :sql
|
121
|
+
```
|
122
|
+
|
123
|
+
|
75
124
|
## Maintenance
|
76
125
|
|
77
126
|
You should (at least daily) import the updates. RailsCVE currently uses the
|
@@ -1,22 +1,35 @@
|
|
1
1
|
module RailsCVE::Entry::References
|
2
2
|
extend ActiveSupport::Concern
|
3
3
|
|
4
|
+
REF_DELIMITER = ' | '
|
5
|
+
REF_URI_RE = begin
|
6
|
+
prefix = /(?:ASCEND|CISCO|CONFIRM|MISC|REDHAT|URL|XF)/
|
7
|
+
scheme = /(?:https?|ftp|mailto)/
|
8
|
+
rest = /.*/
|
9
|
+
structure = /\A#{prefix}:(?<uri>#{scheme}:#{rest})\z/
|
10
|
+
end
|
11
|
+
|
4
12
|
def reference_uris
|
5
13
|
return [] unless references?
|
6
|
-
references.
|
14
|
+
@reference_uris = references.inject([]) do |refs, r|
|
15
|
+
REF_URI_RE.match(r){|m| refs << m[:uri] }
|
16
|
+
refs
|
17
|
+
end
|
7
18
|
end
|
8
19
|
|
9
20
|
def references=(refs)
|
10
|
-
|
11
|
-
|
12
|
-
references_will_change!
|
13
|
-
super refs.flatten
|
14
|
-
when String
|
15
|
-
references_will_change!
|
16
|
-
super refs.split(' | ')
|
17
|
-
else
|
18
|
-
raise ArgumentError, 'invalid type'
|
21
|
+
unless Array === refs || String === refs
|
22
|
+
raise ArgumentError, 'invalid type'
|
19
23
|
end
|
24
|
+
|
25
|
+
_refs = if Array === refs
|
26
|
+
refs.flatten
|
27
|
+
elsif String === refs
|
28
|
+
refs.split REF_DELIMITER
|
29
|
+
end
|
30
|
+
|
31
|
+
references_will_change!
|
32
|
+
super _refs.map(&:to_s).map(&:strip)
|
20
33
|
end
|
21
34
|
|
22
35
|
end
|
@@ -1,14 +1,21 @@
|
|
1
1
|
module RailsCVE::Entry::Search
|
2
2
|
extend ActiveSupport::Concern
|
3
3
|
|
4
|
+
TS_QUERY = "to_tsvector('english', description) @@ plainto_tsquery(%{q})"
|
5
|
+
TS_RANK = "ts_rank(to_tsvector(description), plainto_tsquery(%{q}))"
|
6
|
+
|
4
7
|
included do
|
5
|
-
scope :
|
8
|
+
scope :search_ranked, ->(query){
|
6
9
|
q = sanitize(query)
|
10
|
+
rank = "#{TS_RANK} AS rank" % { q: q }
|
7
11
|
|
8
|
-
|
9
|
-
|
12
|
+
select("*, #{rank}")
|
13
|
+
.search_plain(query)
|
14
|
+
.order("rank DESC")
|
15
|
+
}
|
10
16
|
|
11
|
-
|
17
|
+
scope :search_plain, ->(query){
|
18
|
+
where(TS_QUERY % { q: sanitize(query) })
|
12
19
|
}
|
13
20
|
end
|
14
21
|
end
|
data/lib/rails_cve/version.rb
CHANGED