API Reference - Security¶
instapay_eg.security
¶
Security validation utilities for InstaPay links.
This module provides tools to verify that a URL is a legitimate, official
InstaPay link - not a phishing or lookalike-domain attack. It is the
security core of the instapay-eg SDK.
SecurityReport
dataclass
¶
Machine-readable result of a full security audit on a URL.
Attributes:
| Name | Type | Description |
|---|---|---|
is_safe |
bool
|
|
scheme_valid |
bool
|
|
domain_valid |
bool
|
|
has_injection |
bool
|
|
phishing_risk |
bool
|
|
url |
str
|
The original URL that was audited. |
failure_reason |
str | None
|
Human-readable explanation of the first failure, or
|
Source code in src/instapay_eg/security.py
is_safe_link
¶
Return True if url is a secure, official InstaPay link.
This is the fast-path check used internally by parse_text. For a
full breakdown of why a link fails, use audit_link instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL string to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
PhishingLinkError
|
When the URL's domain matches a known phishing pattern (a positive signal of an attack, not just an invalid URL). |
Example
is_safe_link("https://ipn.eg/S/alice/instapay/abc123") True is_safe_link("http://ipn.eg/S/alice/instapay/abc123") False
Source code in src/instapay_eg/security.py
audit_link
¶
Perform a full security audit on url and return a structured report.
This is the recommended function to call when you want to log the specific reason a link was rejected - for example, in a fraud-detection pipeline or a Django admin dashboard.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL string to audit. May be empty or malformed. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
A |
SecurityReport
|
class: |
SecurityReport
|
an |
Example
report = audit_link("https://ipn.eg.evil.com/S/alice/instapay/x") report.phishing_risk True report.is_safe False
Source code in src/instapay_eg/security.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
is_phishing_domain
¶
Return True if the URL's domain matches a known phishing pattern.
Use this when you want to distinguish phishing attempts from simply invalid URLs without raising an exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL string to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Example
is_phishing_domain("https://ipn.eg.evil.com/S/alice/instapay/x") True is_phishing_domain("https://ipn.eg/S/alice/instapay/x") False