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:
master
2025-12-17 18:02:37 +02:00
parent 394b57f6bf
commit 8bbfe4d2d2
211 changed files with 47179 additions and 1590 deletions

View File

@@ -0,0 +1,25 @@
// gt-0011: Dead code - function never called
// Expected: UNREACHABLE (tier: imported)
// Vulnerability: CWE-120 (Buffer Copy without Checking Size)
#include <stdio.h>
#include <string.h>
// This function is NEVER called - dead code
void vulnerable_function(const char *input) {
char buffer[32];
strcpy(buffer, input); // SINK: CWE-120 (but unreachable)
printf("Value: %s\n", buffer);
}
void safe_function(const char *input) {
printf("Safe: %.31s\n", input);
}
int main(int argc, char *argv[]) {
if (argc > 1) {
// Only safe_function is called
safe_function(argv[1]);
}
return 0;
}

View File

@@ -0,0 +1,27 @@
{
"$schema": "https://stellaops.io/schemas/sample-manifest.v1.json",
"sampleId": "gt-0011",
"version": "1.0.0",
"category": "unreachable",
"description": "Dead code - function never called - UNREACHABLE",
"language": "c",
"expectedResult": {
"reachable": false,
"tier": "imported",
"confidence": 1.0
},
"source": {
"files": ["main.c"],
"entrypoint": "main",
"sink": "strcpy",
"vulnerability": "CWE-120"
},
"callChain": null,
"annotations": {
"notes": "Vulnerable function exists but is never called from any reachable path",
"difficulty": "trivial",
"reason": "dead_code"
},
"createdAt": "2025-12-17T00:00:00Z",
"createdBy": "corpus-team"
}

View File

@@ -0,0 +1,28 @@
// gt-0012: Compile-time constant false condition
// Expected: UNREACHABLE (tier: imported)
// Vulnerability: CWE-120 (Buffer Overflow)
#include <stdio.h>
#include <string.h>
#define DEBUG_MODE 0 // Compile-time constant
int main(int argc, char *argv[]) {
char buffer[64];
// This branch is constant false - will be optimized out
if (DEBUG_MODE) {
// Vulnerable code in dead branch
gets(buffer); // SINK: CWE-120 (but unreachable)
printf("Debug: %s\n", buffer);
} else {
// Safe path always taken
if (argc > 1) {
strncpy(buffer, argv[1], sizeof(buffer) - 1);
buffer[sizeof(buffer) - 1] = '\0';
printf("Input: %s\n", buffer);
}
}
return 0;
}

View File

@@ -0,0 +1,27 @@
{
"$schema": "https://stellaops.io/schemas/sample-manifest.v1.json",
"sampleId": "gt-0012",
"version": "1.0.0",
"category": "unreachable",
"description": "Compile-time constant false condition - UNREACHABLE",
"language": "c",
"expectedResult": {
"reachable": false,
"tier": "imported",
"confidence": 1.0
},
"source": {
"files": ["main.c"],
"entrypoint": "main",
"sink": "gets",
"vulnerability": "CWE-120"
},
"callChain": null,
"annotations": {
"notes": "Sink is behind a constant false condition that will be optimized out",
"difficulty": "easy",
"reason": "constant_false"
},
"createdAt": "2025-12-17T00:00:00Z",
"createdBy": "corpus-team"
}

View File

@@ -0,0 +1,27 @@
// gt-0013: Ifdef-excluded code path
// Expected: UNREACHABLE (tier: imported)
// Vulnerability: CWE-78 (OS Command Injection)
// Compile with: gcc -DPRODUCTION main.c (LEGACY_SHELL not defined)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define PRODUCTION
void process_command(const char *cmd) {
#ifdef LEGACY_SHELL
// This code is excluded when LEGACY_SHELL is not defined
system(cmd); // SINK: CWE-78 (but unreachable - ifdef excluded)
#else
// Safe path: just print, don't execute
printf("Would execute: %s\n", cmd);
#endif
}
int main(int argc, char *argv[]) {
if (argc > 1) {
process_command(argv[1]);
}
return 0;
}

View File

@@ -0,0 +1,27 @@
{
"$schema": "https://stellaops.io/schemas/sample-manifest.v1.json",
"sampleId": "gt-0013",
"version": "1.0.0",
"category": "unreachable",
"description": "Ifdef-excluded code path - UNREACHABLE",
"language": "c",
"expectedResult": {
"reachable": false,
"tier": "imported",
"confidence": 1.0
},
"source": {
"files": ["main.c"],
"entrypoint": "main",
"sink": "system",
"vulnerability": "CWE-78"
},
"callChain": null,
"annotations": {
"notes": "Vulnerable code excluded by preprocessor directive",
"difficulty": "easy",
"reason": "preprocessor_excluded"
},
"createdAt": "2025-12-17T00:00:00Z",
"createdBy": "corpus-team"
}