feat: expose top-level url_risk field on /predict, wire frontend to it (#822)#844
Open
Rudra-clrscr wants to merge 2 commits into
Open
feat: expose top-level url_risk field on /predict, wire frontend to it (#822)#844Rudra-clrscr wants to merge 2 commits into
Rudra-clrscr wants to merge 2 commits into
Conversation
Userunknown84#822) Most of what issue Userunknown84#822 asks for already existed server-side: domain extraction, WHOIS-based domain age, DNSBL blacklist checks (Spamhaus ZEN/DBL, SpamCop, Barracuda), URLhaus/Google Safe Browsing/VirusTotal threat intel, and suspicious-TLD/IP-based-URL heuristics all already fed into domain_checker.py's `domain_analysis`, computed for every /predict call but never surfaced as a dedicated, top-level risk field. - api.py: make_prediction_response now derives a thin `url_risk` field ({is_url_present, score, level}) from the existing domain_analysis whenever it's present, leaving domain_analysis itself completely unchanged (verified live against real WHOIS/DNSBL lookups: a no-URL message returns {is_url_present: false, score: 0, level: "SAFE"}, and "http://bit.ly/..." returns is_url_present: true with the domain's real, live-looked-up risk score/level). - frontend/src/components/URLPreview.jsx: now accepts a `urlRisk` prop and prefers it (mapping SAFE/WARNING/BLOCK to the component's existing safe/warning/danger status vocabulary) over its old hardcoded shortener/keyword stub, which only ran client-side and was never connected to the real backend signal. Falls back to the local heuristic when hovering before a prediction has run. - App.jsx: added urlRisk state, populated from the /predict response, reset alongside the other prediction state, and passed to URLPreview. - README: new "URL / Phishing Risk Detection" section documenting the full signal chain (WHOIS age, DNSBL, threat intel, heuristics), the url_risk schema, and the optional SAFE_BROWSING_API_KEY/ VIRUSTOTAL_API_KEY env vars - none of which were documented as a distinct feature before. - backend/tests/test_url_risk.py: new tests covering url_risk absent vs. present, both derived correctly from mocked domain_checker results, plus direct unit tests of make_prediction_response's derivation logic and its omission when no domain_analysis is present (backward compat). App.jsx and ManipulationIndex.jsx also carry the same parse-error fixes already submitted in the pending frontend-eslint-errors PR (duplicate `function App()`, unclosed div, undefined analyzeEmojis reference, stray non-JS line) - needed here too since this branch also forks from upstream/main before that fix lands, and this feature requires editing App.jsx.
|
Someone is attempting to deploy a commit to the Aditya Sharma's projects Team on Vercel. A member of the Team first needs to authorize it. |
The container's Flask process defaults to FLASK_HOST=127.0.0.1 (a deliberate secure default for bare-metal runs), so inside the CI container it never listens on an interface reachable through the -p 5000:5000 port mapping, and the smoke test's curl always times out. docker-compose.yml already sets FLASK_HOST=0.0.0.0 for the same reason; the CI workflow's docker run step needs the same override.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #822.
Investigation showed most of this feature already existed server-side:
domain extraction, WHOIS-based domain age, DNSBL blacklist checks (Spamhaus
ZEN/DBL, SpamCop, Barracuda), URLhaus/Google Safe Browsing/VirusTotal threat
intel, and suspicious-TLD/IP-based-URL heuristics were all already feeding
into
domain_checker.py'sdomain_analysis, computed on every/predictcall but never surfaced as a dedicated top-level risk field.
api.py:make_prediction_responsenow derives a thinurl_riskfield (
{is_url_present, score, level}) from the existingdomain_analysiswhenever it's present.domain_analysisitself iscompletely unchanged (backward compatible).
URLPreview.jsx: now accepts aurlRiskprop and prefers it (mappingSAFE/WARNING/BLOCKto the component's existing safe/warning/dangervocabulary) over its old hardcoded shortener/keyword stub, which only ran
client-side and was never connected to the real backend signal. Falls
back to the local heuristic when hovering before a prediction has run.
App.jsx: addedurlRiskstate, populated from the/predictresponse, reset alongside the other prediction state, passed to
URLPreview.full signal chain and the optional
SAFE_BROWSING_API_KEY/VIRUSTOTAL_API_KEYenv vars, which weren't documented as a distinctfeature before.
backend/tests/test_url_risk.py: new tests coveringurl_riskabsent vs. present (derived from mocked
domain_checkerresults), plusdirect unit tests of
make_prediction_response's derivation logic andits omission when no
domain_analysisis present.Note:
App.jsxandManipulationIndex.jsxalso carry the same parse-errorfixes already submitted in the pending
fix/frontend-eslint-errorsPR(duplicate
function App(), unclosed div, undefinedanalyzeEmojisreference, stray non-JS line) — needed here too since this branch also
forks from
upstream/mainbefore that fix lands, and this feature requiredediting
App.jsx. Will need reconciling with whichever PR merges first.Test plan
cd backend && pytest tests/test_url_risk.py -q— 5/5 pass/predict:"url_risk":{"is_url_present":false,"level":"SAFE","score":0}"...at http://bit.ly/abc123"→ real WHOIS lookup (age_days: 6630,creation_date: 2008-05-17), real DNSBL checks,
url_riskcorrectlyderived from the live result
cd frontend && npx vite build— succeedsnpx eslinton all touched frontend files — clean