Skip to content

XRAY-128408 - Add Sast rules flag to audit command#598

Merged
attiasas merged 1 commit intojfrog:devfrom
iddoh-jfrog:feature/XRAY-128408-sast-rules-flag
Nov 3, 2025
Merged

XRAY-128408 - Add Sast rules flag to audit command#598
attiasas merged 1 commit intojfrog:devfrom
iddoh-jfrog:feature/XRAY-128408-sast-rules-flag

Conversation

@iddoh-jfrog
Copy link
Contributor

@iddoh-jfrog iddoh-jfrog commented Oct 29, 2025

Resolves XRAY-128408

Add Custom rules to the SAST scan

Prepare a custom json rules file with your rules:

[
  {
    "name": "custom-rule",
    "message": "User-controlled data used as argument to math.sqrt",
    "finder": {
      "type": "FlowFinder",
      "sources": {
        "type": "calls",
        "names": [
          "input"
        ]
      },
      "sinks": {
        "type": "calls",
        "names": [
          "math.sqrt"
        ]
      }
    },
    "cwe": null,
    "description": "User-controlled square root",
    "severity": "high",
    "tags": []
  }
]

Run with the flag --add-sast-rules=/path/to/file.json

@github-actions
Copy link

github-actions bot commented Oct 29, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@iddoh-jfrog
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@iddoh-jfrog iddoh-jfrog force-pushed the feature/XRAY-128408-sast-rules-flag branch from daa775d to cca14ae Compare October 29, 2025 13:47
@attiasas attiasas added new feature Automatically generated release notes safe to test Approve running integration tests on a pull request labels Oct 29, 2025
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Oct 29, 2025
Copy link
Collaborator

@attiasas attiasas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice Work! check out my comments.

  1. Add description to the PR (link is not enough since this is open source and not everyone can get the info from the link)
  2. Is the user_rules already implemented and released to the scanner? what is the Minimum version for it?
  3. If needed IYO, add an integration test (with test rule file)

@iddoh-jfrog iddoh-jfrog force-pushed the feature/XRAY-128408-sast-rules-flag branch from cca14ae to ca7150c Compare November 2, 2025 09:57
@iddoh-jfrog iddoh-jfrog force-pushed the feature/XRAY-128408-sast-rules-flag branch from ca7150c to 068deaf Compare November 2, 2025 10:00
@attiasas attiasas added ignore for release Automatically generated release notes and removed new feature Automatically generated release notes labels Nov 2, 2025
Copy link
Collaborator

@attiasas attiasas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@attiasas attiasas added the safe to test Approve running integration tests on a pull request label Nov 2, 2025
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Nov 2, 2025
@github-actions
Copy link

github-actions bot commented Nov 2, 2025

🚨 Frogbot scanned this pull request and found the below:

📗 Scan Summary

  • Frogbot scanned for vulnerabilities and found 2 issues
Scan Category Status Security Issues
Software Composition Analysis ℹ️ Not Scanned -
Contextual Analysis ℹ️ Not Scanned -
Static Application Security Testing (SAST) ✅ Done
2 Issues Found 2 Low
Secrets ✅ Done -
Infrastructure as Code (IaC) ✅ Done Not Found

@github-actions
Copy link

github-actions bot commented Nov 2, 2025

Token

at cli/docs/flags.go (line 319)

🎯 Static Application Security Testing (SAST) Vulnerability

Severity Finding
low
Low
Credentials for restricted resources included directly in source code
Full description

Vulnerability Details

Rule ID: go-hardcoded-credentials

Overview

Hardcoded credentials are usernames, passwords, API keys, or other secrets
embedded directly in source code. This practice, identified by CWE-798, is
highly insecure because it makes it easy for anyone with access to the code to
discover and misuse the credentials. If the code is publicly released, shared,
or leaked, the credentials will be exposed to unauthorized parties.

Vulnerable example

In this example, the database username and password for the frog pond are
hardcoded directly in the source code as string literals. This is a major
security risk, as anyone who can read this file can steal the credentials and
gain unauthorized access to the database.

package main

import (
	"database/sql"
	"fmt"
	"log"

	_ "[github.com/go-sql-driver/mysql](https://github.com/go-sql-driver/mysql)"
)

func main() {
	// VULNERABLE: Hardcoded database credentials for the frog pond.
	frogUser := "pond_admin"
	frogPassword := "LeapFlog123!"
	pondName := "lilypad_db"

	connStr := fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/%s",
		frogUser, frogPassword, pondName)

	lilypadDB, err := sql.Open("mysql", connStr)
	if err != nil {
		log.Fatalf("Error opening database: %v", err)
	}
	defer lilypadDB.Close()

	err = lilypadDB.Ping()
	if err != nil {
		log.Fatalf("Error pinging database: %v", err)
	}
	fmt.Println("Successfully connected to the frog pond.")
}

Remediation

