Skip to content

Commit 0c2dd1a

Browse files
committed
Ruby: Flesh out hash-splat docs
1 parent 43f2713 commit 0c2dd1a

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

ruby/ql/docs/flow_summaries.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,47 @@ Any keyword argument to the call.
100100

101101
#### `hash-splat`
102102
The special "hash splat" argument/parameter, which is written as `**args`.
103+
When used in an `Argument` component, this specifier refers to special dataflow
104+
node which is constructed at the call site, containing any elements in a hash
105+
splat argument (`**args`) along with any explicit keyword arguments (`foo:
106+
bar`). The node behaves like a normal dataflow node for a hash, meaning that you
107+
can access specific elements of it using the `Element` component.
108+
109+
For example, the following flow summary states that values flow from any keyword
110+
arguments (including those in a hash splat) to the return value:
111+
112+
```ql
113+
input = "Argument[hash-splat].Element[any]" and
114+
output = "ReturnValue" and
115+
preservesValue = true
116+
```
117+
118+
Assuming this summary is for a global method `foo`, the following test will pass:
119+
120+
```rb
121+
a = source "a"
122+
b = source "b"
123+
124+
h = {a: a}
125+
126+
x = foo(b: b, **h)
127+
128+
sink x # $ hasValueFlow=a hasValueFlow=b
129+
```
130+
131+
If the method returns the hash itself, you will need to use `WithElement` in
132+
order to preserve taint/value in its elements. For example:
133+
134+
```ql
135+
input = "Argument[hash-splat].WithElement[any]" and
136+
output = "ReturnValue" and
137+
preservesValue = true
138+
```
139+
```rb
140+
a = source "a"
141+
x = foo(a: a)
142+
sink x[:a] # $ hasValueFlow=a
143+
```
103144

104145
## `ReturnValue`
105146
`ReturnValue` refers to the return value of the element identified in the

0 commit comments

Comments
 (0)