fix(contract): add access control to set_risk_tier — closes #50#74
Open
jobbykings wants to merge 2 commits into
Open
fix(contract): add access control to set_risk_tier — closes #50#74jobbykings wants to merge 2 commits into
jobbykings wants to merge 2 commits into
Conversation
…tier Fixes mericcintosun#50 - Add initialize(admin) function that sets a trusted admin address once - set_risk_tier now requires caller to be admin OR the user themselves - update_chosen_tier now requires the user themselves (require_auth) - Add get_admin() helper for transparency - Add 7 new auth tests covering all access paths: - test_initialize_sets_admin - test_initialize_twice_panics - test_admin_can_set_risk_tier_for_any_user - test_user_can_set_own_risk_tier - test_third_party_cannot_set_risk_tier_for_another_user - test_user_can_update_own_chosen_tier - test_third_party_cannot_update_chosen_tier - Refactor all existing tests to use setup() helper that calls initialize() Signed-off-by: Daniel Job Gonsum <danieljob003@gmail.com>
|
@jobbykings is attempting to deploy a commit to the mericcintosun Team on Vercel. A member of the Team first needs to authorize it. |
…tier Fixes mericcintosun#50 Problem: set_risk_tier had no authorization check — any address could overwrite any user's risk score, making the credit system trivially manipulable and blocking mainnet deployment. Solution: - Add initialize(admin) — sets a trusted admin address once; panics on re-initialization - Split set_risk_tier into two entry points: - set_risk_tier: user.require_auth() — user signs for themselves - admin_set_risk_tier: admin.require_auth() — oracle/backend flow - update_chosen_tier: user.require_auth() — only the user themselves - Add get_admin() transparency helper - Extract write_risk_tier() private helper to avoid duplication - Add 5 new auth tests: - test_initialize_sets_admin - test_initialize_twice_panics - test_user_can_set_own_risk_tier - test_third_party_cannot_set_risk_tier_for_another_user - test_admin_can_set_risk_tier_for_any_user - test_non_admin_cannot_call_admin_set_risk_tier - test_user_can_update_own_chosen_tier - test_third_party_cannot_update_chosen_tier - Refactor all existing tests to use setup() helper (initialize first) Note: env.invoker() does not exist in the Soroban SDK. The correct pattern is address.require_auth() on the specific principal that must sign. The 'admin OR user' pattern is implemented as two separate functions with distinct auth requirements. Signed-off-by: Daniel Job Gonsum <danieljob003@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #50 — [Security]
set_risk_tierhas no access control — any address can overwrite any user's scoreWithout authorization checks, any on-chain actor could call
set_risk_tierto manipulate any user's credit score, making the entire system untrustworthy and blocking mainnet deployment.Changes
risk_score/src/lib.rsinitialize(admin)get_admin()set_risk_tier— auth guardrequire_auth()update_chosen_tier— auth guardrequire_auth()setup()test helperinitialize+mock_all_authsso all existing tests keep passingNew tests (7)
test_initialize_sets_admintest_initialize_twice_panicstest_admin_can_set_risk_tier_for_any_usertest_user_can_set_own_risk_tiertest_third_party_cannot_set_risk_tier_for_another_user← key security testtest_user_can_update_own_chosen_tiertest_third_party_cannot_update_chosen_tier← key security testAll 18 pre-existing tests were updated to use the
setup()helper and continue to pass.Testing