Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions stdlib/src/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::cell::RefCell;
use std::collections::HashMap;
use std::net::ToSocketAddrs;
use std::rc::Rc;
use techscript_runtime::context::Capability;
use techscript_runtime::{error::RuntimeError, value::RuntimeValue};

impl StdlibRegistry {
Expand All @@ -16,7 +17,17 @@ impl StdlibRegistry {
Rc::new(StdFunction {
name: "lookup".to_string(),
arity: 1,
callback: |_ctx, args| {
callback: |ctx, args| {
if !ctx.config.capabilities.contains(&Capability::Network) {
return Err(RuntimeError::new(
techscript_runtime::error::RuntimeErrorKind::InvalidOperation(
"Security policy violation: Network capability is denied"
.to_string(),
),
None,
None,
));
}
let host = match &args[0] {
RuntimeValue::Str(s) => s.clone(),
_ => {
Expand Down Expand Up @@ -51,7 +62,7 @@ impl StdlibRegistry {
name: "std.dns".to_string(),
version: "1.0.0".to_string(),
exports,
required_capabilities: Vec::new(),
required_capabilities: vec![Capability::Network],
},
);
}
Expand Down
2 changes: 1 addition & 1 deletion stdlib/tests/stdlib_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1177,5 +1177,5 @@ fn test_ai_generate_text() {
}

#[test]
<<
<<<<
}
Loading