Course contentsShow
← Security
Lesson 1154 of 3,05224. Application Security - Input ValidationFree lesson

Semantic and Business Logic Validation

Apply business rule validation to ensure input makes sense in the application context beyond syntax checks.

Semantic and Business Logic Validation

What you'll learn: How to validate that input doesn't just look right syntactically, but actually makes sense for your application's business rules.


Data can pass all format checks and still be completely wrong for your application. Semantic and business logic validation ensures that input is not only properly formatted, but also logically valid within your application's context and business rules.

Beyond Syntax: Meaning Matters

Think of it like a birthday invitation. The date "February 30, 2024" passes basic format validation (it's formatted as a date), but it's semantically invalid—February never has 30 days. Similarly, "January 15, 2020" might be syntactically perfect but violates business logic if you're scheduling future appointments.

What Semantic Validation Checks

Semantic validation verifies that data makes logical sense:

  • Range constraints: Is the quantity between 1 and 999?
  • Relationship rules: Is the end date after the start date?
  • State consistency: Can a user cancel an order that's already shipped?
  • Business invariants: Is the discount percentage within allowed limits for this customer tier?

Real-World Example

A flight booking system might validate:

  1. Format check: Departure date matches YYYY-MM-DD ✓
  2. Semantic check: Date is not in the past ✓
  3. Business logic check: Date falls within the booking window (not more than 11 months ahead) ✓

Someone trying to book a flight for yesterday or three years from now passes format validation but fails semantic/business validation. These checks prevent both honest mistakes and malicious manipulation (like negative quantities to get refunds).

Where to Apply It

Perform semantic validation immediately after format validation, still on the server side. Never rely solely on client-side checks—attackers bypass those easily.

Key Takeaway: Semantic and business logic validation ensures input is not just well-formed, but actually makes sense in your application's real-world context—catching both errors and attacks that format checks miss.