fix(subscription): require admin auth on init - #1500
Merged
aji70 merged 1 commit intoJul 24, 2026
Conversation
- init() now calls admin.require_auth() before persisting any config, so only the address that will become the stored admin can perform initialization. Previously init stored the admin address with no signature verification at all. - Update AUTH_MATRIX.md and the subscription README to document that init requires admin authorization. - Add test_init_requires_admin_auth_without_persisting_state, mirroring the equivalent earnings contract test: an unauthorized init attempt is rejected and leaves the contract uninitialized, then a properly authorized init succeeds. - Add sub_init_invalid_non_admin_rejected to the AUTH_MATRIX.md compliance suite (auth_matrix.rs) and rename sub_init_valid_any_caller to sub_init_valid_admin_signs to reflect the new requirement. Closes MyFanss#1376
|
@priscaenoch Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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
closes #1376
MyfansContract::init()stored the suppliedadminaddress with no signature verification at all — any caller could initialize the contract and name themselves (or anyone else) admin, since only the "already initialized" state was checked.init()now callsadmin.require_auth()immediately after the already-initialized guard and before any other validation/storage writes, so only the address that will become the stored admin can perform initialization.contract/AUTH_MATRIX.md's subscriptioninitrow: signer requirement changed fromnonetoadmin, with matching valid/invalid invocation examples.contract/contracts/subscription/README.mdto document thatinitrequires admin authorization.test_init_requires_admin_auth_without_persisting_state(insrc/test.rs), mirroring the existing, identical pattern already used for theearningscontract'sinit: an unauthorized attempt is rejected and leaves the contract uninitialized, then a properly authorizedinitsucceeds.sub_init_invalid_non_admin_rejectedto theAUTH_MATRIX.mdcompliance suite (tests/auth_matrix.rs), and renamedsub_init_valid_any_callertosub_init_valid_admin_signsto reflect the new requirement (all existing callers of this test already mock all auths, so its assertions are unaffected).All other existing
inittests (test_init_succeeds_sets_admin_and_configuration,test_init_rejects_*, property tests,contract_integration.rs, etc.) already callenv.mock_all_auths()in their setup, so they are unaffected by this change.Testing/validation performed
MyfansContract::initacrosssrc/test.rs,tests/auth_matrix.rs,tests/contract_integration.rs, andsrc/property_tests.rsto confirm each already runs undermock_all_auths()and will not break.cargo test -p subscription,cargo fmt --check, or the wasm build locally. Please confirm CI (cargo test -p subscription) passes before merging.Issue
#1376