Skip to content

Commit 2757b0b

Browse files
committed
Change example to net/http Request::FormValue
1 parent 1e1bbe9 commit 2757b0b

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

docs/codeql/codeql-language-guides/customizing-library-models-for-go.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,15 @@ The remaining values are used to define the ``access path``, the ``kind``, and t
107107
- The eighth value ``sql-injection`` is the kind of the sink. The sink kind is used to define the queries where the sink is in scope. In this case - the SQL injection queries.
108108
- The ninth value ``manual`` is the provenance of the sink, which is used to identify the origin of the sink.
109109

110-
Example: Taint source from the ``net`` package
111-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
112-
This example shows how the Go query pack models the return value from the ``Listen`` method as a ``remote`` source.
113-
This is the ``Listen`` function which is located in the ``net`` package.
110+
Example: Taint source from the ``net/http`` package
111+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
112+
This example shows how the Go query pack models the return value from the ``FormValue`` method as a ``remote`` source.
113+
This is the ``FormValue`` method of the ``Request`` struct which is located in the ``net/http`` package.
114114

115115
.. code-block:: go
116116
117-
func Tainted() {
118-
ln, err := net.Listen("tcp", ":8080") // The return value of this method is a remote source.
117+
func Tainted(r *http.Request) {
118+
name := r.FormValue("name") // The return value of this method is a source of tainted data.
119119
...
120120
}
121121
@@ -129,16 +129,16 @@ We need to add a tuple to the ``sourceModel``\(package, type, subtypes, name, si
129129
pack: codeql/go-all
130130
extensible: sourceModel
131131
data:
132-
- ["net", "", False, "Listen", "", "", "ReturnValue", "remote", "manual"]
132+
- ["net/http", "Request", True, "FormValue", "", "", "ReturnValue", "remote", "manual"]
133133
134134
135135
Since we are adding a new source, we need to add a tuple to the ``sourceModel`` extensible predicate.
136136
The first five values identify the function to be modeled as a source.
137137

138-
- The first value ``net`` is the package name.
139-
- The second value ``""`` is left blank, since the function is not a method of a type.
140-
- The third value ``False`` is a flag that indicates whether or not the source also applies to all overrides of the method.
141-
- The fourth value ``Listen`` is the function name.
138+
- The first value ``net/http`` is the package name.
139+
- The second value ``Request`` is the type name, since the function is a method of the ``Request`` type.
140+
- The third value ``True`` is a flag that indicates whether or not the source also applies to all overrides of the method.
141+
- The fourth value ``FormValue`` is the function name.
142142
- The fifth value ``""`` is the function input type signature. For Go it should always be an empty string. It is needed for other languages where multiple functions or methods may have the same name and they need to be distinguished by the number and types of the arguments.
143143

144144
The sixth value should be left empty and is out of scope for this documentation.

0 commit comments

Comments
 (0)