Skip to content

fix(bash): resolve the script-dir idiom written inline in source (#5562) - #5570

Closed
yashsaxena wants to merge 1 commit into
Graphify-Labs:v8from
yashsaxena:bash-inline-source
Closed

yashsaxena wants to merge 1 commit into
Graphify-Labs:v8from
yashsaxena:bash-inline-source

Conversation

@yashsaxena

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #5562.
A source (or .) argument with the script-dir idiom written inline, as in . "$(cd "$(dirname "$0")/.." && pwd)/lib/greet.sh", gave no edge: the leading-expansion rules strip ${VAR}/$VAR, not $(cd … && pwd).
A new helper, _bash_inline_script_dir_path, reads that form the way _bash_assignment_base reads it in an assignment (the script's folder, up one per /..), then the literal path after pwd).
The target goes through _resolve_safe and is_file(), like the other source forms.
This is the f4 form #3416 listed; the $0 and /.. spelling still gave nothing on 0.9.122.

Type of change

  • Bug fix

Verification & Invariants

Invariant (B-1, GHSA-g6c9-j4vm-mwq4): a path a corpus names is only probed through _resolve_safe, and a .. after a guessed base is not followed.
The literal path accepts only [A-Za-z0-9._-] segments and rejects ...

  • Read the CONTRIBUTING.md guide.
  • Reproduced the issue (Bash extractor: . "$(cd "$(dirname "$0")/.." && pwd)/lib/f.sh" (the script-dir idiom inline in source) gets no edge #5562, on graphifyy 0.9.122 from PyPI).
  • Made the smallest fix necessary.
  • Added a regression test: test_extract_bash_source_inline_script_dir_idiom fails without the fix (no bash_sources entry, no imports_from edge); ..._rejects_traversal guards the .. case.
  • Kept the PR description synchronized with the final implementation.
  • Documented any limitations / unsupported cases explicitly: a /.. outside the inner quotes ("$(dirname "$0")"/..) is not counted, the same as in assignments today.

How was this tested?

I could not run the suite on my machine, so this repo's own CI workflow ran on the branch in my fork:

CI workflow (workflow_dispatch) on yashsaxena/graphify@bash-inline-source: all jobs pass
(skillgen-check, test 3.11/3.12/3.13/3.14, pi-guard, security-scan)
test (3.12): 12063 passed, 119 skipped, 2 xfailed   (serial pass: 285 passed, 3 skipped)

Graphify-specific checklist

  • I updated generated skill artifacts: not needed, no fragments changed.
  • Extraction stays deterministic (no ENV reads).
  • Reviewed for security: the new probe is gated by _resolve_safe.
  • No API keys or local graph data.
  • AI authorship disclosed in the commit message (Co-Authored-By: Claude).

…phify-Labs#5562)

. "$(cd "$(dirname "$0")/.." && pwd)/lib/x.sh" now loads lib/x.sh, gated by
_resolve_safe like the other source forms. A .. after the idiom is not followed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @yashsaxena. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic.

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Graphify review View in Graphify

Review before merging · Merge confidence 3/5

1 bug · 1 possible issue to check · High impact

The extractor adds static resolution for inline Bash script-directory source paths.

Bug  Inline sources through subdirectories can point at the wrong file · bash.py:135

1 possible issue we couldn't confirm

They don't change the score.

Code graph · 625 functions depend on this change
  • 2 functions became more coupled. extract_bash() (54 callers), walk() (1 callers).
  • Gate, test list and every flagged function: in the Graphify check.

Reviewed 671649e

Comment on lines +132 to +135
# The literal path after the idiom's closing `&& pwd)` when the idiom is written
# inline in a `source` argument (#5562):
# `$(cd "$(dirname "$0")/.." && pwd)/lib/x.sh` -> `lib/x.sh`.
_BASH_INLINE_PWD_PATH = re.compile(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug  Inline sources through subdirectories can point at the wrong file

A source path that adds a directory after dirname "$0" can be linked to a different file than the script actually sources.

Update _bash_inline_script_dir_path to include subdirectories after dirname "$0".

Evidence · checked against the code
  • Independent source review: The caller checks that the inferred path is safe and exists, but does not compare it with the shell-resolved target. The inspected tests cover a /.. idiom and reject a .. suffix; they do not test an intervening directory such as /sub.
Prompt to fix with AI
In graphify/extractors/bash.py, _bash_inline_script_dir_path (lines 132-135):
Problem: Inline sources through subdirectories can point at the wrong file
Fix it at the cause, and add a test that fails without the fix.

Graphify · Checked against the code · View in Graphify

@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.123, landed via authorship-preserving cherry-pick so your commits keep your name. Thanks @yashsaxena!

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.

Bash extractor: . "$(cd "$(dirname "$0")/.." && pwd)/lib/f.sh" (the script-dir idiom inline in source) gets no edge

2 participants