Skip to content

feat: Add Input Validation and Improve Error Handling for SDK Security - #2

Open
adityajha2005 wants to merge 1 commit into
campaign-layer:mainfrom
adityajha2005:main
Open

feat: Add Input Validation and Improve Error Handling for SDK Security#2
adityajha2005 wants to merge 1 commit into
campaign-layer:mainfrom
adityajha2005:main

Conversation

@adityajha2005

Copy link
Copy Markdown

Summary

This PR enhances the security and robustness of the Origin SDK by adding comprehensive input validation to all public API methods and improving error handling. These changes prevent invalid inputs from reaching the API layer, reducing the risk of failures, data exposure, or unexpected behavior in the public SDK.

Changes Made

  • Input Validation: Added strict validation for all user inputs in SpotifyAPI and TwitterAPI classes:
    • API keys must be non-empty strings
    • Spotify IDs, album IDs, playlist IDs must be non-empty strings
    • Twitter usernames must match format (1-15 chars, alphanumeric + underscore)
    • Tweet IDs must be numeric strings
    • Wallet addresses must match Ethereum format (0x + 40 hex chars)
    • Page/limit parameters must be positive integers within bounds
  • Error Handling: Introduced ValidationError class for consistent error messaging without exposing internal details
  • Test Updates: Updated test suites to use valid data and mock API calls where needed
  • Code Quality: All changes maintain backward compatibility and improve type safety

Testing

  • All 34 tests pass, including new validation test suite
  • Input validation correctly rejects invalid data
  • Mocked API calls prevent real network dependencies in tests
  • Build process completes successfully

Security Impact

  • Prevents injection attacks and invalid API calls
  • Reduces risk of data leakage through error messages
  • Enhances trust for public SDK users

Breaking Changes

None - All changes are additive and maintain existing API contracts.

Attached Screenshot's of the test Suites and npm build

image image

@adityajha2005

Copy link
Copy Markdown
Author

@1marcghannam @andithemudkip @boidushya let me know, if any changes needed in this pr

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