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

feat(load_config): enforce stricter extension checks #5591

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

stevenjoezhang
Copy link
Member

What does it do?

I've noticed that Hexo supports searching for configuration files with different suffixes, such as _config.txt and _config.json. However, this check is very loose, meaning that _config.backup or _config.yml.bak are also considered valid configuration files. This feature can cause confusion and even security issues for users. Typically, users use _config.yml only, and in cases of custom usage, they can specify hexo.config_path. This suggests that there is little need for custom suffixes. Therefore, I recommend removing this feature in the pull request.

Screenshots

Pull request tasks

  • Add test cases for the changes.
  • Passed the CI test.

Copy link

How to test

git clone -b config https://github.com/hexojs/hexo.git
cd hexo
npm install
npm test

Copy link
Member

@SukkaW SukkaW left a comment

Choose a reason for hiding this comment

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

I still prefer to automatically choose config.yml or config.json without specifying it. We might wanna make findConfigPath more strict though.

@stevenjoezhang stevenjoezhang changed the title feat(load_config): remove findConfigPath feat(load_config): enforce stricter extension checks Dec 23, 2024
@stevenjoezhang
Copy link
Member Author

@SukkaW I've updated the code, and now the JSON suffix is also supported.

};

async function findConfigPath(path: string): Promise<string> {
const { dir, name } = parse(path);

const files = await readdir(dir);
const item = files.find(item => item.startsWith(name));
const item = files.find(item => item === name + '.json');
Copy link
Member

@SukkaW SukkaW Dec 23, 2024

Choose a reason for hiding this comment

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

This doesn't make sense. That should be using path.basename(item) === 'config'.

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.

2 participants