T09 · Insecure Skill Coding Practices
- Location
scripts/desens_check.py:57- Finding
Incomplete Directory Traversal Allows Sensitive Content to Bypass Desensitization Checks
- Content
View full analysis
Vulnerability Details
File Location:
scripts/desens_check.py, lines 57-66
Vulnerability Type: Incomplete security scanning caused by incorrect loop indentation
Risk Level: MediumVulnerable Code
python if os.path.isfile(a.path): targets = [a.path] else: targets = [] for root, dirs, files in os.walk(a.path): dirs[:] = [d for d in dirs if d not in SKIP_DIRS] for f in files: fp_full = os.path.join(root, f) if os.path.basename(fp_full) in SELF_SKIP: continue if os.path.splitext(f)[1].lower() in SCAN_EXT: targets.append(fp_full)Technical Analysis
The loop that processes
filesis outside theos.walk()loop. Consequently,rootandfilesretain only the values from the final directory visited by the traversal. Files in the root directory and earlier nested directories are not added totargetsand are therefore never inspected.When none of the files from the final visited directory match a desensitization pattern, the script reaches the following success path and reports that the artifact passed:
python if not results: print("[PASS] 去敏复核通过:未检出内部路径/内网域名/工作区片段/指定姓名。") sys.exit(0)This contradicts the documented release-gate behavior, which requires the complete artifact to have zero findings before release.
Attack Path
- An artifact provider creates a release directory containing multiple directories.
- The provider places internal paths, internal hostnames, workspace identifiers, or a name supplied through
--namesin a file located outside the last directory visited byos.walk(). - The release workflow invokes
desens_check.py --path <artifact-directory>. - The vulnerable traversal omits that file from
targets. - The scanner finds no issue in the limited set of files it actually inspects and exits successfully.
- The incomplete success result ca ...[truncated 633 chars]
- Remediation
View remediation
Remediation Suggestions
Move file processing inside the
os.walk()loop:python for root, dirs, files in os.walk(a.path): dirs[:] = [d for d in dirs if d not in SKIP_DIRS] for f in files: fp_full = os.path.join(root, f) if os.path.basename(fp_full) in SELF_SKIP: continue if os.path.splitext(f)[1].lower() in SCAN_EXT: targets.append(fp_full)Additionally:
- Reject nonexistent paths rather than treating them as an empty successful scan.
- Track and report unreadable files instead of silently continuing.
- Add regression tests with findings in the root, intermediate directories, and deeply nested directories.
- Verify that the number of scanned files matches the expected artifact inventory before returning a pass result.
