Skip to content

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

Open
akordavid373 wants to merge 1 commit into
mericcintosun:mainfrom
akordavid373:fix/issue-50-set-risk-tier-access-control
Open

fix(contract): add access control to set_risk_tier (closes #50)#85
akordavid373 wants to merge 1 commit into
mericcintosun:mainfrom
akordavid373:fix/issue-50-set-risk-tier-access-control

Conversation

@akordavid373

Copy link
Copy Markdown

Summary

Fixes #50set_risk_tier had no authorization check, allowing any address to overwrite any user's risk score.

Changes

risk_score/src/lib.rs

  • Added initialize(admin: Address) — stores the admin address in instance storage once; panics if called again
  • Added get_admin() — returns the stored admin address
  • Updated set_risk_tier signature to (env, caller, user, score, tier, chosen_tier)
    • caller.require_auth() enforces on-chain signature verification
    • Asserts caller == admin || caller == user; panics with "Unauthorized" otherwise
  • All existing tests updated to call initialize via a setup() helper with mock_all_auths

risk_score/Cargo.toml

  • Added [dev-dependencies] with soroban-sdk = { version = "22.0.8", features = ["testutils"] }

Tests

3 new auth-specific tests:

Test Expected
test_admin_can_set_any_user_tier ✅ passes
test_user_can_set_own_tier ✅ passes
test_stranger_cannot_set_other_user_tier ✅ panics with Unauthorized

22/22 tests pass. cargo clippy and cargo fmt clean.

…un#50)

- Add initialize(admin) to set a trusted admin address once
- set_risk_tier now requires caller == admin OR caller == user
- Add get_admin() helper
- Add testutils dev-dependency for test utilities
- Update all tests to use setup() helper with mock_all_auths
- Add 3 new auth tests: admin can set any user, user can set own,
  stranger cannot overwrite another user's score
- 22/22 tests pass, clippy clean, fmt clean

Signed-off-by: david akor <akordavid373@gmail.com>
@vercel

vercel Bot commented Apr 30, 2026

Copy link
Copy Markdown

@akordavid373 is attempting to deploy a commit to the mericcintosun Team on Vercel.

A member of the Team first needs to authorize it.

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