Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
217af66
Reject surplus arguments to profiles subcommands
inxbit Nov 17, 2026
ef8db3e
Write the requested reports when the input is empty
inxbit Nov 17, 2026
49d1fa9
Wait for input when the filter's stdin is non-blocking
inxbit Nov 17, 2026
2be3fbd
Apply --sanitize and --strip-ansi to profiles test output
inxbit Nov 17, 2026
a846162
Refuse a FIFO in place of a runtime file without blocking
inxbit Nov 17, 2026
0d42686
Track only real SGR controls as the program's colors
inxbit Nov 17, 2026
fd3c800
Keep the line controls inside a CSI that --strip-ansi removes
inxbit Nov 17, 2026
cbde563
Let an exclusive rule style all of its own capture groups
inxbit Nov 17, 2026
5df530b
Keep non-SGR controls when a prompt's colors are neutralized
inxbit Nov 17, 2026
39b23d3
Skip SS3 keys whole in --local-echo
inxbit Nov 17, 2026
9a3b90f
Refuse a trace file that has a second hard link
inxbit Nov 17, 2026
a26c805
Reject a capture index that does not fit usize
inxbit Nov 17, 2026
01df4e9
Fix built-in rules that mispaint common device output
inxbit Nov 17, 2026
815baab
Keep line controls inside any stripped non-string escape
inxbit Nov 17, 2026
365fe32
Match a profile's strong signals as whole words
inxbit Nov 17, 2026
fb6a9d2
Scan content, not git grep records, for IPv6 and padded IPv4
inxbit Nov 17, 2026
4a08084
Use a synthetic user name in a prompt matcher test
inxbit Nov 17, 2026
e3ea7a9
Build the crate package in CI, and correct release and site details
inxbit Nov 17, 2026
296642f
Add changelog entries for the audit fixes
inxbit Nov 17, 2026
3b64cbc
Let a strong signal continue into a glued model or version
inxbit Nov 17, 2026
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
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ jobs:
echo "apt could not install the PCRE2 build dependency"
exit 1
- run: cargo test --locked
# The crate ships an allowlist of files (`include` in Cargo.toml). Build
# what would be published here, so a missing file fails a pull request
# instead of a release tag that cannot be moved or deleted.
- run: cargo package --locked

test:
name: Test
Expand Down
73 changes: 73 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,79 @@

All notable changes to PrismTTY are documented here.

## Unreleased

### Security

- Apply `--sanitize` and `--strip-ansi` to `profiles test`. It printed its
fixture without the filtering the two flags ask for, so an OSC 52 clipboard
write in a captured fixture still reached the terminal under `--sanitize`.
- Refuse a `--trace-io` file that has a second hard link. The trace was
appended to whatever else the path was linked to.
- Open the reload marker and pid files without blocking. A FIFO in place of
the marker made `prismtty --reload` hang forever.

### Fixed

- Treat only real SGR controls as the program's colors. Any CSI ending in `m`
counted, so xterm's key modifier option (`CSI > 4 ; 1 m`, XTMODKEYS) was
tracked as bold and the text after each highlight was redrawn bold or
faint. The same control was deleted from the stream when a prompt's colors
were neutralized, so the terminal never changed how it reports keys. A
control with an intermediate byte (`CSI + 31 m`) is no longer read as a
color, and a C0 control inside an SGR no longer loses the color.
- Reject surplus arguments to `profiles list`, `show`, `validate` and `test`.
`profiles validate good.yml broken.yml` reported success having read only
the first file.
- Write the `--show-profile` and `--benchmark` reports when the input is
empty.
- Wait for input when the filter inherits a non-blocking stdin, instead of
exiting with "Resource temporarily unavailable".
- Let an exclusive rule style all of its own capture groups. With colors on
groups 0 and 1, group 1 was skipped because group 0 had already protected
the span.
- Match a profile's strong signals only where they begin a word. `rhel`
inside `ServerHello` selected linux-unix, `ios xe` inside `BIOS XE` and
`asa version` inside `NASA version` selected cisco, and `pan-os` inside
`japan-osaka` selected palo-alto. A model or version glued on after the
signal (`Nexus9000`, `rhel9`) still matches.
- Skip SS3 keys whole in `--local-echo`. An arrow or function key sent in
application mode (`ESC O A`) was echoed as `OA`.
- Reject a numeric capture key that does not fit the platform's `usize`. On
a 32-bit build 4294967296 wrapped to group 0.

### Profiles

