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(dev-env): CWE-377, CWE-378 originating from xdgDataDirectory() #1654

Merged
merged 2 commits into from
Jan 18, 2024

Conversation

sjinks
Copy link
Member

@sjinks sjinks commented Jan 15, 2024

Description

This PR fixes CWE-377 and CWE-378, which come from xdgDataDirectory().

The code used to fall back to the system temporary directory if the XDG Data Directory is unavailable. However, that solution was not really good because files in the temporary directory can be deleted by the system without a prior warning.

The code that finds out the XDG Data Directory is this:

const homeDirectory = os.homedir();
const {env} = process;

exports.data = env.XDG_DATA_HOME ||
        (homeDirectory ? path.join(homeDirectory, '.local', 'share') : undefined);

The only way to get undefined is not to have the XDG_DATA_HOME environment variable set and not to have the home directory. This is a very extreme case :-)

The current solution is to throw an exception if we cannot determine the data directory.

The other (and not fixed) issue is that xdg-basedir package is the wrong tool to use:

This package is meant for Linux. You should not use XDG on macOS or Windows. Instead, you should follow their platform conventions. You can use env-paths for that.

However, I am not in the mood to fix this now. Maybe someday :-)

Fixes: #1653

Refs:

Pull request checklist

New release checklist

Steps to Test

CI should pass.

@sjinks sjinks added the [Type] Bug Something isn't working label Jan 15, 2024
@sjinks sjinks self-assigned this Jan 15, 2024
Copy link

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@sjinks sjinks merged commit 32d66f6 into trunk Jan 18, 2024
16 checks passed
@sjinks sjinks deleted the GH-1653 branch January 18, 2024 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Insecure temporary file creation (CWE-377, CWE-378) in dev-environment-core
2 participants