Skip to content

fix: prevent stale and invalid amounts in money requirements - #318

Open
kripypastishka wants to merge 1 commit into
HelpChat:mainfrom
kripypastishka:fix/money-requirement-fail-closed
Open

kripypastishka wants to merge 1 commit into
HelpChat:mainfrom
kripypastishka:fix/money-requirement-fail-closed

Conversation

@kripypastishka

Copy link
Copy Markdown

Fix stale and invalid amounts in money requirements

Summary

Fixes an issue in HasMoneyRequirement where the amount resolved from a placeholder could persist between evaluations, potentially causing incorrect permission or economy requirement results.

Problem

Previously, the requirement stored the resolved amount in a mutable instance field.

When a placeholder returned an invalid numeric value, parsing failed, but the requirement continued evaluating using the previously stored amount.

Since requirement instances can be reused across players and evaluations, this could lead to unintended results.

Changes

  • Make the configured amount immutable.
  • Use a local requiredAmount variable for each evaluation.
  • Return false when placeholder parsing fails.
  • Reject negative, NaN, and infinite amounts.
  • Avoid parsing the same placeholder again when handling errors.

Security Impact

Prevents stale values from affecting money-based access checks and ensures that invalid amounts fail closed.

Compatibility

No configuration, database schema, or public API changes are required.

Invalid or negative amounts are now rejected instead of being passed to the economy provider.

Testing

The original and modified logic were checked using a standalone Java regression test with mocked dependencies.

Not yet verified:

  • Full Gradle build
  • GitHub Actions CI
  • Integration testing with Paper and Vault

Recommendations

Before merging, run ./gradlew build and verify both has money and !has money requirements with valid, invalid, and dynamically changing placeholder values.

Risk

Low to moderate. The change is localized to money requirement evaluation.

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.

1 participant