- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- Administrator's Guide
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
Datadog Static Code Analysis lets you define static analysis rules as custom rules. You can share these custom rules within your organization.
SAST rules are organized within rulesets. A ruleset is a collection of rules. There are no constraints on how rules are organized within a ruleset. For example, some users might want to have rulesets for a specific language and others for a category.
A ruleset must have a unique name with only letters, numbers, and hyphens (-
). Examples of valid
ruleset names are python-security
, cobra-team-checks
, or my-company-security-checks
.
A custom rule is composed of three main components:
Custom rules use tree-sitter queries to query the code abstract syntax tree (AST) and retrieve elements to analyze. Elements of the AST are captured by the query using the @
operator.
All captured nodes from the tree-sitter query are injected in the JavaScript code and further processed to produce violations.
The JavaScript code is defined in a visit
function. This function is triggered at each match of the tree-sitter query.
If a tree-sitter query captures a function call and the analyzed code contains 10 function calls, the visit
function is called 10 times and each invocation has the capture of each occurrence.
The visit
function has the signature visit(node, path, code)
:
node
is the tree-sitter context being matched.path
is the path under analysis (convenient for filtering violation on path or filename).code
is the code under analysis.To get a captured node, use the captures
attribute of the first argument of the visit
function. For example, the code below retrieves the functionName
from a tree-sitter query. Each element contains the following attributes:
astType
: the tree-sitter type of the node.start
: start position of the node. The position contains line
and col
attributes.end
: end position of the node. The position contains line
and col
attributes.function visit(node, filename, code) {
const functionNameNode = node.captures["functionName"];
console.log("ast type");
console.log(functionNameNode.astType);
console.log("start line");
console.log(functionNameNode.start.line);
}
The analyzer includes a few helper functions to help you write rules:
getCodeForNode(node, code)
captures the code for a specific node.buildError(startLine, startCol, endLine, endCol, message, severity, category)
builds an error.severity
is one of the following: ERROR
, WARNING
, NOTICE
and INFO
.category
is one of the following: BEST_PRACTICES
, CODE_STYLE
, ERROR_PRONE
, PERFORMANCE
and SECURITY
.addError(error)
reports an error.All Datadog default rules are available in Code Security. You can easily analyze and copy them to create your own custom rules.