feat(rate-limiting): Implement core rate limiting functionality with configuration, decision-making, metrics, middleware, and service registration
- Add RateLimitConfig for configuration management with YAML binding support. - Introduce RateLimitDecision to encapsulate the result of rate limit checks. - Implement RateLimitMetrics for OpenTelemetry metrics tracking. - Create RateLimitMiddleware for enforcing rate limits on incoming requests. - Develop RateLimitService to orchestrate instance and environment rate limit checks. - Add RateLimitServiceCollectionExtensions for dependency injection registration.
This commit is contained in:
18
datasets/reachability/ground-truth/basic/gt-0001/main.c
Normal file
18
datasets/reachability/ground-truth/basic/gt-0001/main.c
Normal file
@@ -0,0 +1,18 @@
|
||||
// gt-0001: Direct call to vulnerable sink from main
|
||||
// Expected: REACHABLE (tier: executed)
|
||||
// Vulnerability: CWE-120 (Buffer Copy without Checking Size)
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char buffer[32];
|
||||
|
||||
if (argc > 1) {
|
||||
// Vulnerable: strcpy without bounds checking
|
||||
strcpy(buffer, argv[1]); // SINK: CWE-120
|
||||
printf("Input: %s\n", buffer);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"$schema": "https://stellaops.io/schemas/sample-manifest.v1.json",
|
||||
"sampleId": "gt-0001",
|
||||
"version": "1.0.0",
|
||||
"category": "basic",
|
||||
"description": "Direct call to vulnerable sink from main - REACHABLE",
|
||||
"language": "c",
|
||||
"expectedResult": {
|
||||
"reachable": true,
|
||||
"tier": "executed",
|
||||
"confidence": 1.0
|
||||
},
|
||||
"source": {
|
||||
"files": ["main.c"],
|
||||
"entrypoint": "main",
|
||||
"sink": "strcpy",
|
||||
"vulnerability": "CWE-120"
|
||||
},
|
||||
"callChain": [
|
||||
{"function": "main", "file": "main.c", "line": 5},
|
||||
{"function": "strcpy", "file": "<libc>", "line": null}
|
||||
],
|
||||
"annotations": {
|
||||
"notes": "Simplest reachable case - direct call from entrypoint to vulnerable function",
|
||||
"difficulty": "trivial"
|
||||
},
|
||||
"createdAt": "2025-12-17T00:00:00Z",
|
||||
"createdBy": "corpus-team"
|
||||
}
|
||||
22
datasets/reachability/ground-truth/basic/gt-0002/main.c
Normal file
22
datasets/reachability/ground-truth/basic/gt-0002/main.c
Normal file
@@ -0,0 +1,22 @@
|
||||
// gt-0002: Two-hop call chain to vulnerable sink
|
||||
// Expected: REACHABLE (tier: executed)
|
||||
// Vulnerability: CWE-134 (Format String)
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
void format_message(const char *user_input, char *output) {
|
||||
// Vulnerable: format string from user input
|
||||
sprintf(output, user_input); // SINK: CWE-134
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char buffer[256];
|
||||
|
||||
if (argc > 1) {
|
||||
format_message(argv[1], buffer);
|
||||
printf("Result: %s\n", buffer);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"$schema": "https://stellaops.io/schemas/sample-manifest.v1.json",
|
||||
"sampleId": "gt-0002",
|
||||
"version": "1.0.0",
|
||||
"category": "basic",
|
||||
"description": "Two-hop call chain to vulnerable sink - REACHABLE",
|
||||
"language": "c",
|
||||
"expectedResult": {
|
||||
"reachable": true,
|
||||
"tier": "executed",
|
||||
"confidence": 1.0
|
||||
},
|
||||
"source": {
|
||||
"files": ["main.c"],
|
||||
"entrypoint": "main",
|
||||
"sink": "sprintf",
|
||||
"vulnerability": "CWE-134"
|
||||
},
|
||||
"callChain": [
|
||||
{"function": "main", "file": "main.c", "line": 15},
|
||||
{"function": "format_message", "file": "main.c", "line": 7},
|
||||
{"function": "sprintf", "file": "<libc>", "line": null}
|
||||
],
|
||||
"annotations": {
|
||||
"notes": "Two-hop chain: main -> helper -> sink",
|
||||
"difficulty": "easy"
|
||||
},
|
||||
"createdAt": "2025-12-17T00:00:00Z",
|
||||
"createdBy": "corpus-team"
|
||||
}
|
||||
25
datasets/reachability/ground-truth/basic/gt-0003/main.c
Normal file
25
datasets/reachability/ground-truth/basic/gt-0003/main.c
Normal file
@@ -0,0 +1,25 @@
|
||||
// gt-0003: Three-hop call chain with command injection
|
||||
// Expected: REACHABLE (tier: executed)
|
||||
// Vulnerability: CWE-78 (OS Command Injection)
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void execute_command(const char *cmd) {
|
||||
// Vulnerable: system call with user input
|
||||
system(cmd); // SINK: CWE-78
|
||||
}
|
||||
|
||||
void process_input(const char *input) {
|
||||
char command[256];
|
||||
snprintf(command, sizeof(command), "echo %s", input);
|
||||
execute_command(command);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc > 1) {
|
||||
process_input(argv[1]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"$schema": "https://stellaops.io/schemas/sample-manifest.v1.json",
|
||||
"sampleId": "gt-0003",
|
||||
"version": "1.0.0",
|
||||
"category": "basic",
|
||||
"description": "Three-hop call chain with multiple sinks - REACHABLE",
|
||||
"language": "c",
|
||||
"expectedResult": {
|
||||
"reachable": true,
|
||||
"tier": "executed",
|
||||
"confidence": 1.0
|
||||
},
|
||||
"source": {
|
||||
"files": ["main.c"],
|
||||
"entrypoint": "main",
|
||||
"sink": "system",
|
||||
"vulnerability": "CWE-78"
|
||||
},
|
||||
"callChain": [
|
||||
{"function": "main", "file": "main.c", "line": 20},
|
||||
{"function": "process_input", "file": "main.c", "line": 12},
|
||||
{"function": "execute_command", "file": "main.c", "line": 6},
|
||||
{"function": "system", "file": "<libc>", "line": null}
|
||||
],
|
||||
"annotations": {
|
||||
"notes": "Three-hop chain demonstrating command injection path",
|
||||
"difficulty": "easy"
|
||||
},
|
||||
"createdAt": "2025-12-17T00:00:00Z",
|
||||
"createdBy": "corpus-team"
|
||||
}
|
||||
37
datasets/reachability/ground-truth/basic/gt-0004/main.c
Normal file
37
datasets/reachability/ground-truth/basic/gt-0004/main.c
Normal file
@@ -0,0 +1,37 @@
|
||||
// gt-0004: Function pointer call to sink
|
||||
// Expected: REACHABLE (tier: executed)
|
||||
// Vulnerability: CWE-120 (Buffer Copy without Checking Size)
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef void (*copy_func_t)(char *, const char *);
|
||||
|
||||
void copy_data(char *dest, const char *src) {
|
||||
// Vulnerable: strcpy without bounds check
|
||||
strcpy(dest, src); // SINK: CWE-120
|
||||
}
|
||||
|
||||
void safe_copy(char *dest, const char *src) {
|
||||
strncpy(dest, src, 31);
|
||||
dest[31] = '\0';
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char buffer[32];
|
||||
copy_func_t copier;
|
||||
|
||||
// Function pointer assignment - harder for static analysis
|
||||
if (argc > 2 && argv[2][0] == 's') {
|
||||
copier = safe_copy;
|
||||
} else {
|
||||
copier = copy_data; // Vulnerable path selected
|
||||
}
|
||||
|
||||
if (argc > 1) {
|
||||
copier(buffer, argv[1]); // Indirect call
|
||||
printf("Result: %s\n", buffer);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"$schema": "https://stellaops.io/schemas/sample-manifest.v1.json",
|
||||
"sampleId": "gt-0004",
|
||||
"version": "1.0.0",
|
||||
"category": "basic",
|
||||
"description": "Function pointer call to sink - REACHABLE",
|
||||
"language": "c",
|
||||
"expectedResult": {
|
||||
"reachable": true,
|
||||
"tier": "executed",
|
||||
"confidence": 0.9
|
||||
},
|
||||
"source": {
|
||||
"files": ["main.c"],
|
||||
"entrypoint": "main",
|
||||
"sink": "strcpy",
|
||||
"vulnerability": "CWE-120"
|
||||
},
|
||||
"callChain": [
|
||||
{"function": "main", "file": "main.c", "line": 18},
|
||||
{"function": "<function_ptr>", "file": "main.c", "line": 19},
|
||||
{"function": "copy_data", "file": "main.c", "line": 8},
|
||||
{"function": "strcpy", "file": "<libc>", "line": null}
|
||||
],
|
||||
"annotations": {
|
||||
"notes": "Indirect call via function pointer - harder for static analysis",
|
||||
"difficulty": "medium"
|
||||
},
|
||||
"createdAt": "2025-12-17T00:00:00Z",
|
||||
"createdBy": "corpus-team"
|
||||
}
|
||||
31
datasets/reachability/ground-truth/basic/gt-0005/main.c
Normal file
31
datasets/reachability/ground-truth/basic/gt-0005/main.c
Normal file
@@ -0,0 +1,31 @@
|
||||
// gt-0005: Recursive function with sink
|
||||
// Expected: REACHABLE (tier: executed)
|
||||
// Vulnerability: CWE-134 (Format String)
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
char result[1024];
|
||||
|
||||
void process_recursive(const char *input, int depth) {
|
||||
if (depth <= 0 || strlen(input) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Vulnerable: format string in recursive context
|
||||
sprintf(result + strlen(result), input); // SINK: CWE-134
|
||||
|
||||
// Recurse with modified input
|
||||
process_recursive(input + 1, depth - 1);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
result[0] = '\0';
|
||||
|
||||
if (argc > 1) {
|
||||
process_recursive(argv[1], 5);
|
||||
printf("Result: %s\n", result);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"$schema": "https://stellaops.io/schemas/sample-manifest.v1.json",
|
||||
"sampleId": "gt-0005",
|
||||
"version": "1.0.0",
|
||||
"category": "basic",
|
||||
"description": "Recursive function with sink - REACHABLE",
|
||||
"language": "c",
|
||||
"expectedResult": {
|
||||
"reachable": true,
|
||||
"tier": "executed",
|
||||
"confidence": 1.0
|
||||
},
|
||||
"source": {
|
||||
"files": ["main.c"],
|
||||
"entrypoint": "main",
|
||||
"sink": "sprintf",
|
||||
"vulnerability": "CWE-134"
|
||||
},
|
||||
"callChain": [
|
||||
{"function": "main", "file": "main.c", "line": 22},
|
||||
{"function": "process_recursive", "file": "main.c", "line": 14},
|
||||
{"function": "process_recursive", "file": "main.c", "line": 14},
|
||||
{"function": "sprintf", "file": "<libc>", "line": null}
|
||||
],
|
||||
"annotations": {
|
||||
"notes": "Recursive call pattern - tests loop/recursion handling",
|
||||
"difficulty": "medium"
|
||||
},
|
||||
"createdAt": "2025-12-17T00:00:00Z",
|
||||
"createdBy": "corpus-team"
|
||||
}
|
||||
Reference in New Issue
Block a user