feat(frontend): add synthetic monitoring, edge caching, and phishing mitigation#646
Open
Vicky08100 wants to merge 1 commit into
Conversation
…ishing url validator
|
@Vicky08100 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
@GBOYEE has applied to work on this issue as part of the Stellar Wave Program's 6th wave.
ℹ️ Repo Maintainers: To accept this application, review their application or assign @GBOYEE to this issue. |
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.
Closes #611
Closes #587
Closes #578
PR Description
This PR implements three MVP-critical frontend features for the SoroTask platform. Each is a self-contained TypeScript module in
src/lib/, with a full Jest test suite and dedicated documentation file.Issue #611 - Synthetic Monitoring Script Generator
Added
SyntheticMonitoringGeneratorinsrc/lib/synthetic-monitoring.ts. It takes a declarative list of monitoring steps and generates a self-contained, Playwright-compatible TypeScript async function string. The generated function wraps every step intry/catchand returns a typedMonitoringResult({ success, timestamp, error? }), so automated pipelines get structured output instead of uncaught exceptions.Supported step types:
navigate,click,type,waitForSelector,assertText.All selector and value arguments are serialised with
JSON.stringifybefore being embedded in the generated script, which prevents string-injection attacks through crafted selector inputs. Thenavigatestep useswaitUntil: 'load'-networkidlewas considered but is officially discouraged by Playwright as brittle and slow.Time complexity is O(N) per
generateScript()call where N is the number of steps. The generator fails fast ataddStep()time (not at script generation) for invalid actions or empty targets.Issue #587 - Service Worker Edge Caching Strategy Engine
Added
EdgeCachingStrategyEngineinsrc/lib/edge-caching.ts. It implements the Stale-While-Revalidate caching strategy using the browser Cache API:Only responses that are
status 200,ok, andtype basic(same-origin) are written to cache. This deliberately excludes opaque cross-origin responses, which havestatus 0, inaccessible headers, and can bloat cache storage by ~7MB per entry in some browsers.Cache entries are evicted oldest-first when the count exceeds
maxItems(default 250). The class is instantiated once and wired into the service workerfetchevent viahandleRequest().Issue #578 — Phishing Attack Mitigation and URL Validator
Added
PhishingMitigatorinsrc/lib/phishing-mitigation.ts. It validates URLs for phishing risk using eleven independent checks, each contributing a numeric score. The score maps to a risk level:0→safe1–3→suspicious(valid, but caller should warn the user)≥ 4→dangerous(invalid,sanitizedUrlisnull)Detection layers:
javascript:,data:,vbscript:,blob:,file:— immediate score of 10.allowHttpInDevis set).xn--signal possible homograph attacks — +3.trustedDomainsallowlist — +2..tk,.ml,.ga,.cf,.gq,.xyz,.top,.work,.click— +2.redirect,url,next,goto,return,returnurl,continue,destination,forward,redir,redirect_uri— +3.user:pass@hostin URL authority — +4.The default trusted domain list covers
sorotask.app,sorolabs.xyz,stellar.org,freighter.app,stellarchain.io, and the Stellar horizon/testnet hosts.A
defaultMitigatorsingleton is exported for use anywhere in the app. The class is stateless — no DOM, no network I/O — making every code path deterministic and fully unit-testable.Change
Source files (new):
frontend/src/lib/synthetic-monitoring.ts—SyntheticMonitoringGeneratorclass; generates Playwright-compatible monitoring scripts from declarative step listsfrontend/src/lib/edge-caching.ts—EdgeCachingStrategyEngineclass; Stale-While-Revalidate service worker caching with eviction and offline fallbackfrontend/src/lib/phishing-mitigation.ts—PhishingMitigatorclass; multi-layer URL threat scoring, allowlist enforcement, anddefaultMitigatorexportTest files (new):
frontend/src/lib/__tests__/synthetic-monitoring.test.ts— 18 tests covering all step types, validation, script output, injection prevention, and instance isolationfrontend/src/lib/__tests__/edge-caching.test.ts— 13 tests covering SWR cache hit/miss, offline fallback, stale-cache fallback, eviction, and uninitialised passthroughfrontend/src/lib/__tests__/phishing-mitigation.test.ts— 37 tests covering all 11 threat detection layers,isSafe,sanitize,defaultMitigator, and result shape invariantsDocumentation files (new):
frontend/docs/synthetic-monitoring-script-generator.mdfrontend/docs/service-worker-edge-caching-strategy.mdfrontend/docs/phishing-attack-mitigation-url-validator.mdTesting
Result: 68 passed, 0 failed across 3 test suites.