- generic: a good-state word after `not` is no longer green (`not reachable`,
`not connected` in aligned columns, `not valid`), and `not reachable` is a
bad state like `not connected`.
- generic: bare `den` (a site code, a word) is no longer painted as a denial;
`deny`, `denies` and `denied` still are.
- generic: an IPv6 zone that holds `-`, `.` or `_` (`%eth-0`, `%bond0.100`)
is colored with its address instead of splitting it.
- arubacx and fortinet: configuration-context prompts (`switch(config)#`,
`FGT (global) #`) are colored like the plain prompt.
- palo-alto: aggregate interfaces (`ae1`, `ae1.107`) are colored.

### Library API

- `strip_ansi` keeps the format effectors (backspace through carriage return)
found inside a CSI or a plain escape sequence, as a terminal runs them.
It used to drop them with the control, which joined the lines around an
escape cut short at a line end. Controls inside a string control are still
removed with it.

### Release and QA

- CI builds the crate package (`cargo package --locked`), so a file missing
from the `include` list fails a pull request instead of a release tag.
- The privacy scan checks file content and paths separately for IPv6
addresses. It scanned `git grep` records whole, so a line number joined an
address that began the line. It also checks zero-padded IPv4 octets.
- A prompt matcher test used a real local account name; it is synthetic now.
- The READMEs no longer say a release archive contains its checksum, and
name the PCRE2 runtime requirement.

## 1.3.0 - 2026-10-22

### Security
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ writing anything.
Generated images and video keep their provenance next to them. PNGs carry the
prompt or capture notes in an embedded `impeccable:prompt` text chunk; other
files use a `.json` sidecar named after the file (for example
`prism-loop.mp4.json`) with a `prompt` field. Update it when you replace the
`prism-intro.mp4.json`) with a `prompt` field. Update it when you replace the
asset.

