Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix adding enum value & command line exception #255

Merged
merged 7 commits into from
Nov 24, 2022
Merged

fix adding enum value & command line exception #255

merged 7 commits into from
Nov 24, 2022

Conversation

jianyexi
Copy link
Contributor

@jianyexi jianyexi commented Nov 10, 2022

Copy link
Member

@mikekistler mikekistler left a comment

Choose a reason for hiding this comment

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

Look good! 👍

@jantache-microsoft
Copy link
Member

On inspection (I haven't done any testing), I don't think the escape function fits all cases of escaping. E.g. in Linux bash, one could put $(injected command here) in the path string, and the injected would be evaluated by oad's call to the shell. This will also break if a double-quote is somehow in the path string.

Perhaps handling these cases is out of scope, but if oad is called remotely behind some attacker-controlled input, this could be bad.

Perhaps the shell-invoking command exec and execSync do actually make use of the shell features, in which case the escape function should be improved. But if there's no particular reason a shell needs to be invoked, I strongly recommend using execFile and execFileSync instead, since they pass arguments to the invoked program as-is rather than doing any form of shell evaluation.

@jianyexi
Copy link
Contributor Author

On inspection (I haven't done any testing), I don't think the escape function fits all cases of escaping. E.g. in Linux bash, one could put $(injected command here) in the path string, and the injected would be evaluated by oad's call to the shell. This will also break if a double-quote is somehow in the path string.

Perhaps handling these cases is out of scope, but if oad is called remotely behind some attacker-controlled input, this could be bad.

Perhaps the shell-invoking command exec and execSync do actually make use of the shell features, in which case the escape function should be improved. But if there's no particular reason a shell needs to be invoked, I strongly recommend using execFile and execFileSync instead, since they pass arguments to the invoked program as-is rather than doing any form of shell evaluation.

I didn't use the execFileSync is because it doesn't work in Windows if I pass the 'node' to it.
And the escape only applies to an internal argument, so there is no security issue, so I think this would be a designated fix for your issue so that we have the minimal impact, if we can still consider using the execFile but need to have a further investigation.

@jantache-microsoft
Copy link
Member

Correct me if I am wrong, but isn't the text in this code user-controlled?

    const cmd = `${this.dotNetPath()} ${this.openApiDiffDllPath()} -o ${oldSwagger} -n ${newSwagger}`

    log.debug(`Executing: "${cmd}"`)
    const { stdout } = await exec(cmd, { encoding: "utf8", maxBuffer: 1024 * 1024 * 64 })

And could be attacked by a valid file path like:

$ ls -d $PWD/swagger.json
'/c/Users/jantache/$(echo insert dangerous command here)/swagger.json'

@jianyexi
Copy link
Contributor Author

jianyexi commented Nov 15, 2022

Correct me if I am wrong, but isn't the text in this code user-controlled?

    const cmd = `${this.dotNetPath()} ${this.openApiDiffDllPath()} -o ${oldSwagger} -n ${newSwagger}`

    log.debug(`Executing: "${cmd}"`)
    const { stdout } = await exec(cmd, { encoding: "utf8", maxBuffer: 1024 * 1024 * 64 })

And could be attacked by a valid file path like:

$ ls -d $PWD/swagger.json
'/c/Users/jantache/$(echo insert dangerous command here)/swagger.json'

The tool will check if the file exists, if you provide an invalid file path, the tool will fail before executing this command, and your attack works only when your server do contain such dangerous swagger file path which can't be controlled by the attacker

if (!fs.existsSync(oldSwagger)) {

@jianyexi jianyexi merged commit 000f1f7 into main Nov 24, 2022
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.

None yet

3 participants