Enhance Security Practices for HanLP Based on OpenSSF Scorecard #1931
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Enhance Security Practices for HanLP Based on OpenSSF Scorecard
Description
Dear HanLP Maintainers,
Firstly, I want to express my sincere appreciation for your contributions to HanLP. It’s inspiring to see how this project has grown and made such a significant impact within the open-source community.
The OpenSSF Scorecard is an automated tool that evaluates the security practices of open-source projects based on a variety of criteria. It provides a security score and actionable insights that help improve project safety and risk management.
While reviewing HanLP using the OpenSSF Scorecard, I identified two potential risks that could improve the overall security posture of the project. These are related to Token-Permissions and Pinned-Dependencies, both of which are important for maintaining the integrity and security of the project's CI/CD pipeline.
Issues Identified:
Token Permissions:
In the current workflow configuration, the
unit-tests
workflow appears to lack explicitly defined permissions. This can be a security risk, as workflows may have broader access than necessary. It is considered best practice to define the exact permissions required for each workflow or job in the permissions field of the GitHub Actions configuration. This will limit access to only what’s needed, reducing the risk of over-permissioning, which can lead to security vulnerabilities.Pinned Dependencies:
Another area for improvement is how third-party libraries are referenced within the workflow configuration. Some dependencies currently use the
@v4
tag, which points to an evolving version of the library. This can introduce issues if the library is updated with breaking changes or vulnerabilities. The OpenSSF scorecard recommends using specific commit hashes for dependencies, which locks the version and ensures that only known secure versions are used. This will prevent unintentional upgrades that might introduce new risks.My PR:
To address the issues mentioned above, I have submitted a pull request with the following changes:
@v4
references with specific commit hashes for third-party libraries.pip install somepackage
bypip install -r requirements.txt --require-hashes
. (Please tell me the exact version of the dependencies, I would be happy to complete it.)Additional Security Suggestions Based on Scorecard:
Branch Protection:
Enabling branch protection rules would add an additional layer of security by requiring status checks to pass before merging code into important branches (such as main or master). This ensures that only properly validated code is merged, reducing the risk of introducing vulnerabilities.
Static Analysis (SAST):
Integrating a Static Application Security Testing (SAST) tool, such as CodeQL in GitHub, into the CI pipeline could help detect vulnerabilities in the source code automatically. This proactive measure can identify and mitigate security issues before they escalate into problems.
Please feel free to review the PR at your convenience. I understand the tremendous effort required to maintain an open-source project, and I deeply appreciate the work you all put into HanLP. I’m happy to assist with any further improvements or clarifications.
Thank you again for your dedication to open source. I look forward to seeing HanLP continue to evolve!
Type of Change
Please check any relevant options and delete the rest.
How Has This Been Tested?
None.
Checklist
Check all items that apply.
dev
branch instead ofmaster