Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruby auto-tagging #96

Merged
merged 3 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ jobs:
$CONDA/bin/conda build -c conda-forge --no-anaconda-upload --output-folder /tmp/conda-out/ .
env:
ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_TOKEN }}
continue-on-error: true
- name: Release Anaconda
if: startsWith(github.ref, 'refs/tags/')
run: |
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name := "chen"
ThisBuild / organization := "io.appthreat"
ThisBuild / version := "2.3.0"
ThisBuild / version := "2.3.1"
ThisBuild / scalaVersion := "3.6.2"

val cpgVersion = "1.0.1"
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"downloadUrl": "https://github.com/AppThreat/chen",
"issueTracker": "https://github.com/AppThreat/chen/issues",
"name": "chen",
"version": "2.3.0",
"version": "2.3.1",
"description": "Code Hierarchy Exploration Net (chen) is an advanced exploration toolkit for your application source code and its dependency hierarchy.",
"applicationCategory": "code-analysis",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion meta.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% set version = "2.3.0" %}
{% set version = "2.3.1" %}

package:
name: chen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,9 @@ class ConfigFileCreationPass(cpg: Cpg) extends XConfigFileCreationPass(cpg):
// XML files
extensionFilter(".xml"),
// ERB files
extensionFilter(".erb")
extensionFilter(".erb"),
pathEndFilter("bom.json"),
pathEndFilter(".cdx.json"),
pathEndFilter("chennai.json")
)
end ConfigFileCreationPass
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ class CdxPass(atom: Cpg) extends CpgPass(atom):
else
str

private def toRubyModuleForm(str: String) =
if str.nonEmpty then
s".*(::)?${str.split("::").head}(::).*"
else
str

override def run(dstGraph: DiffGraphBuilder): Unit =
atom.configFile.name(BOM_JSON_FILE).content.foreach { cdxData =>
val cdxJson = parse(cdxData).getOrElse(Json.Null)
Expand Down Expand Up @@ -161,14 +167,31 @@ class CdxPass(atom: Cpg) extends CpgPass(atom):
bpkg.replace(File.separator, Pattern.quote(File.separator))
if language == Languages.PYTHON || language == Languages.PYTHONSRC
then bpkg = toPyModuleForm(bpkg)
if language == Languages.RUBYSRC
then bpkg = toRubyModuleForm(bpkg)
if language == Languages.PHP
then
bpkg = bpkg.replaceAll("""\\""", """\\\\""")
bpkg = s"""$bpkg.*"""
if bpkg.nonEmpty && !donePkgs.contains(bpkg) then
donePkgs.put(bpkg, true)
// Ruby
if language == Languages.RUBYSRC
then
atom.call.code(bpkg).argument.newTagNode(
compPurl
).store()(dstGraph)
atom.call.code(bpkg).receiver.isMethod.where(_.fullName(
s"((app|config)${Pattern.quote(File.separator)})?(routes|controller(s)?|model(s)?|application).*\\.rb.*"
)).parameter.newTagNode("framework-input").store()(dstGraph)
atom.call.code(bpkg).receiver.newTagNode(
s"$compType-value"
).store()(dstGraph)
atom.call.code(bpkg).callee(NoResolve).isMethod.parameter.newTagNode(
s"$compType-input"
).store()(dstGraph)
// C/C++
if language == Languages.NEWC || language == Languages.C
else if language == Languages.NEWC || language == Languages.C
then
atom.method.fullNameExact(bpkg).callIn(
NoResolve
Expand Down
266 changes: 133 additions & 133 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "appthreat-chen"
version = "2.3.0"
version = "2.3.1"
description = "Code Hierarchy Exploration Net (chen)"
authors = ["Team AppThreat <[email protected]>"]
license = "Apache-2.0"
Expand Down
Loading