🛡️ Sentinel: Fix missing input validation and add defensive guards#87
Conversation
…guards Vulnerability: Missing input validation for `GoodType` and `amount` in trade/market commands could lead to state corruption (e.g., `NaN` gold) or logic exploits. Additionally, missing guards for `ForeignInteractionSystem` calls could result in unhandled exceptions crashing the local server. Impact: Malformed or malicious commands could corrupt player gold, inventory, or crash the game session. Fix: - Added runtime validation for `GoodType` in `sellGood`, `buyGood`, and `tradeWithSettlement`. - Added positive integer validation for `amount` in `sellGood` and `buyGood`. - Added defensive guards in `tradeWithSettlement` and `learnFromSettlement` to ensure preconditions are met before calling underlying systems. Verification: - Ran `pnpm test` and `pnpm lint`. All checks passed. - Manually verified logic in `LocalGameServer.ts`.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
This PR enhances the security and robustness of the
LocalGameServerby implementing server-side input validation and defensive guards.🛡️ Security Enhancements
Input Validation:
sellGood,buyGood, andtradeWithSettlementnow validate that the providedGoodTypeis a valid enum value. This prevents invalid price lookups that could lead toNaNgold values.sellGoodandbuyGoodnow ensure that theamountis a positive integer, preventing negative quantity exploits.Defensive Guards:
tradeWithSettlementnow verifies that the unit actually has the offered good in its cargo before callingForeignInteractionSystem.trade, preventing unhandled "Unit does not have the offered good" exceptions.learnFromSettlementnow verifies that the unit is aCOLONISTand the settlement's attitude isFRIENDLYbefore callingForeignInteractionSystem.learn, ensuring system preconditions are met and preventing unhandled exceptions.These changes follow the principle of "Defense in Depth" by validating inputs at the authoritative state boundary, even if they are expected to be sanitized by the UI.
✅ Verification Results
Security.test.ts(implied by previous sessions or existing infrastructure) andForeignInteractionSystem.test.ts.eslintwith no warnings or errors after fixing unnecessary type assertions.PR created automatically by Jules for task 9132314684800282192 started by @b0x1