@@ -2525,3 +2525,47 @@ function App() {
25252525
25262526// or with windowing (height and positionning constraints and bad HTML semantics)
25272527// -> x elements are rendered from the whole list once scrolled; the rest is unrendered
2528+
2529+
2530+
2531+ // SECURITY
2532+
2533+ // PREVENTING CROSS SITE SCRIPTING ATTACKS (XSS)
2534+
2535+ // Avoid getting URL data (such as query string) to write code directly in your page
2536+ // Every data coming from the URL is subject to attack !
2537+ // Make sure those URL data are treated as text only
2538+ // Or modified first -> replace all '<' and '>'
2539+ // JSX handles that for us making sure they are strings. see below
2540+ function Print ( ) {
2541+ const qs = new URLSearchParams ( window . location . search ) ;
2542+ const bug = {
2543+ title : decodeURIComponent ( qs . get ( 't' ) ) ,
2544+ severity : decodeURIComponent ( qs . get ( 's' ) ) ,
2545+ description : decodeURIComponent ( qs . get ( 'd' ) ) ,
2546+ } ;
2547+ return (
2548+ < div >
2549+ < h1 > { bug . title } </ h1 >
2550+ < h3 > { bug . severity } </ h3 >
2551+ < p > { bug . description } </ p >
2552+ </ div >
2553+ ) ;
2554+ }
2555+
2556+ // Links can take malicius javascript too inside href
2557+ // pay attention not to take anything from url parameters
2558+ // or add tests such as below
2559+ export function getBackUrl ( ) {
2560+ const qs = new URLSearchParams ( window . location . search ) ;
2561+ const backUrl = qs . get ( 'backUrl' ) ;
2562+ try {
2563+ const url = new URL ( backurl ) ;
2564+ if ( url . protocol . toLowerCase ( ) !== 'http:' ) {
2565+ backUrl = null ;
2566+ }
2567+ } catch {
2568+ backUrl = null ;
2569+ }
2570+ return backUrl ;
2571+ }
0 commit comments