2022-08-27 11:52:29 +05:30
---
stage: Secure
group: Static Analysis
2022-11-25 23:54:43 +05:30
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments
2022-08-27 11:52:29 +05:30
---
# Customize rulesets **(ULTIMATE)**
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/235382) in GitLab 13.5.
> - [Added](https://gitlab.com/gitlab-org/gitlab/-/issues/339614) support for
> passthrough chains. Expanded to include additional passthrough types of `file`, `git`, and `url` in GitLab 14.6.
> - [Added](https://gitlab.com/gitlab-org/gitlab/-/issues/235359) support for overriding rules in GitLab 14.8.
2023-03-04 22:38:38 +05:30
You can customize the behavior of our SAST analyzers by [defining a ruleset configuration file ](#create-the-configuration-file ) in the
repository being scanned. There are two kinds of customization:
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
- Modifying the behavior of **predefined rules** . This includes:
- [Disabling predefined rules ](#disable-predefined-rules ). Available for all analyzers.
- [Overriding predefined rules ](#override-predefined-rules ). Available for all analyzers.
- Replacing predefined rules by [synthesizing a custom configuration ](#synthesize-a-custom-configuration )
using **passthroughs** . Available for only [nodejs-scan ](https://gitlab.com/gitlab-org/security-products/analyzers/nodejs-scan )
and [semgrep ](https://gitlab.com/gitlab-org/security-products/analyzers/semgrep ).
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
## Disable predefined rules
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
You can disable predefined rules for any SAST analyzer. Disabled rules won't appear
on the [Pipeline Security ](../index.md#view-security-scan-information-in-the-pipeline-security-tab )
tab or the [Vulnerability Report ](../index.md#view-security-scan-information-in-the-vulnerability-report ).
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
Disabling rules has a retroactive effect. The analyzer continues to scan for the
vulnerability, but findings are omitted from the [`gl-sast-report.json` artifact ](index.md#reports-json-format ).
See the [Schema ](#schema ) and [Examples ](#examples ) sections for information on how
to configure this behavior.
## Override predefined rules
Certain attributes of predefined rules can be overridden for any SAST analyzer. This
can be useful when adapting SAST to your existing workflow or tools. For example, you
might want to override the severity of a vulnerability based on organizational policy,
or choose a different message to display in the Vulnerability Report.
See the [Schema ](#schema ) and [Examples ](#examples ) sections for information on how
to configure this behavior.
## Synthesize a custom configuration
You can completely replace the predefined rules of some SAST analyzers:
- [nodejs-scan ](https://gitlab.com/gitlab-org/security-products/analyzers/nodejs-scan ) - you
can replace the default [njsscan configuration file ](https://github.com/ajinabraham/njsscan#configure-njsscan )
with your own.
- [semgrep ](https://gitlab.com/gitlab-org/security-products/analyzers/semgrep ) - you can replace
the [GitLab-maintained ruleset ](https://gitlab.com/gitlab-org/security-products/analyzers/semgrep/-/tree/main/rules )
with your own.
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
You provide your customizations via passthroughs, which are composed into a
passthrough chain at runtime and evaluated to produce a complete configuration. The
underlying scanner is then executed against this new configuration.
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
There are multiple passthrough types that let you provide configuration in different
ways, such as using a file committed to your repository or inline in the ruleset
configuration file. You can also choose how subsequent passthroughs in the chain are
handled; they can overwrite or append to previous configuration.
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
See the [Schema ](#schema ) and [Examples ](#examples ) sections for information on how
to configure this behavior.
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
## Create the configuration file
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
To create the ruleset configuration file:
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
1. Create a `.gitlab` directory at the root of your project, if one doesn't already exist.
1. Create a file named `sast-ruleset.toml` in the `.gitlab` directory.
## Schema
### The top-level section
The top-level section contains one or more _configuration sections_ , defined as [TOML tables ](https://toml.io/en/v1.0.0#table ).
| Setting | Description |
| --------| ----------- |
| `[$analyzer]` | Declares a configuration section for an analyzer. The name follows the snake-case names defined in the list of [SAST analyzers ](analyzers.md#sast-analyzers ). |
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
Configuration example:
2022-08-27 11:52:29 +05:30
```toml
2023-03-04 22:38:38 +05:30
[semgrep]
...
```
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
Avoid creating configuration sections that modify existing rules _and_ synthesize a custom ruleset, as
the latter replaces predefined rules completely.
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
### The `[$analyzer]` configuration section
The `[$analyzer]` section lets you customize the behavior of an analyzer. Valid properties
differ based on the kind of configuration you're making.
| Setting | Applies to | Description |
| --------| -------------- | ----------- |
| `[[$analyzer.ruleset]]` | Predefined rules | Defines modifications to an existing rule. |
| `interpolate` | All | If set to `true` , you can use `$VAR` in the configuration to evaluate environment variables. Use this feature with caution, so you don't leak secrets or tokens. (Default: `false` ) |
| `description` | Passthroughs | Description of the custom ruleset. |
| `targetdir` | Passthroughs | The directory where the final configuration should be persisted. If empty, a directory with a random name is created. The directory can contain up to 100MB of files. |
| `validate` | Passthroughs | If set to `true` , the content of each passthrough is validated. The validation works for `yaml` , `xml` , `json` and `toml` content. The proper validator is identified based on the extension used in the `target` parameter of the `[[$analyzer.passthrough]]` section. (Default: `false` ) |
| `timeout` | Passthroughs | The maximum time to spend to evaluate the passthrough chain, before timing out. The timeout cannot exceed 300 seconds. (Default: 60) |
#### `interpolate`
WARNING:
To reduce the risk of leaking secrets, use this feature with caution.
The example below shows a configuration that uses the `$GITURL` environment variable to access a
private repository. The variable contains a username and token (for example `https://user:token@url` ), so
they're not explicitly stored in the configuration file.
```toml
[semgrep]
description = "My private Semgrep ruleset"
interpolate = true
[[semgrep.passthrough]]
type = "git"
value = "$GITURL"
ref = "refs/heads/main"
2022-08-27 11:52:29 +05:30
```
2023-03-04 22:38:38 +05:30
### The `[[$analyzer.ruleset]]` section
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
The `[[$analyzer.ruleset]]` section targets and modifies a single predefined rule. You can define
one to many of these sections per analyzer.
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
| Setting | Description |
| --------| ----------- |
| `disable` | Whether the rule should be disabled. (Default: `false` ) |
| `[$analyzer.ruleset.identifier]` | Selects the predefined rule to be modified. |
| `[$analyzer.ruleset.override]` | Defines the overrides for the rule. |
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
Configuration example:
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
```toml
[semgrep]
[[semgrep.ruleset]]
disable = true
...
```
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
### The `[$analyzer.ruleset.identifier]` section
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
The `[$analyzer.ruleset.identifier]` section defines the identifiers of the predefined
rule that you wish to modify.
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
| Setting | Description |
| --------| ----------- |
| `type` | The type of identifier used by the predefined rule. |
| `value` | The value of the identifier used by the predefined rule. |
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
You can look up the correct values for `type` and `value` by viewing the
[`gl-sast-report.json` ](index.md#reports-json-format ) produced by the analyzer.
You can download this file as a job artifact from the analyzer's CI job.
For example, the snippet below shows a finding from a `semgrep` rule with three
identifiers. The `type` and `value` keys in the JSON object correspond to the
values you should provide in this section.
2022-08-27 11:52:29 +05:30
```json
2023-03-04 22:38:38 +05:30
...
"vulnerabilities": [
{
"id": "7331a4b7093875f6eb9f6eb1755b30cc792e9fb3a08c9ce673fb0d2207d7c9c9",
"category": "sast",
"message": "Key Exchange without Entity Authentication",
"description": "Audit the use of ssh.InsecureIgnoreHostKey\n",
...
"identifiers": [
2022-08-27 11:52:29 +05:30
{
2023-03-04 22:38:38 +05:30
"type": "semgrep_id",
"name": "gosec.G106-1",
"value": "gosec.G106-1"
2022-08-27 11:52:29 +05:30
},
{
2023-03-04 22:38:38 +05:30
"type": "cwe",
"name": "CWE-322",
"value": "322",
"url": "https://cwe.mitre.org/data/definitions/322.html"
},
{
"type": "gosec_rule_id",
"name": "Gosec Rule ID G106",
"value": "G106"
2022-08-27 11:52:29 +05:30
}
]
2023-03-04 22:38:38 +05:30
}
...
]
...
2022-08-27 11:52:29 +05:30
```
2023-03-04 22:38:38 +05:30
Configuration example:
2022-08-27 11:52:29 +05:30
```toml
2023-03-04 22:38:38 +05:30
[semgrep]
[[semgrep.ruleset]]
[semgrep.ruleset.identifier]
type = "semgrep_id"
value = "gosec.G106-1
...
```
### The `[$analyzer.ruleset.override]` section
The `[$analyzer.ruleset.override]` section allows you to override attributes of a predefined rule.
| Setting | Description |
| --------| ----------- |
| `description` | A detailed description of the issue. |
| `message` | (Deprecated) A description of the issue. |
| `name` | The name of the rule. |
| `severity` | The severity of the rule. Valid options are: `Critical` , `High` , `Medium` , `Low` , `Unknown` , `Info` ) |
NOTE:
While `message` is populated by the analyzers, it has been [deprecated ](https://gitlab.com/gitlab-org/security-products/analyzers/report/-/blob/1d86d5f2e61dc38c775fb0490ee27a45eee4b8b3/vulnerability.go#L22 )
in favor of `name` and `description` .
Configuration example:
```toml
[semgrep]
[[semgrep.ruleset]]
[semgrep.ruleset.override]
2022-08-27 11:52:29 +05:30
severity = "Critical"
2023-03-04 22:38:38 +05:30
name = "Command injection"
...
2022-08-27 11:52:29 +05:30
```
2023-03-04 22:38:38 +05:30
### The `[[$analyzer.passthrough]]` section
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
NOTE:
This is currently supported by the `nodejs-scan` and `semgrep` analyzers only.
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
The `[[$analyzer.passthrough]]` section allows you to synthesize a custom configuration for an analyzer. You
can define up to 20 of these sections per analyzer. Passthroughs are composed into a _passthrough chain_
that evaluates into a complete configuration that replaces the predefined rules of the analyzer.
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
Passthroughs are evaluated in order. Passthroughs listed later in the chain have
a higher precedence and can overwrite or append to data yielded by previous
passthroughs (depending on the `mode` ). This is useful for cases where you need
to use or modify an existing configuration.
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
The amount of data generated by a single passthrough is limited to 1MB.
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
| Setting | Applies to | Description |
| ------- | ---------- | ----------- |
| `type` | All | One of `file` , `raw` , `git` or `url` . |
| `target` | All | The target file to contain the data written by the passthrough evaluation. If empty, a random filename is used. |
| `mode` | All | If `overwrite` , the `target` file is overwritten. If `append` , new content is appended to the `target` file. Note that the `git` type only supports `overwrite` . (Default: `overwrite` ) |
| `ref` | `type = "git"` | Contains the name of the branch or the SHA to pull. When using a branch name, specify it in the form `refs/heads/<branch>` , not `refs/remotes/<remote_name>/<branch>` . |
| `subdir` | `type = "git"` | Used to select a subdirectory of the Git repository as the configuration source. |
| `value` | All | For the `file` , `url` , and `git` types, defines the location of the file or Git repository. For the `raw` type, contains the inline configuration. |
| `validator` | All | Used to explicitly invoke validators (`xml`, `yaml` , `json` , `toml` ) on the target file after the evaluation of a passthrough. |
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
#### Passthrough types
2022-08-27 11:52:29 +05:30
| Type | Description |
2023-03-04 22:38:38 +05:30
| ------ | ----------- |
| `file` | Use a file that is present in the Git repository. |
2022-08-27 11:52:29 +05:30
| `raw` | Provide the configuration inline. |
| `git` | Pull the configuration from a remote Git repository. |
2023-03-04 22:38:38 +05:30
| `url` | Fetch the configuration using HTTP. |
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
WARNING:
When using the `raw` passthrough with a YAML snippet, it's recommended to format all indentation
in the `sast-ruleset.toml` file as spaces. The YAML specification mandates spaces over tabs, and the
analyzer will fail to parse your custom ruleset unless the indentation is represented accordingly.
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
## Examples
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
### Disable predefined rules of SAST analyzers
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
With the following custom ruleset configuration, the following rules are omitted from the report:
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
- `semgrep` rules with a `semgrep_id` of `gosec.G106-1` or a `cwe` of `322` .
- `sobelow` rules with a `sobelow_rule_id` of `sql_injection` .
- `flawfinder` rules with a `flawfinder_func_name` of `memcpy` .
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
```toml
[semgrep]
[[semgrep.ruleset]]
disable = true
[semgrep.ruleset.identifier]
type = "semgrep_id"
value = "gosec.G106-1"
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
[[semgrep.ruleset]]
disable = true
[semgrep.ruleset.identifier]
type = "cwe"
value = "322"
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
[sobelow]
[[sobelow.ruleset]]
disable = true
[sobelow.ruleset.identifier]
type = "sobelow_rule_id"
value = "sql_injection"
[flawfinder]
[[flawfinder.ruleset]]
disable = true
[flawfinder.ruleset.identifier]
type = "flawfinder_func_name"
value = "memcpy"
```
### Override predefined rules of SAST analyzers
With the following custom ruleset configuration, vulnerabilities found with
`semgrep` with a type `CWE` and a value `322` will have their severity
overridden to `Critical` .
```toml
[semgrep]
[[semgrep.ruleset]]
[semgrep.ruleset.identifier]
type = "CWE"
value = "322"
[semgrep.ruleset.override]
severity = "Critical"
```
### Synthesize a custom configuration using a raw passthrough for `nodejs-scan`
With the following custom ruleset configuration, the predefined behavior
of the `nodejs-scan` analyzer is replaced with a custom configuration.
The syntax used for the `value` follows the [njsscan config format ](https://github.com/ajinabraham/njsscan#configure-njsscan ).
2022-08-27 11:52:29 +05:30
```toml
[nodejs-scan]
2023-03-04 22:38:38 +05:30
description = "My custom ruleset for nodejs-scan"
2022-08-27 11:52:29 +05:30
[[nodejs-scan.passthrough]]
type = "raw"
value = '''
2023-03-04 22:38:38 +05:30
---
2022-08-27 11:52:29 +05:30
- nodejs-extensions:
- .js
2023-03-04 22:38:38 +05:30
2022-08-27 11:52:29 +05:30
template-extensions:
- .new
- .hbs
- ''
2023-03-04 22:38:38 +05:30
2022-08-27 11:52:29 +05:30
ignore-filenames:
2023-03-04 22:38:38 +05:30
- skip.js
2022-08-27 11:52:29 +05:30
ignore-paths:
- __MACOSX
- skip_dir
- node_modules
2023-03-04 22:38:38 +05:30
2022-08-27 11:52:29 +05:30
ignore-extensions:
- .hbs
2023-03-04 22:38:38 +05:30
2022-08-27 11:52:29 +05:30
ignore-rules:
- regex_injection_dos
- pug_jade_template
- express_xss
'''
```
2023-03-04 22:38:38 +05:30
### Synthesize a custom configuration using a file passthrough for `semgrep`
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
With the following custom ruleset configuration, the predefined ruleset
of the `semgrep` analyzer is replaced with a custom ruleset contained in
a file called `my-semgrep-rules.yaml` in the repository being scanned.
```yaml
# my-semgrep-rules.yml
---
rules:
- id: my-custom-rule
pattern: print("Hello World")
message: |
Unauthorized use of Hello World.
2023-03-17 16:20:25 +05:30
severity: ERROR
2023-03-04 22:38:38 +05:30
languages:
- python
```
2022-08-27 11:52:29 +05:30
```toml
2023-03-04 22:38:38 +05:30
[semgrep]
description = "My custom ruleset for Semgrep"
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
[[semgrep.passthrough]]
2022-08-27 11:52:29 +05:30
type = "file"
2023-03-04 22:38:38 +05:30
value = "my-semgrep-rules.yml"
2022-08-27 11:52:29 +05:30
```
2023-03-04 22:38:38 +05:30
### Synthesize a custom configuration using a passthrough chain for `semgrep`
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
With the following custom ruleset configuration, the predefined ruleset
of the `semgrep` analyzer is replaced with a custom ruleset produced by
evaluating a chain of four passthroughs. Each passthrough produces a file
that's written to the `/sgrules` directory within the container. A
`timeout` of 60 seconds is set in case any Git remotes are unresponsive.
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
Different passthrough types are demonstrated in this example:
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
- Two `git` passthroughs, the first pulling `refs/heads/test` from the
`myrules` Git repository, and the second pulling revision `97f7686`
from the `sast-rules` repository, and considering only files in the
`go` subdirectory.
2022-08-27 11:52:29 +05:30
- The `sast-rules` entry has a higher precedence because it appears later in
the configuration.
2023-03-04 22:38:38 +05:30
- If there's a filename collision between the two checkouts, files
from the `sast-rules` repository will overwrite files from the
`myrules` repository.
- A `raw` passthrough, which writes its `value` to `/sgrules/insecure.yml` .
- A `url` passthrough, which fetches a configuration hosted at a URL and
writes it to `/sgrules/gosec.yml` .
2022-08-27 11:52:29 +05:30
Afterwards, Semgrep is invoked with the final configuration located under
`/sgrules` .
```toml
[semgrep]
2023-03-04 22:38:38 +05:30
description = "My custom ruleset for Semgrep"
2022-08-27 11:52:29 +05:30
targetdir = "/sgrules"
timeout = 60
[[semgrep.passthrough]]
type = "git"
value = "https://gitlab.com/user/myrules.git"
2022-11-25 23:54:43 +05:30
ref = "refs/heads/test"
2022-08-27 11:52:29 +05:30
[[semgrep.passthrough]]
type = "git"
value = "https://gitlab.com/gitlab-org/secure/gsoc-sast-vulnerability-rules/playground/sast-rules.git"
ref = "97f7686db058e2141c0806a477c1e04835c4f395"
subdir = "go"
[[semgrep.passthrough]]
type = "raw"
target = "insecure.yml"
value = """
rules:
- id: "insecure"
patterns:
2023-03-04 22:38:38 +05:30
- pattern: "func insecure() {...}"
2022-08-27 11:52:29 +05:30
message: |
Insecure function insecure detected
metadata:
cwe: "CWE-200: Exposure of Sensitive Information to an Unauthorized Actor"
severity: "ERROR"
languages:
2023-03-04 22:38:38 +05:30
- "go"
"""
2022-08-27 11:52:29 +05:30
[[semgrep.passthrough]]
type = "url"
value = "https://semgrep.dev/c/p/gosec"
target = "gosec.yml"
```
2023-03-04 22:38:38 +05:30
### Configure the mode for passthroughs in a chain
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
You can choose how to handle filename conflicts that occur between
passthroughs in a chain. The default behavior is to overwrite
existing files with the same name, but you can choose `mode = append`
instead to append the content of later files onto earlier ones.
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
You can use the `append` mode for the `file` , `url` , and `raw`
passthrough types only.
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
With the following custom ruleset configuration, two `raw` passthroughs
are used to iteratively assemble the `/sgrules/my-rules.yml` file, which
is then provided to Semgrep as the ruleset. Each passthrough appends a
single rule to the ruleset. The first passthrough is responsible for
initialising the top-level `rules` object, according to the
[Semgrep rule syntax ](https://semgrep.dev/docs/writing-rules/rule-syntax/ ).
2022-08-27 11:52:29 +05:30
```toml
[semgrep]
2023-03-04 22:38:38 +05:30
description = "My custom ruleset for Semgrep"
2022-08-27 11:52:29 +05:30
targetdir = "/sgrules"
validate = true
[[semgrep.passthrough]]
type = "raw"
2023-03-04 22:38:38 +05:30
target = "my-rules.yml"
2022-08-27 11:52:29 +05:30
value = """
rules:
- id: "insecure"
patterns:
2023-03-04 22:38:38 +05:30
- pattern: "func insecure() {...}"
2022-08-27 11:52:29 +05:30
message: |
2023-03-04 22:38:38 +05:30
Insecure function 'insecure' detected
2022-08-27 11:52:29 +05:30
metadata:
2023-03-04 22:38:38 +05:30
cwe: "..."
2022-08-27 11:52:29 +05:30
severity: "ERROR"
languages:
2023-03-04 22:38:38 +05:30
- "go"
2022-08-27 11:52:29 +05:30
"""
[[semgrep.passthrough]]
type = "raw"
mode = "append"
2023-03-04 22:38:38 +05:30
target = "my-rules.yml"
2022-08-27 11:52:29 +05:30
value = """
- id: "secret"
patterns:
2023-03-04 22:38:38 +05:30
- pattern-either:
- pattern: '$MASK = "..."'
- metavariable-regex:
metavariable: "$MASK"
regex: "(password|pass|passwd|pwd|secret|token)"
2022-08-27 11:52:29 +05:30
message: |
2023-03-04 22:38:38 +05:30
Use of hard-coded password
metadata:
2022-08-27 11:52:29 +05:30
cwe: "..."
severity: "ERROR"
languages:
2023-03-04 22:38:38 +05:30
- "go"
2022-08-27 11:52:29 +05:30
"""
```
2023-03-04 22:38:38 +05:30
```yaml
# /sgrules/my-rules.yml
rules:
- id: "insecure"
patterns:
- pattern: "func insecure() {...}"
message: |
Insecure function 'insecure' detected
metadata:
cwe: "..."
severity: "ERROR"
languages:
- "go"
- id: "secret"
patterns:
- pattern-either:
- pattern: '$MASK = "..."'
- metavariable-regex:
metavariable: "$MASK"
regex: "(password|pass|passwd|pwd|secret|token)"
message: |
Use of hard-coded password
metadata:
cwe: "..."
severity: "ERROR"
languages:
- "go"
```