Summary
A business logic input validation flaw in SourceCodester Pharmacy Product Management System 1.0 allows negative values to be submitted for price and total cost when adding stock.
By abusing the txtprice and txttotalcost parameters in add-stock.php, an attacker can corrupt financial records and manipulate inventory asset values and procurement costs under normal application use flows.
Affected context
The vulnerability occurs in the stock entry workflow of the Pharmacy Product Management System, specifically in add-stock.php when users add or update inventory.
It affects deployments where user-supplied financial fields such as txtprice and txttotalcost are trusted without enforcing domain-specific constraints (e.g., non-negative values, reasonable ranges).
The issue is most relevant in environments where staff, partners, or integrated systems can submit stock entries and where those entries feed into accounting, reporting, or inventory valuation processes.
Exploit preconditions
- Attack surface: Web application stock management interface (
add-stock.php). - Required access: Ability to submit stock entry forms (typically authenticated user or anyone with access to the inventory management feature).
- Trigger point: Submission of stock records with negative values for
txtpriceand/ortxttotalcost. - Why exploitation is possible: The application performs minimal or no server-side validation of these fields and does not enforce logical business rules (such as non-negative prices and costs), allowing crafted values to be accepted and stored.
Why this happens
The root cause is inadequate input validation for business-critical numeric fields, mapping to CWE-20: Improper Input Validation.
While the application may syntactically accept numeric input, it fails to apply semantic constraints that reflect real-world business rules (e.g., prices and total costs should not be negative).
This lack of domain validation lets users submit values that are mathematically valid but logically impossible, leading to inconsistent financial records and exploitable discrepancies in accounting and inventory valuation logic.
Potential impact
- Manipulation of inventory asset values to appear lower or negative.
- Artificial reduction or inflation of procurement costs in financial reports.
- Corruption of accounting data, including profit/loss calculations and stock valuation.
- Potential facilitation of fraud or concealment of unauthorized stock movements.
- Disruption of downstream processes that rely on accurate financial and inventory data.
General mitigation guidance
Effective mitigation focuses on enforcing business rules at the server side and treating all client input as untrusted:
- Apply strict domain validation for financial fields, ensuring they are non-negative and within reasonable bounds.
- Enforce business constraints in centralized validation layers, not just in client-side scripts or UI controls.
- Normalize and validate all numeric inputs using server-side checks before persisting or using them in calculations.
- Implement integrity safeguards around financial and inventory operations, such as invariants (e.g., total cost = quantity × unit price and all terms non-negative).
- Use least-privilege design for user roles so that only appropriate staff can perform sensitive stock and pricing operations, reducing abuse risk.
How teams detect issues like this
Organizations can detect this kind of vulnerability using both code-centric and behavior-centric approaches:
- Static analysis / code review: Search for financial or quantity fields that are cast to numeric types and stored without range or sign checks; flag direct use of request parameters in database writes or calculations without validation.
- Business logic reviews: Perform manual walkthroughs of critical workflows (stock entry, pricing, invoicing) to confirm that business rules are explicitly enforced on the server.
- Logging and anomaly detection: Monitor inventory and financial records for anomalous negative values or out-of-range prices and costs, and generate alerts for review.
- Testing and QA: Incorporate domain-specific test cases in automated and manual testing to verify that invalid business values (e.g., negative prices) are consistently rejected.

