Skip to content

Fix: Add trust check for project config files - #3016

Open
pujal0909 wants to merge 36 commits into
masterfrom
fix/trust-config
Open

pujal0909 wants to merge 36 commits into
masterfrom
fix/trust-config

Conversation

@pujal0909

@pujal0909 pujal0909 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

What It Does

Project config files are now loaded only from directories the user trusts. Unrecognized and world-writable directories are skipped with a warning. Follows : zowe/zowe-client-python-sdk#405

This is a breaking change.

How to Test

Follow the steps in the linked Python SDK PR, but instead of test.py use a Node.js script test.js:

const readline = require("node:readline/promises");
const { Config, ConfigUtils, TrustedConfigManager } = require("@zowe/imperative");

async function trustPromptFn(dir) {
    const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
    try {
        const answer = await rl.question(`Do you trust ${dir}? `);
        return answer.trim().toLowerCase() === "y";
    } finally {
        rl.close();
    }
}

(async () => {
    const homeDir = ConfigUtils.getZoweDir();
    // TrustedConfigManager.add(homeDir, __dirname);

    const config = await Config.load("zowe", { homeDir, trustPromptFn });
    if (!config.exists) throw new Error("No team configuration file found");

    const profile = { ...config.api.profiles.defaultGet("base"),
        ...config.api.profiles.defaultGet("zosmf") };
    for (const [key, value] of Object.entries(profile)) {
        console.log(`${key}: ${value}`);
    }
})().catch(err => {
    console.error(err);
    process.exitCode = 1;
});

Review Checklist
I certify that I have:

  • updated the changelog
  • manually tested my changes
  • added/updated automated unit/integration tests
  • created/ran system tests (provide build number if applicable)
  • followed the contribution guidelines

Additional Comments

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Pujal <pujal.gandhi@broadcom.com>
@github-project-automation github-project-automation Bot moved this to New Issues in Zowe CLI Squad Nov 10, 2026
@zowe-robot zowe-robot moved this from New Issues to In Progress in Zowe CLI Squad Nov 10, 2026
@codecov

codecov Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.95413% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.84%. Comparing base (fb46737) to head (f526f33).

Files with missing lines Patch % Lines
.../imperative/src/config/src/TrustedConfigManager.ts 93.67% 5 Missing ⚠️
...ackages/imperative/src/cmd/src/CommandProcessor.ts 93.75% 2 Missing ⚠️
packages/imperative/src/config/src/Config.ts 96.42% 2 Missing ⚠️
...ackages/imperative/src/settings/src/AppSettings.ts 94.11% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3016      +/-   ##
==========================================
+ Coverage   92.78%   92.84%   +0.06%     
==========================================
  Files         661      662       +1     
  Lines       21266    21448     +182     
  Branches     4925     4982      +57     
==========================================
+ Hits        19731    19914     +183     
+ Misses       1532     1531       -1     
  Partials        3        3              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

@pujal0909
pujal0909 requested a review from t1m0thyj November 11, 2026 15:34
pujal0909 and others added 3 commits November 11, 2026 10:35
Signed-off-by: Pujal <pujal.gandhi@broadcom.com>
Signed-off-by: Pujal <pujal.gandhi@broadcom.com>
@pujal0909
pujal0909 requested a review from zFernand0 November 11, 2026 21:01
Signed-off-by: Pujal Gandhi <71276682+pujal0909@users.noreply.github.com>
@pujal0909
pujal0909 requested a review from anaxceron November 12, 2026 16:32
@pujal0909
pujal0909 marked this pull request as ready for review November 12, 2026 16:32
@github-actions

Copy link
Copy Markdown

📅 Suggested merge-by date: 11/26/2026

@zowe-robot zowe-robot moved this from In Progress to Review/QA in Zowe CLI Squad Nov 12, 2026
Comment thread packages/imperative/CHANGELOG.md Outdated

## Recent Changes

