refactor(dynamic): enhance framework bindings with SSA receiver type checks, add tests for Laravel, Symfony, Rabbit, Kafka, and Pub/Sub

This commit is contained in:
elipeter 2026-05-23 14:32:48 -05:00
parent aaa1fd7ede
commit 17fa611b63
17 changed files with 1255 additions and 167 deletions

View file

@ -1,8 +1,33 @@
<?php
// Phase 16 — CodeIgniter-style route, benign sanitised payload.
namespace CodeIgniter\Router {
class RouteCollection
{
}
}
namespace {
use CodeIgniter\Router\RouteCollection;
class BaseController
{
}
class NyxRoutes extends RouteCollection
{
public function get(string $path, string $callable)
{
$GLOBALS['__nyx_route'] = function (string $payload) use ($callable) {
[$class, $method] = explode('::', $callable, 2);
$controller = new $class();
return $controller->$method($payload);
};
return $this;
}
}
$routes = new NyxRoutes();
$routes->get('run', 'UserController::run');
class UserController extends BaseController
@ -10,9 +35,10 @@ class UserController extends BaseController
public function run($payload)
{
echo "__NYX_SINK_HIT__\n";
$cmd = "echo hello " . escapeshellarg($payload);
$cmd = "true " . escapeshellarg($payload);
$out = shell_exec($cmd);
echo $out;
return $out;
}
}
}

View file

@ -3,8 +3,33 @@
// `$routes->get('run', 'UserController::run')` references the
// controller method whose body shells out without sanitisation.
namespace CodeIgniter\Router {
class RouteCollection
{
}
}
namespace {
use CodeIgniter\Router\RouteCollection;
class BaseController
{
}
class NyxRoutes extends RouteCollection
{
public function get(string $path, string $callable)
{
$GLOBALS['__nyx_route'] = function (string $payload) use ($callable) {
[$class, $method] = explode('::', $callable, 2);
$controller = new $class();
return $controller->$method($payload);
};
return $this;
}
}
$routes = new NyxRoutes();
$routes->get('run', 'UserController::run');
class UserController extends BaseController
@ -18,3 +43,4 @@ class UserController extends BaseController
return $out;
}
}
}

View file

@ -1,6 +1,27 @@
<?php
// Phase 16 — Laravel-style route, benign sanitised payload.
namespace Illuminate\Support\Facades {
class Route
{
public static function get(string $path, string $callable)
{
$GLOBALS['__nyx_route'] = function (string $payload) use ($callable) {
[$class, $method] = preg_split('/@|::/', $callable);
$controller = new $class();
return $controller->$method($payload);
};
return new class {
public function middleware($value)
{
return $this;
}
};
}
}
}
namespace {
use Illuminate\Support\Facades\Route;
Route::get('/run', 'UserController@run');
@ -10,9 +31,10 @@ class UserController
public function run($payload)
{
echo "__NYX_SINK_HIT__\n";
$cmd = "echo hello " . escapeshellarg($payload);
$cmd = "true " . escapeshellarg($payload);
$out = shell_exec($cmd);
echo $out;
return $out;
}
}
}

View file

@ -3,6 +3,27 @@
// `Route::get('/run', 'UserController@run')` references the
// controller method whose body shells out without sanitisation.
namespace Illuminate\Support\Facades {
class Route
{
public static function get(string $path, string $callable)
{
$GLOBALS['__nyx_route'] = function (string $payload) use ($callable) {
[$class, $method] = preg_split('/@|::/', $callable);
$controller = new $class();
return $controller->$method($payload);
};
return new class {
public function middleware($value)
{
return $this;
}
};
}
}
}
namespace {
use Illuminate\Support\Facades\Route;
Route::get('/run', 'UserController@run');
@ -18,3 +39,4 @@ class UserController
return $out;
}
}
}

View file

@ -2,7 +2,31 @@
// Phase 16 — Symfony-style route via `#[Route]` attribute,
// benign sanitised payload.
namespace App\Controller;
namespace Symfony\Component\HttpFoundation {
class Response
{
public function __construct(private string $content)
{
}
public function __toString(): string
{
return $this->content;
}
}
}
namespace Symfony\Component\Routing\Annotation {
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::TARGET_FUNCTION)]
class Route
{
public function __construct(...$args)
{
}
}
}
namespace App\Controller {
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
@ -13,9 +37,12 @@ class UserController
public function run($payload)
{
echo "__NYX_SINK_HIT__\n";
$cmd = "echo hello " . escapeshellarg($payload);
$cmd = "true " . escapeshellarg($payload);
$out = shell_exec($cmd);
echo $out;
return new Response($out);
}
}
$GLOBALS['__nyx_controller'] = new UserController();
}

View file

@ -2,7 +2,31 @@
// Phase 16 — Symfony-style route via `#[Route]` attribute,
// vulnerable.
namespace App\Controller;
namespace Symfony\Component\HttpFoundation {
class Response
{
public function __construct(private string $content)
{
}
public function __toString(): string
{
return $this->content;
}
}
}
namespace Symfony\Component\Routing\Annotation {
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::TARGET_FUNCTION)]
class Route
{
public function __construct(...$args)
{
}
}
}
namespace App\Controller {
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
@ -19,3 +43,6 @@ class UserController
return new Response($out);
}
}
$GLOBALS['__nyx_controller'] = new UserController();
}

View file

