Skip to content

feat(rules): flag preloaded libraries and risky library paths (SG-018) - #213

Open
MaxonT wants to merge 1 commit into
obielin:mainfrom
MaxonT:contrib/103-auto
Open

MaxonT wants to merge 1 commit into
obielin:mainfrom
MaxonT:contrib/103-auto

Conversation

@MaxonT

@MaxonT MaxonT commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Hi there, here is a proposed fix for this issue.

Fixes #103

Thanks for the issue, the sample line and the list of what to flag were easy to turn into tests. This adds SG-018, "Library Preloaded Into Other Programs" (MEDIUM), taking the next free ID since SG-016 and SG-017 are still open in #210 and #211.

  • src/skillshield/rules.py: the rule and its entry in ALL_RULES. It flags LD_PRELOAD or DYLD_INSERT_LIBRARIES set to a value (export, env, a leading VAR=value command, Dockerfile ENV, csh setenv), LD_LIBRARY_PATH with /tmp, /var/tmp, /dev/shm or a Downloads folder among its entries, and writes to /etc/ld.so.preload (a redirect, tee, cp, mv, install, or Python open for writing). Tags are owasp-asi05 and owasp-ast01. The description tells the reviewer that some legitimate skills do this and to check why, as the issue asks.
  • tests/test_sg018_library_preload.py: the sample from the issue, 23 differently worded true positives, 17 near misses (text that only explains LD_PRELOAD, unset, echo $LD_PRELOAD, an empty value, /tmpfiles, cat and grep on /etc/ld.so.preload, and others), a check of the tags, and timing checks on long unbroken inputs. Two early patterns were quadratic on long repeated input (cp x repeated, and LD_LIBRARY_PATH= repeated); the first was caught by a timing check and the second by the reviewer, and both are linear now, with a timing case for each.
  • README.md (rules table, OWASP table, rule counts) and CHANGELOG.md.

How I checked: the 52 new tests pass, and with the rule taken out of ALL_RULES 33 of the first 49 (checked before the last three were added) fail (the rest are the near misses, which pass either way). ruff check src tests and black --check src tests are clean. On the full suite, 1780 passed and 14 failed: the two tests/test_redteam.py tests that need .pyc files (they fail on a fresh checkout of main too, since the partial clone leaves binary files out) and 12 timing tests on other rules (test_*_stays_fast*, test_hostile_*_scans_fast, and the English-text skip tests for French and German). The Mac was under heavy load while they ran (load average above 20); I reran those 12 on main under the same load and 7 failed there as well, and the 6 that still failed on my branch are among them, so I read them as load, not this change. I did not get a quiet-machine rerun. I ran Python 3.12 only, not the rest of the matrix.

Not covered, since the issue did not list them: setting the variable from code (os.environ["LD_PRELOAD"] = ...), JSON or YAML env blocks ("LD_PRELOAD": "..."), dd of=, ln -s and sed -i aimed at /etc/ld.so.preload, DYLD_LIBRARY_PATH, and a preload set inside a script variable. Prose that quotes a full export LD_PRELOAD=/path line is flagged too, like the other pattern rules.

Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com>
@MaxonT
MaxonT requested a review from obielin as a code owner November 28, 2026 08:40
@coderabbitai

coderabbitai Bot commented Nov 28, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 10 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between f2fe28c and a2ebcf0.

Files selected for processing: 4

  • CHANGELOG.md
  • README.md
  • src/skillshield/rules.py
  • tests/test_sg018_library_preload.py

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New rule: preloading a library into other programs (LD_PRELOAD, DYLD_INSERT_LIBRARIES)

1 participant