Skip to content

Test/ssrf protection utilities - #2680

Closed
desireddymohithreddy0925 wants to merge 6 commits into
Priyanshu-byte-coder:mainfrom
desireddymohithreddy0925:test/ssrf-protection-utilities
Closed

Test/ssrf protection utilities#2680
desireddymohithreddy0925 wants to merge 6 commits into
Priyanshu-byte-coder:mainfrom
desireddymohithreddy0925:test/ssrf-protection-utilities

Conversation

@desireddymohithreddy0925

Copy link
Copy Markdown
Contributor

Fixes #2615

Summary of Changes

Added comprehensive unit tests for the pure utility functions in src/lib/ssrf-protection.ts using Vitest. The async isSafeUrl function is intentionally excluded from these tests as it requires DNS mocking.

Details:

  1. Exported Utility Functions:

    • Exported ipToNumber and isPrivateIP from src/lib/ssrf-protection.ts so they can be explicitly tested without side effects.
  2. ipToNumber Tests:

    • Validated conversion of standard IPv4 addresses.
    • Tested edge cases including 0.0.0.0 and 255.255.255.255.
    • Ensured invalid formats (non-numeric parts, out-of-range values, wrong octet count, missing octets) gracefully return NaN.
  3. isPrivateIP Tests:

    • Covered all five private IPv4 ranges (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 127.0.0.0/8, 169.254.0.0/16).
    • Covered IPv6 loopback and link-local addresses (::1, ::, fe80:, fc00:, fd00:).
    • Validated handling of IPv6-mapped IPv4 addresses (e.g., ::ffff:127.0.0.1 flagged as private, ::ffff:8.8.8.8 flagged as public).
    • Verified that boundary and public IP addresses are reliably allowed and not falsely flagged.
  4. validateUrlBasic Tests:

    • Ensured http and https URLs pass validation.
    • Verified that other unsafe protocols (ftp, data:, javascript:, file:) correctly fail.
    • Checked that malformed URLs fail safely.

Impact

  • Ensures the SSRF protection logic correctly classifies private vs. public IP ranges.
  • Validates edge cases in IPv6 and IPv4-mapped address handling.
  • Guards the URL validation baseline used before any DNS resolution occurs.

@github-actions github-actions Bot added gssoc26 GSSoC 2026 contribution type:testing GSSoC type bonus: tests (+10 pts) labels Jun 22, 2026
@github-actions

Copy link
Copy Markdown

GSSoC Label Checklist 🏷️

@Umbrella-io — please apply the appropriate labels before merging:

Difficulty (pick one):

  • level:beginner — 20 pts
  • level:intermediate — 35 pts
  • level:advanced — 55 pts
  • level:critical — 80 pts

Quality (optional):

  • quality:clean — ×1.2 multiplier
  • quality:exceptional — ×1.5 multiplier

Validation (required to score):

  • gssoc:approved — counts for points
  • gssoc:invalid / gssoc:spam / gssoc:ai-slop — does not score

Type labels (type:*) are auto-detected from files and title. Review and adjust if needed.
Points formula: (difficulty × quality_multiplier) + type_bonus

@github-actions github-actions Bot added type:bug GSSoC type bonus: bug fix type:feature GSSoC type bonus: new feature type:design GSSoC type bonus: UI/design (+10 pts) type:performance GSSoC type bonus: performance (+15 pts) labels Jun 22, 2026
@Priyanshu-byte-coder

Copy link
Copy Markdown
Owner

Closing — this PR is identical to your other submissions (#2680-#2692). All contain the same goal-category feature code despite different test titles. This is not a test PR, it's a feature addition, and submitting 13 copies is points farming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc26 GSSoC 2026 contribution type:bug GSSoC type bonus: bug fix type:design GSSoC type bonus: UI/design (+10 pts) type:devops GSSoC type bonus: devops (+15 pts) type:feature GSSoC type bonus: new feature type:performance GSSoC type bonus: performance (+15 pts) type:testing GSSoC type bonus: tests (+10 pts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test : add unit tests for ssrf-protection utility functions

2 participants