Browsers and caches keep CSS, JavaScript, and font files for a while, so a
Expand Down
5 changes: 4 additions & 1 deletion README.crates.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ Prebuilt release archives and checksums are available on the
[GitHub releases page](https://github.com/inxbit/prismtty/releases).

Each release archive contains the binaries, license/readme files, example
profiles, shell completions, and a `.tar.gz.sha256` checksum.
profiles, and shell completions. Its `.tar.gz.sha256` checksum is a separate
file next to it on the release page. The binaries load PCRE2 at run time: from
Homebrew (`brew install pcre2`) on macOS, and from the system `libpcre2-8` on
Linux.

Installed commands:

Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ Prebuilt release archives and checksums are available on the
[latest release page](https://github.com/inxbit/prismtty/releases/latest).

Each release archive contains the binaries, license/readme files, example
profiles, shell completions, and a `.tar.gz.sha256` checksum.
profiles, and shell completions. Its `.tar.gz.sha256` checksum is a separate
file next to it on the release page. The binaries load PCRE2 at run time: from
Homebrew (`brew install pcre2`) on macOS, and from the system `libpcre2-8` on
Linux.

### Build Locally

Expand Down
1 change: 1 addition & 0 deletions docs/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ a {
.out .ln:nth-child(3) { --d: 0.86s; }
.out .ln:nth-child(4) { --d: 1.04s; }
.out .ln:nth-child(5) { --d: 1.22s; }
.out .ln:nth-child(6) { --d: 1.4s; }

.out-raw .ln {
animation-delay: var(--d);
Expand Down
19 changes: 16 additions & 3 deletions scripts/privacy-scan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,14 @@ for line in result.stdout.splitlines():
try:
address = ipaddress.ip_address(match.group(0))
except ValueError:
continue
# Devices print zero-padded octets (10.001.2.3), which ipaddress
# refuses. They name the same address.
try:
address = ipaddress.ip_address(
".".join(str(int(octet)) for octet in match.group(0).split("."))
)
except ValueError:
continue
if (
match.group(0) not in allowed_netmasks
and match.group(0) not in allowed_wildcard_masks
Expand All @@ -125,6 +132,9 @@ result = subprocess.run(
"--untracked",
"--exclude-standard",
"-n",
# NUL after the path and the line number, so neither can run into an
# address that begins the line.
"-z",
"-I",
"-E",
":",
Expand All @@ -150,8 +160,11 @@ ipv6_pattern = re.compile(
r"(?![0-9A-Za-z_])"
)
findings = []
for line in result.stdout.splitlines():
for match in ipv6_pattern.finditer(line):
for record in result.stdout.split("\n"):
path, _, rest = record.partition("\0")
number, _, content = rest.partition("\0")
line = f"{path}:{number}:{content}"
for match in [*ipv6_pattern.finditer(path), *ipv6_pattern.finditer(content)]:
address_text = match.group("bracketed") or match.group("plain")
try:
address = ipaddress.ip_address(address_text)
Expand Down
22 changes: 18 additions & 4 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ use thiserror::Error;
use crate::config::{
MAX_PROFILE_TEST_FILE_BYTES, PrismConfig, load_profile_file, read_bounded_regular_file,
};
use crate::highlight::{Highlighter, RuleMatchError, StreamingHighlighter};
use crate::highlight::{
Highlighter, RuleMatchError, StreamingHighlighter, strip_ansi, strip_string_escapes,
};
use crate::terminal_text::escape_untrusted;

use args::{Action, Options, parse_args, print_help};
Expand Down Expand Up @@ -203,6 +205,15 @@ fn run_inner(args: Vec<OsString>) -> Result<ExitCode, CliError> {
Action::ProfilesTest { profile, fixture } => {
let input =
read_bounded_regular_file(&fixture, MAX_PROFILE_TEST_FILE_BYTES, "fixture")?;
// The fixture is printed to the terminal like program output, so
// the flags that remove escapes from that output apply to it too.
let input = if options.strip_ansi {
strip_ansi(&input)
} else if options.sanitize {
strip_string_escapes(&input)
} else {
input
};
let store = profile_store()?;
let config = PrismConfig::from_profiles(&store, &[profile.as_str()])?;
let highlighter = Highlighter::from_config(config)?;
Expand Down Expand Up @@ -252,14 +263,17 @@ fn run_stdin(options: Options) -> Result<ExitCode, CliError> {
let trace = IoTrace::open(options.trace_io.as_deref())?;
let (_registration, reload_watcher) = register_for_reload();
let stdin = io::stdin();
// As in PTY mode, another program on the terminal can leave stdout
// non-blocking.
// As in PTY mode, another program on the terminal or pipe can leave
// stdin and stdout non-blocking.
let mut stdout = WaitWhenWouldBlock {
fd: stdout.as_raw_fd(),
inner: stdout,
};
highlight_stream(
stdin.lock(),
WaitWhenWouldBlock {
fd: stdin.as_raw_fd(),
inner: stdin.lock(),
},
&mut stdout,
prepared,
InputSource {
Expand Down
16 changes: 16 additions & 0 deletions src/cli/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,22 @@ fn parse_profiles_command(
.map(|arg| arg.to_string_lossy().to_string())
.unwrap_or_else(|| "list".to_string());

// Each subcommand reads a fixed number of arguments. A surplus one is an
// error rather than dropped, so `profiles validate a.yml b.yml` cannot
// report success having read only `a.yml`.
let expected_args = match subcommand.as_str() {
"list" => 1,
"show" | "validate" => 2,
"test" => 3,
_ => usize::MAX,
};
if let Some(surplus) = args.get(expected_args) {
return Err(CliError::Usage(format!(
"profiles {subcommand} unexpected argument '{}'",
escape_untrusted(&surplus.to_string_lossy())
)));
}

match subcommand.as_str() {
"list" => Ok((options, Action::ProfilesList)),
"show" => {
Expand Down
20 changes: 20 additions & 0 deletions src/cli/pty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1475,6 +1475,15 @@ fn local_echo_escape_step(input: &[u8], idx: usize) -> LocalEchoStep {
let Some(next) = input.get(idx + 1) else {
return LocalEchoStep::Incomplete;
};
// SS3: an arrow or function key in application mode, `ESC O` plus one
// final byte.
if *next == b'O' {
return if idx + 2 < input.len() {
LocalEchoStep::Skip(idx + 3)
} else {
LocalEchoStep::Incomplete
};
}
if *next != b'[' {
return LocalEchoStep::Skip(idx + 1);
}
Expand Down Expand Up @@ -2788,6 +2797,17 @@ mod tests {
assert_eq!(echo.push(b"show\r"), b"show\r\n");
}

// In application cursor-key mode an arrow or function key arrives as SS3
// (`ESC O A`, `ESC O P`). Its final byte is part of the key, not text.
#[test]
fn local_echo_skips_ss3_keys_whole_even_when_split() {
assert_eq!(super::local_echo_bytes(b"a\x1bOAb\x1bOPc"), b"abc");

let mut echo = super::LocalEchoState::default();
assert!(echo.push(b"\x1bO").is_empty());
assert_eq!(echo.push(b"Ax"), b"x");
}

#[test]
fn local_echo_state_bounds_incomplete_csi_and_recovers() {
let mut echo = super::LocalEchoState::default();
Expand Down
40 changes: 39 additions & 1 deletion src/cli/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,11 @@ fn write_private_file(path: &Path, contents: &[u8]) -> io::Result<()> {
.write(true)
.truncate(true)
.mode(0o600)
.custom_flags(libc::O_NOFOLLOW)
// O_NONBLOCK: opening a FIFO for writing otherwise blocks until it
// has a reader. With it the open fails or returns at once, and the
// file type check below refuses anything that is not a regular file.
// It has no effect on writes to a regular file.
.custom_flags(libc::O_NOFOLLOW | libc::O_NONBLOCK)
.open(path)?;
ensure_private_runtime_file(&file, path)?;
file.write_all(contents)
Expand Down Expand Up @@ -506,6 +510,40 @@ mod tests {
);
}

// Opening a FIFO for writing blocks until something reads it. A FIFO in
// place of the reload marker must be refused, not waited on forever.
#[cfg(unix)]
#[test]
fn runtime_write_file_refuses_a_fifo_without_blocking() {
use std::os::unix::ffi::OsStrExt;

let temp = tempfile::tempdir().expect("tempdir creates");
let runtime = temp.path().join("runtime");
let reload = runtime.join("reload");
super::ensure_private_runtime_dir(&runtime).expect("runtime dir creates");
let fifo_path =
std::ffi::CString::new(reload.as_os_str().as_bytes()).expect("path has no NUL");
// SAFETY: `fifo_path` is a valid NUL-terminated path; mkfifo only
// creates the FIFO there.
assert_eq!(unsafe { libc::mkfifo(fifo_path.as_ptr(), 0o600) }, 0);

let (done_tx, done_rx) = std::sync::mpsc::channel();
let writer_path = reload.clone();
let writer = std::thread::spawn(move || {
let _ = done_tx.send(super::write_private_file(&writer_path, b"now\n"));
});
let result = done_rx.recv_timeout(std::time::Duration::from_secs(5));
if result.is_err() {
// Give the blocked open its reader so the thread can end.
let _ = std::fs::File::open(&reload);
}
writer.join().expect("writer thread ends");

result
.expect("opening the FIFO blocked")
.expect_err("a FIFO is not a runtime file");
}

#[cfg(unix)]
#[test]
fn pid_registration_preserves_legacy_shared_pid_file_for_older_binaries() {
Expand Down
10 changes: 10 additions & 0 deletions src/cli/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ pub(super) fn highlight_stream<R: Read, W: Write>(
let mut chunk_filter = ChunkFilterState::default();
let read = reader.read(&mut buffer)?;
if read == 0 {
// An input that ends before its first byte is still a run: the
// reports that were asked for are written.
session.report_current();
if options.benchmark {
print_benchmark_report(
session.benchmark_report(),
input_bytes,
started.elapsed().as_secs_f64(),
);
}
return Ok(());
}

Expand Down
33 changes: 33 additions & 0 deletions src/cli/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ fn open_trace_file(path: &Path) -> io::Result<File> {
),
));
}
// A second hard link is a second name for the same file: the trace would
// be appended to whatever else that name is used for.
if metadata.nlink() != 1 {
return Err(io::Error::new(
io::ErrorKind::PermissionDenied,
format!("trace file has more than one hard link: {}", path.display()),
));
}
// Writes keep their usual blocking semantics; O_APPEND is preserved.
let fd = file.as_raw_fd();
// SAFETY: `fd` is the open descriptor owned by `file`; F_GETFL only reads
Expand Down Expand Up @@ -280,6 +288,31 @@ mod tests {
);
}

// A second name for a file is a second way to reach it: the trace must
// not be appended to whatever else the path was hard-linked to.
#[cfg(unix)]
#[test]
fn trace_file_rejects_a_hard_linked_target() {
let dir = tempfile::tempdir().expect("tempdir creates");
let target = dir.path().join("target.log");
let path = dir.path().join("trace.log");
std::fs::write(&target, "original\n").expect("target writes");
std::fs::set_permissions(&target, std::fs::Permissions::from_mode(0o600))
.expect("mode sets");
std::fs::hard_link(&target, &path).expect("hard link creates");

let trace = super::IoTrace::open(Some(&path));
if let Ok(trace) = &trace {
trace.log("OUT", b"secret");
}

assert!(trace.is_err(), "a hard-linked trace file was accepted");
assert_eq!(
std::fs::read_to_string(&target).expect("target reads"),
"original\n"
);
}

// Opening a FIFO for writing blocks until a reader appears, which would
// hang startup before the non-regular-file check could reject it.
#[cfg(unix)]
Expand Down
Loading
Loading