Skip to content

Commit b66ea6e

Browse files
committed
Ruby: Simplify ActionMailbox modeling
1 parent 71f2d8f commit b66ea6e

File tree

3 files changed

+19
-31
lines changed

3 files changed

+19
-31
lines changed

ruby/ql/lib/codeql/ruby/frameworks/ActionMailbox.qll

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ module ActionMailbox {
3030
* `ActionMailbox::Base#mail`, which is equivalent. The returned object
3131
* contains data from the incoming email.
3232
*/
33-
class MailCall extends DataFlow::CallNode, Mail::Message::Range {
34-
MailCall() {
33+
class Mail extends DataFlow::CallNode {
34+
Mail() {
3535
this =
3636
[
3737
controller().getAnInstanceSelf().getAMethodCall("inbound_email").getAMethodCall("mail"),
@@ -41,34 +41,21 @@ module ActionMailbox {
4141
}
4242

4343
/**
44-
* Models classes from the `mail` library.
45-
* Version: 2.7.1.
44+
* A method call on a `Mail::Message` object which may return data from a remote source.
4645
*/
47-
module Mail {
48-
/**
49-
* An instance of `Mail::Message`.
50-
*/
51-
class Message extends DataFlow::Node instanceof Message::Range { }
52-
53-
module Message {
54-
abstract class Range extends DataFlow::Node { }
46+
private class RemoteContent extends DataFlow::CallNode, RemoteFlowSource::Range {
47+
RemoteContent() {
48+
this =
49+
any(Mail m)
50+
.(DataFlow::LocalSourceNode)
51+
.getAMethodCall([
52+
"body", "to", "from", "raw_source", "subject", "from_address",
53+
"recipients_addresses", "cc_addresses", "bcc_addresses", "in_reply_to",
54+
"references", "reply_to", "raw_envelope", "to_s", "encoded", "header", "bcc", "cc",
55+
"text_part", "html_part"
56+
])
5557
}
5658

57-
/**
58-
* A method call on a `Mail::Message` object which may return data from a remote source.
59-
*/
60-
class RemoteContent extends DataFlow::CallNode, RemoteFlowSource::Range {
61-
RemoteContent() {
62-
this.getReceiver() instanceof Message and
63-
this.getMethodName() =
64-
[
65-
"body", "to", "from", "raw_source", "subject", "from_address", "recipients_addresses",
66-
"cc_addresses", "bcc_addresses", "in_reply_to", "references", "reply_to",
67-
"raw_envelope", "to_s", "encoded", "header", "bcc", "cc", "text_part", "html_part"
68-
]
69-
}
70-
71-
override string getSourceType() { result = "ActionMailbox" }
72-
}
59+
override string getSourceType() { result = "ActionMailbox" }
7360
}
7461
}

ruby/ql/test/library-tests/frameworks/action_mailbox/ActionMailbox.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ messageInstances
77
| action_mailbox.rb:6:5:6:10 | call to mail |
88
| action_mailbox.rb:10:5:10:8 | call to mail |
99
| action_mailbox.rb:16:9:16:12 | call to mail |
10-
remoteContent
10+
remoteFlowSources
1111
| action_mailbox.rb:3:5:3:13 | call to body |
1212
| action_mailbox.rb:4:5:4:11 | call to to |
1313
| action_mailbox.rb:6:5:6:13 | call to to |
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
private import codeql.ruby.frameworks.ActionMailbox
22
private import codeql.ruby.DataFlow
3+
private import codeql.ruby.dataflow.RemoteFlowSources
34

45
query predicate processMethods(ActionMailbox::Process p) { any() }
56

6-
query predicate messageInstances(ActionMailbox::Mail::Message c) { any() }
7+
query predicate messageInstances(ActionMailbox::Mail c) { any() }
78

8-
query predicate remoteContent(ActionMailbox::Mail::RemoteContent r) { any() }
9+
query predicate remoteFlowSources(RemoteFlowSource r) { any() }

0 commit comments

Comments
 (0)