Skip to content

fix(contract): add access control to set_risk_tier — closes #50#74

Open
jobbykings wants to merge 2 commits into
mericcintosun:mainfrom
jobbykings:fix/issue-50-set-risk-tier-access-control
Open

fix(contract): add access control to set_risk_tier — closes #50#74
jobbykings wants to merge 2 commits into
mericcintosun:mainfrom
jobbykings:fix/issue-50-set-risk-tier-access-control

Conversation

@jobbykings

Copy link
Copy Markdown

Summary

Fixes #50[Security] set_risk_tier has no access control — any address can overwrite any user's score

Without authorization checks, any on-chain actor could call set_risk_tier to manipulate any user's credit score, making the entire system untrustworthy and blocking mainnet deployment.

Changes

risk_score/src/lib.rs

What Why
initialize(admin) Sets a trusted admin address once; panics on re-initialization
get_admin() Transparency helper to read the stored admin
set_risk_tier — auth guard Requires caller to be admin OR the user themselves via require_auth()
update_chosen_tier — auth guard Requires the user themselves via require_auth()
setup() test helper Calls initialize + mock_all_auths so all existing tests keep passing

New tests (7)

  • 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 ← key security test
  • test_user_can_update_own_chosen_tier
  • test_third_party_cannot_update_chosen_tier ← key security test

All 18 pre-existing tests were updated to use the setup() helper and continue to pass.

Testing

cd risk_score
cargo test

Note: Rust/Cargo is not available in the CI environment of this fork. The contract compiles and all tests pass locally with soroban-sdk 22.

…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>
@vercel

vercel Bot commented Apr 29, 2026

Copy link
Copy Markdown

@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>
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.

[Security] set_risk_tier has no access control — any address can overwrite any user's score

1 participant