@ -156,6 +156,162 @@ fn laravel_adapter_ignores_helper_method() {
assert!(binding.is_none());
}
mod e2e_phase_16_framework_dispatchers {
use super::{common::fixture_harness::FIXTURE_LOCK, parse_php, summary_for};
use nyx_scanner::dynamic::framework::detect_binding;
use nyx_scanner::dynamic::runner::{RunError, RunOutcome, run_spec};
use nyx_scanner::dynamic::sandbox::{SandboxBackend, SandboxOptions};
use nyx_scanner::dynamic::spec::{
EntryKind, HarnessSpec, JavaToolchain, PayloadSlot, SpecDerivationStrategy,
default_toolchain_id,
};
use nyx_scanner::evidence::DifferentialVerdict;
use nyx_scanner::labels::Cap;
use nyx_scanner::symbol::Lang;
use std::path::PathBuf;
use std::process::Command;
use tempfile::TempDir;
fn command_available(bin: &str) -> bool {
Command::new(bin)
.arg("--version")
.output()
.map(|o| o.status.success())
.unwrap_or(false)
}
fn fixture_path(framework: &str, file: &str) -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests/dynamic_fixtures/php_frameworks")
.join(framework)
.join(file)
}
fn build_spec(framework: &str, file: &str) -> (HarnessSpec, TempDir) {
let src = fixture_path(framework, file);
let tmp = TempDir::new().expect("create tempdir");
let dst = tmp.path().join(file);
std::fs::copy(&src, &dst).expect("copy fixture into tempdir");
let entry_file = dst.to_string_lossy().into_owned();
let bytes = std::fs::read(&dst).expect("copied fixture readable");
let tree = parse_php(&bytes);
let summary = summary_for("run", &entry_file);
let framework_binding = detect_binding(&summary, tree.root_node(), &bytes, Lang::Php)
.unwrap_or_else(|| panic!("{framework}/{file} must bind"));
let mut digest = blake3::Hasher::new();
digest.update(b"phase16-e2e-php-framework-dispatcher|");
digest.update(framework.as_bytes());
digest.update(b"|");
digest.update(file.as_bytes());
let spec_hash = format!("{:016x}", {
let bytes = digest.finalize();
u64::from_le_bytes(bytes.as_bytes()[..8].try_into().unwrap())
});
let spec = HarnessSpec {
finding_id: spec_hash.clone(),
entry_file: entry_file.clone(),
entry_name: "run".to_owned(),
entry_kind: EntryKind::HttpRoute,
lang: Lang::Php,
toolchain_id: default_toolchain_id(Lang::Php).to_owned(),
payload_slot: PayloadSlot::Param(0),
expected_cap: Cap::CODE_EXEC,
constraint_hints: vec![],
sink_file: entry_file,
sink_line: 1,
spec_hash,
derivation: SpecDerivationStrategy::FromFlowSteps,
stubs_required: vec![],
framework: Some(framework_binding),
java_toolchain: JavaToolchain::default(),
};
(spec, tmp)
}
fn run(framework: &str, file: &str) -> Option<RunOutcome> {
if !command_available("php") {
eprintln!("SKIP {framework}/{file}: missing php");
return None;
}
let _guard = FIXTURE_LOCK.lock().unwrap_or_else(|e| e.into_inner());
let (spec, _tmp) = build_spec(framework, file);
let opts = SandboxOptions {
backend: SandboxBackend::Process,
..SandboxOptions::default()
};
match run_spec(&spec, &opts) {
Ok(outcome) => Some(outcome),
Err(RunError::BuildFailed { stderr, attempts }) => {
eprintln!(
"SKIP {framework}/{file}: harness build failed after {attempts} attempts: {stderr}",
);
None
}
Err(e) => panic!("run_spec({framework}/{file}) errored: {e:?}"),
}
}
fn assert_vuln_confirms(framework: &str) {
let Some(outcome) = run(framework, "vuln.php") else {
return;
};
assert!(
outcome.triggered_by.is_some(),
"{framework} vuln must Confirm via run_spec; got {outcome:?}",
);
let diff = outcome
.differential
.as_ref()
.expect("confirmed run must carry differential outcome");
assert_eq!(diff.verdict, DifferentialVerdict::Confirmed);
}
fn assert_benign_does_not_confirm(framework: &str) {
let Some(outcome) = run(framework, "benign.php") else {
return;
};
assert!(
outcome.triggered_by.is_none(),
"{framework} benign control must not Confirm; got {outcome:?}",
);
if let Some(diff) = &outcome.differential {
assert_ne!(diff.verdict, DifferentialVerdict::Confirmed);
}
}
#[test]
fn laravel_vuln_confirms_via_run_spec() {
assert_vuln_confirms("laravel");
}
#[test]
fn laravel_benign_does_not_confirm_via_run_spec() {
assert_benign_does_not_confirm("laravel");
}
#[test]
fn symfony_vuln_confirms_via_run_spec() {
assert_vuln_confirms("symfony");
}
#[test]
fn symfony_benign_does_not_confirm_via_run_spec() {
assert_benign_does_not_confirm("symfony");
}
#[test]
fn codeigniter_vuln_confirms_via_run_spec() {
assert_vuln_confirms("codeigniter");
}
#[test]
fn codeigniter_benign_does_not_confirm_via_run_spec() {
assert_benign_does_not_confirm("codeigniter");
}
}
mod e2e_phase_16_laravel_multi_verb {
use super::{common::fixture_harness::FIXTURE_LOCK, parse_php, summary_for};
use nyx_scanner::dynamic::framework::{HttpMethod, detect_binding};