Skip to content

Commit 4965000

Browse files
authored
c and python tagging enhancements (#110)
* Python enhancements Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com> --------- Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
1 parent 85487e2 commit 4965000

File tree

6 files changed

+34
-4
lines changed

6 files changed

+34
-4
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name := "chen"
22
ThisBuild / organization := "io.appthreat"
3-
ThisBuild / version := "2.3.8"
3+
ThisBuild / version := "2.3.9"
44
ThisBuild / scalaVersion := "3.6.2"
55

66
val cpgVersion = "1.0.1"

codemeta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"downloadUrl": "https://github.com/AppThreat/chen",
88
"issueTracker": "https://github.com/AppThreat/chen/issues",
99
"name": "chen",
10-
"version": "2.3.8",
10+
"version": "2.3.9",
1111
"description": "Code Hierarchy Exploration Net (chen) is an advanced exploration toolkit for your application source code and its dependency hierarchy.",
1212
"applicationCategory": "code-analysis",
1313
"keywords": [

meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% set version = "2.3.8" %}
1+
{% set version = "2.3.9" %}
22

33
package:
44
name: chen

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class CdxPass(atom: Cpg) extends CpgPass(atom):
4343
)
4444

4545
private def PY_REQUEST_PATTERNS = Array(".*views.py:<module>.*")
46+
private def PY_RESPONSE_PATTERNS =
47+
Array(".*views.py:.*HttpResponse.*", ".*views.py:.*render.*", ".*views.py:.*get_object_.*")
4648

4749
private def containsRegex(str: String) =
4850
val reChars = "[](){}*+&|?.,\\$"
@@ -94,6 +96,12 @@ class CdxPass(atom: Cpg) extends CpgPass(atom):
9496
dstGraph
9597
)
9698
)
99+
PY_RESPONSE_PATTERNS
100+
.foreach(p =>
101+
atom.method.fullName(p).parameter.newTagNode("framework-output").store()(
102+
dstGraph
103+
)
104+
)
97105
components.foreach { comp =>
98106
val PURL_TYPE = "purl"
99107
val compPurl = comp.hcursor.downField(PURL_TYPE).as[String].getOrElse("")

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@ class EasyTagsPass(atom: Cpg) extends CpgPass(atom):
1414
override def run(dstGraph: DiffGraphBuilder): Unit =
1515
atom.method.internal.name(".*(valid|check).*").newTagNode("validation").store()(dstGraph)
1616
atom.method.internal.name("is[A-Z].*").newTagNode("validation").store()(dstGraph)
17+
atom.method.internal.name("is_[a-z].*").newTagNode("validation").store()(dstGraph)
18+
atom.method.internal.name("has_[a-z].*").newTagNode("validation").store()(dstGraph)
1719
atom.method.internal.name(".*(encode|escape|sanit).*").newTagNode("sanitization").store()(
1820
dstGraph
1921
)
2022
atom.method.internal.name(".*(login|authenti).*").newTagNode("authentication").store()(
2123
dstGraph
2224
)
25+
atom.method.internal.name(".*(has_perm|get_perms).*").newTagNode("authentication").store()(
26+
dstGraph
27+
)
2328
atom.method.internal.name(".*(authori).*").newTagNode("authorization").store()(dstGraph)
2429
if language == Languages.JSSRC || language == Languages.JAVASCRIPT then
2530
// Tag cli source
@@ -65,6 +70,23 @@ class EasyTagsPass(atom: Cpg) extends CpgPass(atom):
6570
then
6671
atom.method.internal.name("main").parameter.newTagNode("cli-source").store()(dstGraph)
6772
atom.method.internal.name("wmain").parameter.newTagNode("cli-source").store()(dstGraph)
73+
atom.method.internal.name(".*(ucm_|ucbuf_|event).*").parameter.newTagNode("event").store()(
74+
dstGraph
75+
)
76+
atom.method.internal.name(".*(ucm_|ucbuf_|event).*").parameter.newTagNode("framework-input")
77+
.store()(
78+
dstGraph
79+
)
80+
// TODO: Find a way to make these generic
81+
Seq("json", "glibc", "regex", "decode", "wasm", "execution", "unicode", "utf8").foreach {
82+
stag =>
83+
atom.method.external.name(s".*${stag}.*").callIn(NoResolve).argument.newTagNode(stag)
84+
.store()(dstGraph)
85+
atom.method.external.name(s".*${stag}.*").callIn(NoResolve).argument.newTagNode(
86+
"library-call"
87+
)
88+
.store()(dstGraph)
89+
}
6890
atom.method.external.name("(cuda|curl_|BIO_).*").parameter.newTagNode(
6991
"library-call"
7092
).store()(

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "appthreat-chen"
3-
version = "2.3.8"
3+
version = "2.3.9"
44
description = "Code Hierarchy Exploration Net (chen)"
55
authors = ["Team AppThreat <cloud@appthreat.com>"]
66
license = "Apache-2.0"

0 commit comments

Comments
 (0)