Skip to content

Commit 8d82e5c

Browse files
authored
Merge pull request #4 from greysquirr3l/security/harden-unsafe-and-env-races
security: deny unsafe_code in stygian-browser; fix env-var race in jobber tests
2 parents 41f15b0 + 13eb1ee commit 8d82e5c

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

crates/stygian-browser/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,7 @@ mod tests {
978978
// cleanup to isolate side effects.
979979

980980
#[cfg(test)]
981+
#[allow(unsafe_code)] // env::set_var / remove_var are unsafe in Rust ≥1.93; guarded by ENV_LOCK
981982
mod temp_env {
982983
use std::env;
983984
use std::ffi::OsStr;

crates/stygian-browser/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! # stygian-browser
22
//!
33
#![allow(clippy::multiple_crate_versions)]
4+
#![deny(unsafe_code)] // All unsafe usage is confined to #[cfg(test)] modules with explicit #[allow]
45
//! High-performance, anti-detection browser automation library for Rust.
56
//!
67
//! Built on Chrome `DevTools` Protocol (CDP) via [`chromiumoxide`](https://github.com/mattsse/chromiumoxide)

crates/stygian-graph/src/adapters/graphql_plugins/jobber.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ impl GraphQlTargetPlugin for JobberPlugin {
6262
#[allow(unsafe_code, clippy::expect_used)] // set_var/remove_var are unsafe in Rust ≥1.93; scoped to tests only
6363
mod tests {
6464
use super::*;
65+
use std::sync::Mutex;
66+
67+
// Serialise env-var mutations so parallel test threads don't race each other.
68+
static ENV_LOCK: Mutex<()> = Mutex::new(());
6569

6670
#[test]
6771
fn plugin_name_is_jobber() {
@@ -88,8 +92,11 @@ mod tests {
8892
#[test]
8993
fn default_auth_reads_env() {
9094
let key = "JOBBER_ACCESS_TOKEN";
95+
let _guard = ENV_LOCK
96+
.lock()
97+
.unwrap_or_else(std::sync::PoisonError::into_inner);
9198
let prev = std::env::var(key).ok();
92-
// SAFETY: single-threaded test; no concurrent env access
99+
// SAFETY: ENV_LOCK serialises all env mutations in this module
93100
unsafe { std::env::set_var(key, "test-token-abc") };
94101

95102
let auth = JobberPlugin.default_auth();
@@ -109,8 +116,11 @@ mod tests {
109116
#[test]
110117
fn default_auth_absent_when_no_env() {
111118
let key = "JOBBER_ACCESS_TOKEN";
119+
let _guard = ENV_LOCK
120+
.lock()
121+
.unwrap_or_else(std::sync::PoisonError::into_inner);
112122
let prev = std::env::var(key).ok();
113-
// SAFETY: single-threaded test; no concurrent env access
123+
// SAFETY: ENV_LOCK serialises all env mutations in this module
114124
unsafe { std::env::remove_var(key) };
115125

116126
assert!(JobberPlugin.default_auth().is_none());

0 commit comments

Comments
 (0)