Skip to content

Commit ef53138

Browse files
committed
Tag sinatra routes
Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
1 parent 6d19cd0 commit ef53138

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

platform/frontends/x2cpg/src/main/scala/io/appthreat/x2cpg/passes/taggers/ChennaiTagsPass.scala

+27-1
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,42 @@ class ChennaiTagsPass(atom: Cpg) extends CpgPass(atom):
120120
}
121121
end tagPhpRoutes
122122
private def tagRubyRoutes(dstGraph: DiffGraphBuilder): Unit =
123+
// rails
124+
val railsRoutePrefix = ".*(get|post|put|delete|head|option|resources|namespace)\\s('|\").*"
123125
atom.method.where(
124126
_.filename("config/routes.rb").code(
125-
".*(get|post|put|delete|head|option|resources|namespace).*"
127+
railsRoutePrefix
126128
)
127129
).newTagNode(
128130
FRAMEWORK_ROUTE
129131
).store()(dstGraph)
132+
atom.method.where(
133+
_.filename("config/routes.rb").code(
134+
railsRoutePrefix
135+
)
136+
).parameter.newTagNode(FRAMEWORK_INPUT).store()(
137+
dstGraph
138+
)
130139
atom.method.filename(".*controller.rb.*").parameter.newTagNode(FRAMEWORK_INPUT).store()(
131140
dstGraph
132141
)
142+
atom.method.filename(".*controller.rb.*").methodReturn.newTagNode(
143+
FRAMEWORK_OUTPUT
144+
).store()(dstGraph)
145+
// sinatra
146+
val sinatraRoutePrefix =
147+
"(app\\.namespace|app\\.)?(get|post|delete|head|options|put)\\s('|\").*"
148+
atom.method.code(sinatraRoutePrefix).newTagNode(
149+
FRAMEWORK_ROUTE
150+
).store()(dstGraph)
151+
atom.method.code(sinatraRoutePrefix).parameter
152+
.newTagNode(FRAMEWORK_INPUT).store()(
153+
dstGraph
154+
)
155+
atom.method.code(sinatraRoutePrefix).methodReturn.newTagNode(
156+
FRAMEWORK_OUTPUT
157+
).store()(dstGraph)
158+
end tagRubyRoutes
133159
override def run(dstGraph: DiffGraphBuilder): Unit =
134160
if language == Languages.PYTHON || language == Languages.PYTHONSRC then
135161
tagPythonRoutes(dstGraph)

0 commit comments

Comments
 (0)