The remediated code retrieves the database credentials from environment
variables instead of hardcoding them. This is a much more secure approach, as
it separates the secrets from the source code. This allows credentials to be
managed securely by deployment systems and rotated without changing the code.

package main

import (
	"database/sql"
	"fmt"
	"log"
	"os"

	_ "[github.com/go-sql-driver/mysql](https://github.com/go-sql-driver/mysql)"
)

func main() {
	// SECURE: Retrieve credentials from environment variables.
	frogUser := os.Getenv("FROG_DB_USER")
	frogPassword := os.Getenv("FROG_DB_PASS")
	pondName := os.Getenv("FROG_DB_NAME")

	if frogUser == "" || frogPassword == "" || pondName == "" {
		log.Fatal("DB credentials are not set in environment variables.")
	}

	connStr := fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/%s",
		frogUser, frogPassword, pondName)

	lilypadDB, err := sql.Open("mysql", connStr)
	if err != nil {
		log.Fatalf("Error opening database: %v", err)
	}
	defer lilypadDB.Close()

	err = lilypadDB.Ping()
	if err != nil {
		log.Fatalf("Error pinging database: %v", err)
	}
	fmt.Println("Successfully connected to the frog pond.")
}
Code Flows
Vulnerable data flow analysis result

↘️ "token" (at cli/docs/flags.go line 148)

↘️ Token (at cli/docs/flags.go line 148)

↘️ Token (at cli/docs/flags.go line 319)




@github-actions
Copy link

github-actions bot commented Nov 2, 2025

password

at cli/docs/flags.go (line 229)

🎯 Static Application Security Testing (SAST) Vulnerability

Severity Finding
low
Low
Credentials for restricted resources included directly in source code
Full description

Vulnerability Details

Rule ID: go-hardcoded-credentials

Overview

Hardcoded credentials are usernames, passwords, API keys, or other secrets
embedded directly in source code. This practice, identified by CWE-798, is
highly insecure because it makes it easy for anyone with access to the code to
discover and misuse the credentials. If the code is publicly released, shared,
or leaked, the credentials will be exposed to unauthorized parties.

Vulnerable example

In this example, the database username and password for the frog pond are
hardcoded directly in the source code as string literals. This is a major
security risk, as anyone who can read this file can steal the credentials and
gain unauthorized access to the database.

package main

import (
	"database/sql"
	"fmt"
	"log"

	_ "[github.com/go-sql-driver/mysql](https://github.com/go-sql-driver/mysql)"
)

func main() {
	// VULNERABLE: Hardcoded database credentials for the frog pond.
	frogUser := "pond_admin"
	frogPassword := "LeapFlog123!"
	pondName := "lilypad_db"

	connStr := fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/%s",
		frogUser, frogPassword, pondName)

	lilypadDB, err := sql.Open("mysql", connStr)
	if err != nil {
		log.Fatalf("Error opening database: %v", err)
	}
	defer lilypadDB.Close()

	err = lilypadDB.Ping()
	if err != nil {
		log.Fatalf("Error pinging database: %v", err)
	}
	fmt.Println("Successfully connected to the frog pond.")
}

Remediation

The remediated code retrieves the database credentials from environment
variables instead of hardcoding them. This is a much more secure approach, as
it separates the secrets from the source code. This allows credentials to be
managed securely by deployment systems and rotated without changing the code.

package main

import (
	"database/sql"
	"fmt"
	"log"
	"os"

	_ "[github.com/go-sql-driver/mysql](https://github.com/go-sql-driver/mysql)"
)

func main() {
	// SECURE: Retrieve credentials from environment variables.
	frogUser := os.Getenv("FROG_DB_USER")
	frogPassword := os.Getenv("FROG_DB_PASS")
	pondName := os.Getenv("FROG_DB_NAME")

	if frogUser == "" || frogPassword == "" || pondName == "" {
		log.Fatal("DB credentials are not set in environment variables.")
	}

	connStr := fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/%s",
		frogUser, frogPassword, pondName)

	lilypadDB, err := sql.Open("mysql", connStr)
	if err != nil {
		log.Fatalf("Error opening database: %v", err)
	}
	defer lilypadDB.Close()

	err = lilypadDB.Ping()
	if err != nil {
		log.Fatalf("Error pinging database: %v", err)
	}
	fmt.Println("Successfully connected to the frog pond.")
}
Code Flows
Vulnerable data flow analysis result

↘️ "password" (at cli/docs/flags.go line 70)

↘️ password (at cli/docs/flags.go line 70)

↘️ password (at cli/docs/flags.go line 229)




@attiasas attiasas added new feature Automatically generated release notes safe to test Approve running integration tests on a pull request and removed ignore for release Automatically generated release notes labels Nov 2, 2025
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Nov 2, 2025
@attiasas attiasas merged commit 76dabd9 into jfrog:dev Nov 3, 2025
134 of 135 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new feature Automatically generated release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants