The Security Center API provides centralized security insights, recommendations, and vulnerability assessments across your Cloudflare infrastructure.
Initialize the Security Center resource
import Cloudflare from 'cloudflare';
const client = new Cloudflare({
apiToken: process.env.CLOUDFLARE_API_TOKEN,
});
const securityCenter = client.securityCenter;
Insights
Manage security insights and recommendations.
List insights
Retrieve all security insights for your account.
// Automatically fetches more pages as needed
for await (const insight of client.securityCenter.insights.list({
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
})) {
console.log(insight.type, insight.severity);
}
Filter by dismissed status
Filter by insight class. Options may include:
compliance
misconfiguration
vulnerability
threat
Filter by specific insight types
Page number of paginated results
Number of items per page (default: 20, max: 100)
Filter by Cloudflare product. Options may include:
access
dns
firewall
ssl
workers
Filter by severity level. Options:
low
moderate
high
critical
Dismiss insight
Mark a security insight as dismissed.
const result = await client.securityCenter.insights.dismiss(
'insight_id',
{
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
dismissed: true,
}
);
Whether to dismiss or undismiss the insight
Use cases
Monitor security posture
Get a comprehensive view of your security posture.
const criticalInsights = [];
const highInsights = [];
for await (const insight of client.securityCenter.insights.list({
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
dismissed: false,
})) {
if (insight.severity === 'critical') {
criticalInsights.push(insight);
} else if (insight.severity === 'high') {
highInsights.push(insight);
}
}
console.log(`Critical insights: ${criticalInsights.length}`);
console.log(`High severity insights: ${highInsights.length}`);
Filter by product
View security insights for a specific Cloudflare product.
for await (const insight of client.securityCenter.insights.list({
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
product: ['firewall', 'access'],
dismissed: false,
})) {
console.log(`[${insight.product}] ${insight.type}: ${insight.description}`);
}
Manage compliance insights
Track and manage compliance-related security insights.
for await (const insight of client.securityCenter.insights.list({
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
insight_class: ['compliance'],
dismissed: false,
})) {
console.log(`Compliance issue: ${insight.type}`);
// Review and optionally dismiss
if (insight.severity === 'low') {
await client.securityCenter.insights.dismiss(
insight.id,
{
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
dismissed: true,
}
);
}
}
Automated security reporting
Generate automated security reports.
interface SecurityReport {
total: number;
bySeverity: Record<string, number>;
byProduct: Record<string, number>;
dismissed: number;
}
const report: SecurityReport = {
total: 0,
bySeverity: {},
byProduct: {},
dismissed: 0,
};
for await (const insight of client.securityCenter.insights.list({
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
})) {
report.total++;
if (insight.dismissed) {
report.dismissed++;
}
report.bySeverity[insight.severity] =
(report.bySeverity[insight.severity] || 0) + 1;
report.byProduct[insight.product] =
(report.byProduct[insight.product] || 0) + 1;
}
console.log('Security Report:', JSON.stringify(report, null, 2));
Response types
InsightListResponse
Represents a security insight.
Severity level: low, moderate, high, or critical
Classification of the insight (e.g., compliance, misconfiguration, vulnerability, threat)
Cloudflare product associated with the insight
Detailed description of the security insight
Whether the insight has been dismissed
When the insight was first detected
When the insight was last updated
Recommended action to address the insight
Potential impact if the insight is not addressed
List of resources affected by this insight
InsightDismissResponse
Response from dismissing an insight.
When the insight was dismissed
Best practices
Prioritize by severity: Focus on critical and high severity insights first to address the most pressing security concerns.
Regular reviews: Schedule regular reviews of security insights to maintain strong security posture.
Product-specific monitoring: Set up monitoring for specific products that are critical to your infrastructure.
Dismissing insights does not fix the underlying security issues. Always review and remediate before dismissing.