Update policy rule
curl --request PUT \
--url https://semgrep.dev/api/policies/v1/deployments/{deploymentId}/{policyId}/rules/{rulePath} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{}'import requests
url = "https://semgrep.dev/api/policies/v1/deployments/{deploymentId}/{policyId}/rules/{rulePath}"
payload = {}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({})
};
fetch('https://semgrep.dev/api/policies/v1/deployments/{deploymentId}/{policyId}/rules/{rulePath}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://semgrep.dev/api/policies/v1/deployments/{deploymentId}/{policyId}/rules/{rulePath}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://semgrep.dev/api/policies/v1/deployments/{deploymentId}/{policyId}/rules/{rulePath}"
payload := strings.NewReader("{}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://semgrep.dev/api/policies/v1/deployments/{deploymentId}/{policyId}/rules/{rulePath}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{}")
.asString();require 'uri'
require 'net/http'
url = URI("https://semgrep.dev/api/policies/v1/deployments/{deploymentId}/{policyId}/rules/{rulePath}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{}"
response = http.request(request)
puts response.read_body{
"policyId": "456",
"updatedRule": {
"id": "<string>",
"category": "security",
"confidence": "CONFIDENCE_HIGH",
"cweCategories": [
"CWE-918: Server-Side Request Forgery (SSRF)"
],
"hasValidators": true,
"languages": [
"python"
],
"lastChangeAt": "2024-07-29T22:33:37.380Z",
"lastChangeBy": "<string>",
"owaspCategories": [
"A07: Cross-Site Scripting (XSS)"
],
"path": "python.rule.1",
"policyMode": "MODE_BLOCK",
"registryMaintainer": "semgrep",
"rulesets": [],
"secretType": "<string>",
"severity": "SEVERITY_HIGH",
"source": "SOURCE_COMMUNITY",
"technologies": [
"django",
"flask"
],
"url": "<string>",
"vulnerabilityClass": "Improper Authentication"
}
}Policies
Update policy rule
deprecated
Update a specific rule within a policy.
PUT
/
api
/
policies
/
v1
/
deployments
/
{deploymentId}
/
{policyId}
/
rules
/
{rulePath}
Update policy rule
curl --request PUT \
--url https://semgrep.dev/api/policies/v1/deployments/{deploymentId}/{policyId}/rules/{rulePath} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{}'import requests
url = "https://semgrep.dev/api/policies/v1/deployments/{deploymentId}/{policyId}/rules/{rulePath}"
payload = {}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({})
};
fetch('https://semgrep.dev/api/policies/v1/deployments/{deploymentId}/{policyId}/rules/{rulePath}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://semgrep.dev/api/policies/v1/deployments/{deploymentId}/{policyId}/rules/{rulePath}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://semgrep.dev/api/policies/v1/deployments/{deploymentId}/{policyId}/rules/{rulePath}"
payload := strings.NewReader("{}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://semgrep.dev/api/policies/v1/deployments/{deploymentId}/{policyId}/rules/{rulePath}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{}")
.asString();require 'uri'
require 'net/http'
url = URI("https://semgrep.dev/api/policies/v1/deployments/{deploymentId}/{policyId}/rules/{rulePath}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{}"
response = http.request(request)
puts response.read_body{
"policyId": "456",
"updatedRule": {
"id": "<string>",
"category": "security",
"confidence": "CONFIDENCE_HIGH",
"cweCategories": [
"CWE-918: Server-Side Request Forgery (SSRF)"
],
"hasValidators": true,
"languages": [
"python"
],
"lastChangeAt": "2024-07-29T22:33:37.380Z",
"lastChangeBy": "<string>",
"owaspCategories": [
"A07: Cross-Site Scripting (XSS)"
],
"path": "python.rule.1",
"policyMode": "MODE_BLOCK",
"registryMaintainer": "semgrep",
"rulesets": [],
"secretType": "<string>",
"severity": "SEVERITY_HIGH",
"source": "SOURCE_COMMUNITY",
"technologies": [
"django",
"flask"
],
"url": "<string>",
"vulnerabilityClass": "Improper Authentication"
}
}This endpoint is experimental. It may change or be removed without notice and is not covered by API stability guarantees.
Authorizations
Path Parameters
The unique numerical identifier of your deployment. Can be found via the Deployments Service or in your Settings in the web UI.
Example:
123
The unique numerical identifier for the policy. Find your policy's ID via the List Policies endpoint.
Example:
456
Uniquely identify the Rule using its full path. Find the Rule's path via the List Policy Rules endpoint or via the Semgrep Registry.
Example:
"python.rule.1"
Body
application/json
New policy mode to set for the Rule.
- MODE_MONITOR: Monitor mode, silently report findings
- MODE_COMMENT: Comment mode, leaves PR comments but does not block
- MODE_BLOCK: Block mode, leaves PR comments and blocks PR
- MODE_DISABLED: Disabled mode, not active
| value | description |
|---|---|
| MODE_MONITOR | Monitor mode, silently report findings |
| MODE_COMMENT | Comment mode, leaves PR comments but does not block |
| MODE_BLOCK | Block mode, leaves PR comments and blocks PR |
| MODE_DISABLED | Disabled mode, not active |
Available options:
MODE_MONITOR, MODE_COMMENT, MODE_BLOCK, MODE_DISABLED Response
200 - application/json
OK
Policy ID (numeric). Find your policy's ID via the List Policies endpoint.
Example:
"456"
Was this page helpful?