- **Breaking:** Project config files are now only loaded from trusted directories. World-writable directories are always skipped, and directories outside the current working directory, the home directory, or the `trustedConfigDirs` list in `settings/imperative.json` are skipped unless `IConfigOpts.trustPromptFn` approves them or `ZOWE_CONFIG_ALLOW_UNTRUSTED_DIRS=true` is set. [#3016](https://github.com/zowe/zowe-cli/pull/3016)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should explain what settings/imperative.json, IConfigOpts.trustPromptFn, and ZOWE_CONFIG_ALLOW_UNTRUSTED_DIRS=true are

Comment on lines 342 to 345
const configPath = Config.search(this.configName, {
ignoreDirs: [this.mHomeDir], startDir: this.mProjectDir, isTrusted: this.isTrustedDir
});
return configPath || path.join(this.mProjectDir, this.configName);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If the project directory is the only layer and that layer is not trusted, this logic falls back to return the same rejected project-level config file. Then when we call Config.reload later on, the read function is called and that reads the layer without another trust check.

Can we update this to distinguish between a missing config and rejected config, so that we do not load a rejected file?

*/
public static isDirTrusted(dirPath: string, cliHome: string, promptFn?: TrustPromptFn, startDir?: string): boolean {
const allowEnv = process.env[this.ENV_ALLOW_UNTRUSTED]?.toLowerCase();
if (process.env.CI != null || allowEnv === "1" || allowEnv === "true") return true;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(nitpick) I'm not opposed to keeping this check as-is since we have used the if (process.env.CI != null) pattern elsewhere, but I'm wondering if we should make the check a bit more explicit to avoid edge cases?

Suggested change
if (process.env.CI != null || allowEnv === "1" || allowEnv === "true") return true;
const isCI = Boolean(process.env.CI && process.env.CI !== 'false' && process.env.CI !== '0');
if (isCI || allowEnv === "1" || allowEnv === "true") return true;

CBforZ and others added 3 commits November 13, 2026 15:47
Co-Authored-by: Codex @model: GPT-6.1 Sol
Modified AI generated code: Yes
Dev Name: Timothy Johnson

Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
CBforZ and others added 8 commits December 2, 2026 09:18
Signed-off-by: CBforZ <chris.boehm@broadcom.com>
Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
Co-Authored-by: Codex @model: GPT-6.2 Sol
Modified AI generated code: Yes
Dev Name: Timothy Johnson

Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
Signed-off-by: Pujal <pujal.gandhi@broadcom.com>
Signed-off-by: Pujal Gandhi <71276682+pujal0909@users.noreply.github.com>
@pujal0909
pujal0909 requested a review from traeok December 3, 2026 15:59
Signed-off-by: Pujal <pujal.gandhi@broadcom.com>
traeok
traeok previously requested changes Dec 3, 2026

@traeok traeok left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seeing some test failures on Windows. Happy to help with debugging / resolving on my Windows machine if it helps!

Comment thread packages/imperative/CHANGELOG.md Resolved
Signed-off-by: Pujal <pujal.gandhi@broadcom.com>
Signed-off-by: Pujal <pujal.gandhi@broadcom.com>
@pujal0909
pujal0909 requested a review from traeok December 3, 2026 19:57
Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
Add trusted config prompts to CLI and daemon

(namespaceObj as Record<string, SettingValue>)[key] = value;
this.flush();
(namespaceObj as Record<string, SettingValue>)[key] = value;
@t1m0thyj
t1m0thyj requested a review from CBforZ December 3, 2026 21:49
Co-Authored-by: Codex @model: GPT-6.2 Sol
Modified AI generated code: Yes
Dev Name: Timothy Johnson

Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
@traeok
traeok self-requested a review December 4, 2026 15:53
@traeok
traeok dismissed their stale review December 4, 2026 15:54

taking another look today

Signed-off-by: Pujal <pujal.gandhi@broadcom.com>
@sonarqubecloud

sonarqubecloud Bot commented Dec 4, 2026

Copy link
Copy Markdown

@traeok traeok left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The only concerns I have left are out of scope, so I am ready to approve. Thanks for the fix and addressing feedback!

@zFernand0 zFernand0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM! 😋

*/
public static isDirTrustedWithoutPrompt(dirPath: string, cliHome: string): boolean {
const allowEnv = process.env[this.ENV_ALLOW_UNTRUSTED]?.toLowerCase();
const isCI = Boolean(process.env.CI && process.env.CI !== "false" && process.env.CI !== "0");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should consider turning this into a utility function we can use everywhere (if we don't have one already) 🙏

Maybe sometghin that will return true if a give ENV is set 😋
We could apply to to CI and ZOWE_CONFIG_ALLOW_UNTRUSTED_DIRS

let warning: string | undefined;
try {
if (TrustedConfigManager.isWorldWritable(dir)) {
warning = "The directory is world-writable. To load this config, run 'chmod o-w <path>' on the directory " +

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we help th users by adding the director in the warning?

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

Labels

None yet

Projects

Status: Review/QA

Development

Successfully merging this pull request may close these issues.

7 participants