Skip to content

Cover remaining C1 controls in stdisplay tests - #8

Open
assisted-by-ai wants to merge 1 commit into
masterfrom
codex/find-unhandled-control-characters-in-stdisplay
Open

Cover remaining C1 controls in stdisplay tests#8
assisted-by-ai wants to merge 1 commit into
masterfrom
codex/find-unhandled-control-characters-in-stdisplay

Conversation

@assisted-by-ai

Copy link
Copy Markdown
Owner

Summary

  • add regression cases for NEL, PAD/SS3, and status control bytes to ensure they are redacted

Testing

  • NO_COLOR="" COLORTERM="" TERM="xterm-direct" PYTHONPATH=usr/lib/python3/dist-packages python3 -m pytest -o 'python_files=tests/*.py' usr/lib/python3/dist-packages/stdisplay/tests/stdisplay.py

Codex Task

@assisted-by-ai

Copy link
Copy Markdown
Owner Author

stdisplay builds an allowlist of safe characters: printable ASCII (0x20–0x7E), newline, tab, and allowed SGR escape sequences. Everything else—including other control characters, Unicode beyond ASCII, and any escape sequence that is not an allowed SGR—is replaced with underscores.

Conclusion
Based on the implementation, there isn’t a gap where control characters or Unicode that are meant to be sanitized slip through; anything outside the stated allowlist is converted to underscores.

Added a dedicated test case class covering hostile non-SGR escape sequences (OSC, DCS, kitty graphics, UTF-8 mode, and C1 CSI) to ensure they are neutralized by stdisplay.

Added coverage for APC, PM, SOS, and C1 APC control strings to verify stdisplay redacts them outside the SGR allowlist.

Added zero-width and right-to-left override examples to the shared escape-case corpus to verify they are reduced to safe placeholders.

Introduced coverage for single C1 control characters and 8-bit string commands to confirm stdisplay neutralizes them.

Added Unicode formatting controls (bidi overrides/isolates, zero-width joiner, BOM, and related markers) to the shared escape corpus to confirm they are reduced to safe placeholders.

Added coverage for additional C0/C1 controls and nested OSC/DCS clipboard payloads to ensure stdisplay neutralizes them with underscores.

Added regression coverage for additional C1 control bytes (NEL, PAD/SS3, and STS–EPA range) to confirm stdisplay replaces them with safe placeholders.

]


class TestSTDisplayMaliciousCases(unittest.TestCase):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These don't have to go in their own class.

("\x1b]0;evil title\x07", "_]0;evil title_"),
("\x1bP1;2|malicious\x1b\\", "_P1;2|malicious_\\"),
("\x1b_Gf=24,s=1,v=1;AAAA\x1b\\", "__Gf=24,s=1,v=1;AAAA_\\"),
("\x1b%Gpayload", "_%Gpayload"),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ESC % doesn't seem to be a C1 control sequence that I can tell.

@ArrayBolt3

ArrayBolt3 commented Dec 5, 2025

Copy link
Copy Markdown

Added a dedicated test case class covering hostile non-SGR escape sequences (OSC, DCS, kitty graphics, UTF-8 mode, and C1 CSI) to ensure they are neutralized by stdisplay.

Added coverage for APC, PM, SOS, and C1 APC control strings to verify stdisplay redacts them outside the SGR allowlist.

Added zero-width and right-to-left override examples to the shared escape-case corpus to verify they are reduced to safe placeholders.

Introduced coverage for single C1 control characters and 8-bit string commands to confirm stdisplay neutralizes them.

Added Unicode formatting controls (bidi overrides/isolates, zero-width joiner, BOM, and related markers) to the shared escape corpus to confirm they are reduced to safe placeholders.

Added coverage for additional C0/C1 controls and nested OSC/DCS clipboard payloads to ensure stdisplay neutralizes them with underscores.

Added regression coverage for additional C1 control bytes (NEL, PAD/SS3, and STS–EPA range) to confirm stdisplay replaces them with safe placeholders.

All accepted. (I didn't audit to make sure all of the sequences in this PR are the sequences ChatGPT says it included, but really any weird Unicode and escape sequences should be caught by stdisplay, so I don't care too much about whether the commands being sanitized out are well-formed or even valid. We only cared about this for the CSI commands because stdisplay is supposed to semi-interpret and allow through some CSI commands.)

Added the test cases in ArrayBolt3@bb095e1. (Did not use the redundant code from this.) This PR can be closed.

assisted-by-ai added a commit that referenced this pull request May 25, 2026
…nload-error

coverity: stop masking the download step's exit status
assisted-by-ai pushed a commit that referenced this pull request May 25, 2026
Address the actionable code-level alerts surfaced by CodeQL on the
default branch. Skipped Scorecard meta-alerts (repo policy, not code)
and the random-between clear-text-logging alert (false positive: the
script's documented purpose is to print the random number to stdout).

Fixed:
- stdisplay.py: drop tautological `if sgr >= 2**3` so sgr_combo is
  always initialized (alert #9, py/uninitialized-local-variable).
- guimessage.py: open file via `with`, drop dead commented-out code,
  drop unused local `message` (Kicksecure#21, #7, #8).
- str_replace: open file via `with`; stdin path no longer needs a
  shared file handle (Kicksecure#22, py/file-not-closed).
- sttee.py: manage output file lifetimes via `contextlib.ExitStack`
  instead of manual try/finally close loop (Kicksecure#23).
- get-backing-devices-for-mountpoint: replace builtin `exit()` with
  `sys.exit()` (#10, py/use-of-exit-or-quit).
- translations.py: bare `except:` -> `except Exception:`, `== None`
  -> `is None`, drop unused `import sys` (#17, Kicksecure#24, Kicksecure#25, Kicksecure#26).
- leak-tests/{exhaustive_ip_send,simple_ping,tcp_test,udp_test}.py,
  find_wl_compositor, tor-dormant-check, tor-signal-newnym: drop
  unused imports (#11, #12, #13, #14, #15, #16, #18).
- strip_markup/tests/strip_markup.py and unicode_show/tests/
  unicode_show.py: replace `from unittest import mock` with
  `import unittest.mock as mock` so `unittest` isn't imported both
  ways (#19, #20).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants