<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Udendu Abasili on Medium]]></title>
        <description><![CDATA[Stories by Udendu Abasili on Medium]]></description>
        <link>https://medium.com/@udenduabasili?source=rss-42f0a7ffd067------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*CmU98QQsfWo9F2ig</url>
            <title>Stories by Udendu Abasili on Medium</title>
            <link>https://medium.com/@udenduabasili?source=rss-42f0a7ffd067------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 13:29:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@udenduabasili/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Build a web vulnerability scanner with React and Flask(part 2)]]></title>
            <link>https://udenduabasili.medium.com/build-a-web-vulnerability-scanner-with-react-and-flask-part-2-22b1ffd4aaf7?source=rss-42f0a7ffd067------2</link>
            <guid isPermaLink="false">https://medium.com/p/22b1ffd4aaf7</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Udendu Abasili]]></dc:creator>
            <pubDate>Thu, 18 Feb 2021 16:20:50 GMT</pubDate>
            <atom:updated>2021-02-18T16:20:50.510Z</atom:updated>
            <content:encoded><![CDATA[<p>This is the second part of the series.</p><p><a href="https://udenduabasili.medium.com/build-a-web-vulnerability-scanner-with-react-and-flask-part-1-d9a3189dd8d3">Part1</a></p><p>We would be working with the <strong>3.0 Privacy and Confidentiality </strong>from <a href="https://www.certifiedsecure.com/checklists/cs-web-application-security-test.pdf">Certified Secure</a>. What we would be doing from that list would be scanning the URLs on our website for link and headers vulnerabilities.</p><h3>URL SCANNING</h3><p>Back in our flask app, we would be installing Selenium and web driver. <a href="https://www.selenium.dev/">Selenium</a> is a portable framework for testing web applications. Typically we would have been using the <strong>requests </strong>library, but since a lot of websites these days are built with Javascript frameworks like Angular, React, and Meteor and therefore mostly do Javascript rendering, the typically HTML web crawling with requests and Beautiful Soup won&#39;t work. The general idea of selenium is that we would be able to load and control the website we want to test automatically from our web scanner app. Webdriver in this case offers us the opportunity to make use of the latest version of Chrome browser for selenium without having to manually download it ourselves.</p><p>Create a new python package at the same level as models, routes etc called <strong>services, </strong>and then inside that package, create another one called <strong>privacy_confidentiality. </strong>Next<strong>, </strong>create another file inside the services package called login.py. Within this file, add the following</p><pre>from collections import defaultdict</pre><pre>import re</pre><pre>from time import sleep</pre><pre>import os</pre><pre>from selenium.webdriver.common.by import By</pre><pre>from selenium.webdriver.support import expected_conditions as EC</pre><pre>from selenium.common.exceptions import NoSuchElementException, TimeoutException</pre><pre>from  time import sleep</pre><pre>from math import sqrt</pre><pre>import sys</pre><pre>def login(driver, login_url: str, login_params: object):</pre><pre>&quot;&quot;&quot;Login into a website</pre><pre>Args:</pre><pre>login_url (str): The login url</pre><pre>login_params (object): The login paramters we would use to login</pre><pre>Returns:</pre><pre>login_response [object]:</pre><pre>&quot;&quot;&quot;</pre><pre>login_response = {}</pre><pre>error_messages = []</pre><pre>try:</pre><pre>driver.get(login_url)</pre><pre>keys = [keys for keys, values in login_params.items()]</pre><pre>form = driver.find_element(By.TAG_NAME, &#39;form&#39;)</pre><pre>inputs = form.find_elements_by_tag_name(&#39;input&#39;)</pre><pre>for key in keys:</pre><pre>try:</pre><pre>input_type = form.find_element_by_css_selector(</pre><pre>f&quot;input[name*=&#39;{key}&#39;]&quot;)</pre><pre>if(input_type):</pre><pre>input_type.send_keys(login_params[key])</pre><pre>sleep(.3)</pre><pre>except NoSuchElementException:</pre><pre>continue</pre><pre>except TimeoutException:</pre><pre>continue</pre><pre>sleep(2)</pre><pre>button = form.find_element_by_css_selector(&quot;input[type=&#39;submit&#39;]&quot;)</pre><pre>button.submit()</pre><pre>sleep(2)</pre><pre>current_url = driver.current_url</pre><pre>if current_url == login_url:</pre><pre>errors = driver.find_elements_by_css_selector(&quot;[class*=&#39;error&#39;]&quot;)</pre><pre>if(len(errors) &gt; 0):</pre><pre>for e in errors:</pre><pre>error_messages.append(e.text)</pre><pre>login_response[&#39;login_success&#39;] = False</pre><pre>login_response[&#39;error_messages&#39;] = error_messages</pre><pre>else:</pre><pre>login_response[&#39;login_success&#39;] = True</pre><pre>else:</pre><pre>login_response[&#39;login_success&#39;] = True</pre><pre>print(login_response, file=sys.stderr)</pre><pre>return login_response</pre><pre>except Exception as e:</pre><pre>login_params[&#39;login_success&#39;] = False</pre><pre>login_params[&#39;error_messages&#39;] = e</pre><pre>return login_response</pre><p>There are few comments added to this file, but the general idea is that this function would be responsible for going to the login URL of the website we want to scan (the user would provide a separate URL login link), getting the form tag from within that page and then getting an array of the inputs tags inside the form. The login parameters object we would be taking in as arguments would contain keys called password, username, and email and then we would loop through those keys to find the inputs within our array of inputs that have substrings matching the name value of the input. This is achieved with the help of this selector already in our function above.</p><p><strong>Note: you can also search with input type instead of name</strong></p><pre>input_type = form.find_element_by_css_selector(</pre><pre>f&quot;input[name*=&#39;{key}&#39;]&quot;)</pre><p>To prevent our loop from breaking, we added <strong>NoSuchElementException </strong>to skip situations where the sub-string of the key couldn&#39;t be found in any input. <strong>TimeoutException </strong>is not really necessary but it is in case it is taking too long to find the input. The point of the sleep function is to add a little delay to compensate for the fact the components of the websites would take a little while to fully load. Next, we find the input button of type <strong>submit </strong>and then use the submit action to submit the form. Instead of using the sleep function, we can also use <strong>WebDriverWait </strong>which has both an explicit and implicit wait. For the explicit wait, we can wait till a certain condition is met i.e till we find a certain element on the current page. For example</p><pre>WebDriverWait(driver, timeout).until(<strong>lambda</strong> driver: driver.find_element_by_css_selector(&quot;input[type=&#39;submit&#39;]&quot;</pre><pre>))</pre><ul><li>Driver — this is the web driver we would be using to run selenium. we have not created it yet but not that the login function also uses this driver as a parameter</li><li>Timeout — how long to wait till the condition is met before exiting this wait function</li></ul><p>Typically when you login successfully, you get redirected to a new page. We get the current page we are on and compare it with the login page to see if we have logged in successfully.</p><pre>current_url = driver.current_url</pre><pre>if current_url == login_url:</pre><p>If the condition is not met, then we have logged in successfully. We add a key <strong>login_success </strong>to object called<strong> login_response with value True</strong></p><p>If We haven&#39;t logged in successfully, we check the current page for any error message in the HTML. We would typically see an error alert when we are unsuccessful with logging into a website saying ‘wrong password, wrong email, etc’, and in most cases, it would have an error class name or id. We search for this using</p><pre>errors = driver.find_elements_by_css_selector(&quot;[class*=&#39;error&#39;]&quot;)</pre><pre>if(len(errors) &gt; 0):</pre><pre>for e in errors:</pre><pre>error_messages.append(e.text)</pre><pre>login_response[&#39;login_success&#39;] = False</pre><pre>login_response[&#39;error_messages&#39;] = error_messages</pre><pre>else:</pre><pre>login_response[&#39;login_success&#39;] = True</pre><p><strong>Note: only the append function is looped through in the ‘for loop’.</strong></p><p>The e.text would be the text content of the e element. Finally, if we catch any error using the main try and except we return the error and set login_success as False too.</p><p>Now we go to the<strong> __init__ file </strong>in the privacy_confidentiality folder. Create a class called <strong>PrivacyConfidentialityTest.</strong></p><p>Import the following</p><pre>import re</pre><pre>import requests</pre><pre>from selenium import webdriver</pre><pre>from webdriver_manager.chrome import ChromeDriverManager</pre><pre>from selenium.common.exceptions import  WebDriverException</pre><pre>from .url_header_test import URLHEADERTEST</pre><pre>from multiprocessing import Process, Queue</pre><pre>import sys</pre><p>We have not yet created the url_header_test file so you should create it now in the same folder. Inside the current class add the following,</p><pre>def __init__(self, app, url, login_required=False, login_params={}, login_url=&#39;&#39;):</pre><pre>self.url = url</pre><pre>self.urls = []</pre><pre>self.login_required = login_required</pre><pre>self.login_url = login_url</pre><pre>self.app = app</pre><pre>self.login_params = login_params</pre><pre>self.driver = &#39;&#39;</pre><pre>self.url_with_protocol = &#39;&#39;</pre><pre>self.initialize_driver()</pre><p>the create a function called self_url_certification</p><pre>def set_url_certificate(self):</pre><pre>&quot;&quot;&quot;</pre><pre>Sets the application layer protocol for the link i.e http or https</pre><pre>&quot;&quot;&quot;<br>self.app.logger.info(&#39;Setting the website protocol&#39;)</pre><pre>if (bool(re.match(r&#39;^https?:\/\/&#39;, self.url))):</pre><pre>self.url_with_protocol = self.url</pre><pre>return</pre><pre>try:</pre><pre>requests.get(f&quot;https://{self.url}&quot;)</pre><pre>self.url_with_protocol = f&quot;https://{self.url}&quot;</pre><pre>self.login_url = f&quot;https://{self.login_url}&quot;</pre><pre>except requests.exceptions.ConnectionError:</pre><pre>print(&#39;https error&#39;)</pre><pre>self.url_with_protocol = f&quot;http://{self.url}&quot;</pre><pre>self.login_url = f&quot;https://{self.login_url}&quot;</pre><p>The first I want to talk about in the above function is the <strong>self.app.logger.info(‘Setting the website protocol’). </strong>We would be passing the app we created with app =Flask() as a parameter to use the logger function that Flask provides by default to create logs</p><p>In the above function, we want to make sure the link we pass to selenium to load has either http or https at the beginning. If it already contains it, we exit the function. If not we use requests.get to call the website with HTTPS added to the beginning. A successful call means that the website uses HTTPS and the unsuccessful call returns <strong>requests.exceptions.ConnectionError. </strong>This can either mean no HTTPS or the website does not exist, but for now, we would assume just no HTTP. we would handle the none existence of the website error in the next function.</p><pre>def initialize_driver(self):</pre><pre>self.set_url_certificate()</pre><pre>url = self.url_with_protocol</pre><pre>try:</pre><pre>options = webdriver.ChromeOptions()</pre><pre>self.driver = webdriver.Chrome(</pre><pre>ChromeDriverManager().install(), options=options)</pre><pre>self.driver.get(url)</pre><pre>except WebDriverException as e:</pre><pre># print(&#39;The link you have provided is invalid&#39;, file=sys.stderr)</pre><pre>self.driver.quit()</pre><pre>raise Exception(&#39;The link you have provided is invalid&#39;)</pre><pre>except Exception as e:</pre><pre>print(e, &quot;ex&quot;)</pre><p>This is where we initialize our web driver that would run selenium. ChromeDriverManager().install() is used to install the chrome driver we would be used automatically instead of manually downloading it and setting the path. In terms of options, you can set things like using headless, no sandbox, etc. Check the <a href="https://www.selenium.dev/documentation/en/getting_started/">Selenium Documentation </a>to learn more about selenium. We would store the drive in the self. drive variable to use throughout the class. Then we run the self.driver.get to access the website. the <strong>WebDriverException </strong>shows up if selenium cannot access the website (i.e the website does not exist) and we exit the driver and through the Exception error (which would be caught by the function we would create later in our routes).</p><p>Before we create the next function, let&#39;s create the URLTEST class in the url_test.py file. Import</p><pre>import re<br>from selenium.webdriver.common.by import By<br>from ..login import login<br>import requests</pre><pre>import sys</pre><pre>class URLHEADERTEST:</pre><pre>&quot;&quot;&quot;Test website for url strings and tls related information</pre><pre>&quot;&quot;&quot;</pre><pre>def __init__(self, app, url: str,  driver):</pre><pre>self.url = url</pre><pre>self.driver = driver</pre><pre>self.app = app</pre><pre>self.urls = []</pre><pre>self.header_data = []</pre><pre>Then we create get_all_urls function to get all the links in our website and we would also login if necessary </pre><p>Next, we create get_all_urls function to get all the links on the current page of the website we are on. We would also be checking to see if login is necessary</p><pre>ef get_all_urls(self,</pre><pre>login_url,</pre><pre>login_in_required: bool=False,</pre><pre>login_params: object={}):</pre><pre>error = &#39;&#39;</pre><pre>try:</pre><pre>if(login_in_required):</pre><pre>response = login(self.driver, login_url,</pre><pre>login_params)</pre><pre>if(response[&#39;login_success&#39;] == False):</pre><pre>raise AssertionError(response[&#39;error_messages&#39;])</pre><pre>links = self.driver.find_elements(By.TAG_NAME, &#39;a&#39;)</pre><pre>for link in links:</pre><pre>link = link.get_attribute(&#39;href&#39;)</pre><pre>self.urls.append(link)</pre><pre>except AssertionError as e:</pre><pre>error = e.args[0]</pre><pre>return error</pre><pre>except Exception as e:</pre><pre>error = e.args[0]</pre><pre>return error</pre><p>By is another method in selenium to conditionally get element(s) by id, class etc. Also, note that we only return values if there is an error. We would be using this to check if this function contains an error or not. If it is successful, the self.URLs would be populated with links from our current HTML</p><p>Now create the function that would scan the links we have stored in the array for sensitive information. These would be either email, dates(dob), Social security number, or JWT token. We would be using regex for this. I cannot teach regex here so you can just copy the regex listed or ask online for explanations. But basically, we loop through our links and check if any of them matches any of the regexes.</p><pre>def test_url_for_sensitive_info(self):</pre><pre>&quot;&quot;&quot;Test url for sensitive information</pre><pre>&quot;&quot;&quot;</pre><pre>all_urls_are_safe = True</pre><pre>error_type = []</pre><pre>ssn_regex = r&quot;^\d{3}-?\d{2}-?\d{4}$&quot;</pre><pre>email_regex = r&#39;.+@.+&#39;</pre><pre>token_regex = r&#39;^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$&#39;</pre><pre>date_regex = r&#39;[0-9]{2}/[0-9]{2}/[0-9]{4}&#39;</pre><pre>date_regex = r&#39;[0-9]{2}-[0-9]{2}-[0-9]{4}&#39;</pre><pre>for link in self.urls:</pre><pre>if (re.search(ssn_regex, link)):</pre><pre>error_type.append(&#39;ssn error&#39;)</pre><pre>if (re.search(email_regex, link)):</pre><pre>error_type.append(&#39;email error&#39;)</pre><pre>if (re.search(token_regex, link)):</pre><pre>error_type.append(&#39;token error&#39;)</pre><pre>if (re.search(date_regex, link)):</pre><pre>error_type.append(&#39;dob error&#39;)</pre><pre>if(re.search(ssn_regex, link) or</pre><pre>re.search(date_regex, link) or</pre><pre>re.search(token_regex, link) or</pre><pre>re.search(email_regex, link)):</pre><pre>all_urls_are_safe = False</pre><pre>return all_urls_are_safe, error_type</pre><p>Then in the same class, we want to create a function that runs a couple of error handlers that would check if the headers of our links contain certain important parameters. These would involve testing for the vulnerability of your links to XSS, CSRF amongst other things</p><pre>def test_security_data_transmission(self):</pre><pre>for url in self.urls:</pre><pre>self.app.logger.info(f&quot;Scanning {url}.....&quot;)</pre><pre>header_info = []</pre><pre>header_errors = []</pre><pre>try:</pre><pre>request = requests.get(url, timeout=3)</pre><pre>try:</pre><pre>##Test for guard against mime-type attacks</pre><pre>options_content_type = request.headers[&#39;X-Content-Type-Options&#39;]</pre><pre>if options_content_type != &#39;nosniff&#39;:</pre><pre>header_errors.append(&#39;X-Content-Type-Options not set properly, it should be set to no sniff&#39;,)</pre><pre>except:</pre><pre>header_errors.append(&#39;X-Content-Type-Options not found in header&#39;)</pre><pre>#test for reinforced https</pre><pre>try:</pre><pre>transport_security = request.headers[&#39;Strict-Transport-Security&#39;]</pre><pre>header_info.append(transport_security)</pre><pre>except:</pre><pre>header_errors.append(&quot;&quot;&quot;</pre><pre>HSTS header not current present for this link,</pre><pre>It is very prone to a Man in the middle attack</pre><pre>&quot;&quot;&quot;)</pre><pre>##Test for guard against cross-site scripting attacks</pre><pre>try:</pre><pre>content_security = request.headers[&#39;Content-Security-Policy&#39;]</pre><pre>header_info.append(&#39;Content-Security-Policy present for the link&#39;)</pre><p>Now in our init file in the PrivacyConfidentialityTest class add the function</p><pre>def run(self, type=&#39;&#39;):</pre><pre>try:</pre><pre>url = URLHEADERTEST(self.app, self.url, self.driver)</pre><pre>res = url.get_all_urls(</pre><pre>self.login_url,</pre><pre>login_in_required=self.login_required,</pre><pre>login_params=self.login_params</pre><pre>)</pre><pre>if(res is None):</pre><pre>all_urls_are_safe, error_type = url.test_url_for_sensitive_info()</pre><pre>else:</pre><pre>all_urls_are_safe = False</pre><pre>error_type = res</pre><pre>url_test = all_urls_are_safe, error_type</pre><pre>header_test = []</pre><pre>return [url_test, header_test]</pre><pre>self.app.logger.info(&#39;Starting test&#39;)</pre><pre>url_test = all_urls_are_safe, error_type</pre><pre>header_test = url.test_security_data_transmission()</pre><pre>return [url_test, header_test]</pre><p>In the above function, we search to make sure we get no response from get_all_urls (i.e there was no error getting the links) before we move on to testing the header and the URL security of the links</p><p>Now let&#39;s go to the routes package init file and add the route using the Privacy class</p><pre>#routes/_init_.py<br>from .. import  app</pre><pre>from flask import jsonify, request</pre><pre>from  ..service.privacy_confidentiality import PrivacyConfidentialityTest</pre><pre>import sys</pre><pre>@app.route(&#39;/api/privacy-test&#39;, methods=[&#39;POST&#39;])</pre><pre>def privacy_test():</pre><pre>try:</pre><pre>res = request.json</pre><pre>url = res[&#39;url&#39;]</pre><pre>login_url = res[&#39;userData&#39;][&#39;loginUrl&#39;]</pre><pre>login_params= res[&#39;userData&#39;]</pre><pre>login_required = res[&#39;loginRequired&#39;]</pre><pre>provide = PrivacyConfidentialityTest(app, url, login_required, login_params, login_url)</pre><pre>[url_test, header_test] = provide.run()</pre><pre>res = {</pre><pre>&quot;urlTest&quot;: url_test,</pre><pre>&quot;headerTest&quot;: header_test</pre><pre>}</pre><pre>return jsonify(e=200, text=res), 200</pre><pre>except Exception as e:</pre><pre>print(e, file=sys.stderr)</pre><pre>return jsonify(e=500, text=str(e)), 500</pre><p>The exception would catch the error we created earlier due to the driver.get not being able to access the link amongst any other errors that would originate in the route function above. We also pass the app as a parameter as I said earlier.</p><h3><strong>Now in React</strong></h3><p>in the src folder, create pages, component, assets folders</p><p>Then in component create navigation.component.jsx file and add</p><pre>import React from &#39;react&#39;;</pre><pre>import { Nav, Navbar } from &#39;react-bootstrap&#39;;</pre><pre>import { AiFillSecurityScan } from &#39;react-icons/ai&#39;;</pre><pre>import {NavLink, useLocation} from &quot;react-router-dom&quot;;</pre><pre>function Navigation(props) {</pre><pre>const location = useLocation();</pre><pre>return (</pre><pre>&lt;Navbar expand=&quot;lg&quot; bg=&quot;dark&quot; variant=&quot;dark&quot; className=&#39;py-4 &#39;&gt;</pre><pre>&lt;Navbar.Brand exact as={NavLink} to=&quot;&quot;&gt;</pre><pre>&lt;AiFillSecurityScan /&gt;</pre><pre>Traffic Shark</pre><pre>&lt;/Navbar.Brand&gt;</pre><pre>&lt;Navbar.Toggle aria-controls=&quot;responsive-navbar-nav&quot; /&gt;</pre><pre>&lt;Navbar.Collapse id=&quot;responsive-navbar-nav&quot;&gt;</pre><pre>&lt;Nav className=&quot;mr-auto&quot;&gt;</pre><pre>&lt;/Nav&gt;</pre><pre>&lt;Nav&gt;</pre><pre>&lt;Nav.Link</pre><pre>as={NavLink} isActive={()=&gt; location.pathname.includes(&#39;privacy&#39;) } to=&quot;/privacy&quot;&gt;</pre><pre>Privacy and Confidentiality</pre><pre>&lt;/Nav.Link&gt;</pre><pre>&lt;Nav.Link</pre><pre>isActive={()=&gt; location.pathname.includes(&#39;auth&#39;)}</pre><pre>as={NavLink} to=&quot;/auth&quot;&gt;</pre><pre>Authentication and Authorization</pre><pre>&lt;/Nav.Link&gt;</pre><pre>&lt;Nav.Link</pre><pre>as={NavLink}</pre><pre>isActive={()=&gt; location.pathname.includes(&#39;crypto&#39;)}</pre><pre>to=&quot;/crypto&quot;&gt;</pre><pre>Cryptography</pre><pre>&lt;/Nav.Link&gt;</pre><pre>&lt;Nav.Link</pre><pre>as={NavLink}</pre><pre>isActive={()=&gt; location.pathname.includes(&#39;user-input&#39;)}</pre><pre>to=&quot;/user-input&quot;&gt;</pre><pre>User Input</pre><pre>&lt;/Nav.Link&gt;</pre><pre>&lt;Nav.Link</pre><pre>isActive = {</pre><pre>() =&gt; location.pathname.includes(&#39;sessions&#39;)</pre><pre>}</pre><pre>as={NavLink}</pre><pre>to=&quot;/sessions&quot;&gt;</pre><pre>Sessions</pre><pre>&lt;/Nav.Link&gt;</pre><pre>&lt;/Nav&gt;</pre><pre>&lt;/Navbar.Collapse&gt;</pre><pre>&lt;/Navbar&gt;</pre><pre>);</pre><pre>}</pre><pre>export default Navigation;</pre><p>This uses Bootstrap navigation so check out <a href="https://react-bootstrap.github.io/getting-started/introduction/">React Bootstrap</a>. The one thing not here though is <strong>useLocation. </strong>It is used with isActive to mark the link as active if the link contains a substring specified. Next we would create a folder in components folder called privacy_component with form.component.jsx , form.css and result.component.jsx files created inside.</p><p>In the CSS file add</p><pre>.form.row{</pre><pre>margin: 0;</pre><pre>}</pre><pre>.form .col-sm-4{</pre><pre>background-color: greenyellow;</pre><pre>height: auto;</pre><pre>min-height: 150vh;</pre><pre>background-size: auto;</pre><pre>}</pre><pre>@media only screen and (max-width: 800px){</pre><pre>.form .col-sm-4{</pre><pre>display: none;</pre><pre>}</pre><pre>.form .col-sm-8{</pre><pre>max-width: 100%;</pre><pre>flex-basis: 100%;</pre><pre>}</pre><pre>h1.mt-4{</pre><pre>font-size: 1.4rem!important;</pre><pre>}</pre><pre>h1.mt-4 span{</pre><pre>font-size: 1.4rem!important;</pre><pre>}</pre><pre>}</pre><pre>.accordion{</pre><pre>height: max-content;</pre><pre>margin-top: 2rem;</pre><pre>transition: all 2s ease ;</pre><pre>}</pre><pre>.accordion-wrapper{</pre><pre>display: flex;</pre><pre>flex-direction:column;</pre><pre>align-items: center;</pre><pre>margin-top: 2rem;</pre><pre>}</pre><pre>.accordion-input{</pre><pre>display:none</pre><pre>}</pre><pre>.accordion-item{</pre><pre>list-style: none;</pre><pre>overflow: hidden;</pre><pre>border-radius: 18px 19px  0 0;</pre><pre>width: 80%</pre><pre>}</pre><pre>.accordion-item:not(:last-child){</pre><pre>margin-bottom: 2rem</pre><pre>}</pre><pre>.accordion-checkbox{</pre><pre>width: 2rem;</pre><pre>height: 2rem;</pre><pre>margin: 0;</pre><pre>background-color: white;</pre><pre>cursor: pointer</pre><pre>}</pre><pre>.accordion-heading{</pre><pre>font-size: 1.3rem;</pre><pre>color: white;</pre><pre>text-transform: uppercase;</pre><pre>font-weight: bold;</pre><pre>}</pre><pre>.accordion-title{</pre><pre>width: 100%;</pre><pre>box-shadow: 0 1.4rem 4rem rgba(#000000, .2);</pre><pre>display: flex;</pre><pre>align-items: center;</pre><pre>justify-content: space-between;</pre><pre>padding: 1.5rem 2rem;</pre><pre>background-color: black</pre><pre>}</pre><pre>.panel{</pre><pre>width: 100%;</pre><pre>background: rgba(0, 0, 0, 0.315);</pre><pre>padding: 2rem;</pre><pre>}</pre><pre>.panel{</pre><pre>display:none;</pre><pre>transition: all 2s ease</pre><pre>}</pre><pre>.accordion-input:checked ~ .panel{</pre><pre>display:block</pre><pre>}</pre><pre>.accordion-checkbox::after{</pre><pre>content: &#39;&#39;;</pre><pre>position: absolute;</pre><pre>width: 10px;</pre><pre>height: 15px;</pre><pre>border: solid white;</pre><pre>border-width: 0 3px 3px 0;</pre><pre>display: none;</pre><pre>-webkit-transform: rotate(45deg);</pre><pre>-ms-transform: rotate(45deg);</pre><pre>transform: rotate(45deg);</pre><pre>}</pre><pre>.accordion-input:checked + .accordion-title .accordion-checkbox{</pre><pre>background-color: green;</pre><pre>position: relative;</pre><pre>display: flex;</pre><pre>justify-content: center;</pre><pre>align-items: center;</pre><pre>}</pre><pre>.accordion-input:checked + .accordion-title .accordion-heading{</pre><pre>color: green;</pre><pre>}</pre><pre>.accordion-input:checked + .accordion-title .accordion-checkbox::after{</pre><pre>display: block;</pre><pre>}</pre><pre>.form-group{</pre><pre>display: flex;</pre><pre>flex-direction: column;</pre><pre>}</pre><pre>h1.mt-4{</pre><pre>font-family: &#39;Montserrat&#39;, sans-serif;</pre><pre>text-transform: uppercase;</pre><pre>font-weight: bolder;</pre><pre>color: green;</pre><pre>font-size: 3rem;</pre><pre>line-height: 1.13;</pre><pre>}</pre><pre>h1.mt-4 span{</pre><pre>color: black;</pre><pre>font-size: 4rem;</pre><pre>line-height: 1.5;</pre><pre>}</pre><pre>.accordion button{</pre><pre>width: 40%;</pre><pre>margin: 2rem auto;</pre><pre>}</pre><pre>@media only screen and (max-width: 700px){</pre><pre>.accordion button{</pre><pre>width: 100%;</pre><pre>}</pre><pre>.accordion-title{</pre><pre>padding: .5rem 1rem;</pre><pre>}</pre><pre>.accordion-item{</pre><pre>width: 100%;</pre><pre>}</pre><pre>.accordion-wrapper{</pre><pre>align-items: unset;</pre><pre>margin-top: 2rem;</pre><pre>padding: 0;</pre><pre>}</pre><pre>.accordion-checkbox{</pre><pre>width: 1rem;</pre><pre>height: 1rem;</pre><pre>}</pre><pre>.badge{</pre><pre>display: none !important;</pre><pre>}</pre><pre>#header{</pre><pre>font-size: .8rem</pre><pre>}</pre><pre>}</pre><pre>.panel form{</pre><pre>margin-top: 2rem;</pre><pre>}</pre><p>In the form.component.jsx we are going to create two columns. The left one would be just an image background and the right one would contain one accordion with a form, a button, and a URL input. The accordion would have a form based on whether the link in our URL input requires a login or not. I also use <a href="https://www.npmjs.com/package/react-toastify">react-toastify</a> for error notifications. I also created a loading component that is shown when the click the button to make a post request to our Flask and closes when we get a response</p><pre>import React,{useState} from &#39;react&#39;</pre><pre>import { Row, Col, Form, InputGroup, FormControl, Button } from &#39;react-bootstrap&#39;;</pre><pre>import &#39;./form.css&#39;</pre><pre>import { toast } from &#39;react-toastify&#39;;</pre><pre>import axios from &quot;axios&quot;;</pre><pre>import backgroundImage from &#39;../../assets/images/cyber-security-3400657_1920.jpg&#39;;</pre><pre>import Loading from &#39;../loading/loading.component&#39;;</pre><pre>function FormComponent({</pre><pre>history</pre><pre>}) {</pre><pre>const [loginRequired, setLoginRequired] = useState(false)</pre><pre>const [url, setUrl] = useState(&#39;&#39;)</pre><pre>const [isLoading, isLoadingHandler] = useState(false)</pre><pre>const [pickTest, pickTestHandler] = useState(false)</pre><pre>const [userData, setUserData] = useState({</pre><pre>email: &#39;&#39;,</pre><pre>loginUrl:&#39;&#39;,</pre><pre>username: &#39;&#39;,</pre><pre>password: &#39;&#39;</pre><pre>})</pre><pre>const submitHandler = () =&gt;{</pre><pre>let type;</pre><pre>const {email, loginUrl, password, username}= userData</pre><pre>if(!url){</pre><pre>toast.error(&#39;Website url cant be empty&#39;)</pre><pre>return</pre><pre>}</pre><pre>if(loginRequired){</pre><pre>if(!email || !loginUrl || !password){</pre><pre>toast.error(&#39;All url login fields except username are required&#39;)</pre><pre>return</pre><pre>}</pre><pre>}</pre><pre>if (!pickTest) {</pre><pre>toast.error(&#39;You must pick a test&#39;)</pre><pre>return;</pre><pre>}</pre><pre>isLoadingHandler(true)</pre><pre>axios({</pre><pre>method: &#39;post&#39;,</pre><pre>url: &#39;/api/privacy-test&#39;,</pre><pre>data:{</pre><pre>url,</pre><pre>userData,</pre><pre>loginRequired,</pre><pre>},</pre><pre>headers:{</pre><pre>&#39;content-type&#39;: &#39;application/json&#39;</pre><pre>}</pre><pre>})</pre><pre>.then(e =&gt; {</pre><pre>const responseHeader = e.data.text.headerTest</pre><pre>const responseUrl = e.data.text.urlTest</pre><pre>console.log(responseHeader)</pre><pre>const url = {</pre><pre>errorsInUrl: responseUrl[0],</pre><pre>errors: responseUrl[1]</pre><pre>}</pre><pre>this.props.history.push({</pre><pre>pathname: &#39;/privacy/result&#39;,</pre><pre>state: {</pre><pre>detail: {</pre><pre>url,</pre><pre>responseHeader</pre><pre>}</pre><pre>}</pre><pre>})</pre><pre>isLoadingHandler(false)</pre><pre>})</pre><pre>.catch(e =&gt; {</pre><pre>console.log(e)</pre><pre>isLoadingHandler(false)</pre><pre>toast.error(e.response)</pre><pre>})</pre><pre>}</pre><pre>const onChangeHandler = (e) =&gt; {</pre><pre>const {name, value} = e.target</pre><pre>setUserData((prevState) =&gt;({</pre><pre>...prevState,</pre><pre>[name]: value</pre><pre>}))</pre><pre>}</pre><pre>return (</pre><pre>&lt;Row className=&#39;form&#39;&gt;</pre><pre>{</pre><pre>isLoading &amp;&amp; &lt;Loading /&gt;</pre><pre>}</pre><pre>&lt;Col style={{backgroundImage: `url(https://medium.com/$%7BbackgroundImage%7D)`}} sm={4}&gt;</pre><pre>&lt;/Col&gt;</pre><pre>&lt;Col sm={8}&gt;</pre><pre>&lt;h1 class=&quot;text-center mt-4&quot;&gt;</pre><pre>Privacy and Confidentiality</pre><pre>&lt;span&gt; TEST&lt;/span&gt;</pre><pre>&lt;/h1&gt;</pre><pre>&lt;div className=&quot;accordion&quot;&gt;</pre><pre>&lt; Button variant = &quot;primary&quot;</pre><pre>className=&quot;btn btn-success&quot;</pre><pre>onClick = {</pre><pre>submitHandler</pre><pre>}</pre><pre>size = &quot;lg&quot;</pre><pre>block &gt;</pre><pre>START TEST</pre><pre>&lt;/Button&gt;</pre><pre>&lt;React.Fragment&gt;</pre><pre>&lt;label</pre><pre>style={{fontWeight: &#39;bold&#39;, fontSize: &#39;.8rem&#39;}}</pre><pre>htmlFor=&quot;text-muted&quot;&gt;</pre><pre>Link must be without https / http at the beginning</pre><pre>&lt;/label&gt;</pre><pre>&lt;InputGroup className=&quot;mb-3&quot;&gt;</pre><pre>&lt;InputGroup.Prepend&gt;</pre><pre>&lt;InputGroup.Text id=&quot;basic-addon3&quot;&gt;</pre><pre>Website url</pre><pre>&lt;/InputGroup.Text&gt;</pre><pre>&lt;/InputGroup.Prepend&gt;</pre><pre>&lt;FormControl</pre><pre>onChange={e =&gt; setUrl(e.target.value)}</pre><pre>value={url} id=&quot;basic-url&quot; aria-describedby=&quot;basic-addon3&quot; /&gt;</pre><pre>&lt;/InputGroup&gt;</pre><pre>&lt;/React.Fragment&gt;</pre><pre>&lt;ul className=&quot;accordion-wrapper&quot;&gt;</pre><pre>&lt;li className=&quot;accordion-item&quot;&gt;</pre><pre>&lt;input id=&#39;url&#39;</pre><pre>className=&quot;accordion-input&quot;</pre><pre>checked={pickTest}</pre><pre>onChange={e =&gt; pickTestHandler(e.target.checked)}</pre><pre>type=&#39;checkbox&#39;/&gt;</pre><pre>&lt;div className=&quot;accordion-title&quot;&gt;</pre><pre>&lt;span className=&quot;accordion-heading&quot;&gt;url and Header tests&lt;/span&gt;</pre><pre>&lt;label htmlFor=&quot;url&quot; className=&quot;accordion-checkbox&quot;&gt;</pre><pre>&lt;/label&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;div className=&quot;panel&quot;&gt;</pre><pre>&lt;div className=&quot;form-check&quot;&gt;</pre><pre>&lt;input</pre><pre>className=&quot;form-check-input&quot;</pre><pre>type=&quot;checkbox&quot;</pre><pre>checked={loginRequired}</pre><pre>onChange={e =&gt; setLoginRequired(e.target.checked)}</pre><pre>id=&quot;flexCheckDefault&quot;</pre><pre>/&gt;</pre><pre>&lt;label className=&quot;form-check-label&quot; for=&quot;flexCheckDefault&quot;&gt;</pre><pre>Login Required</pre><pre>&lt;/label&gt;</pre><pre>&lt;/div&gt;</pre><pre>{</pre><pre>loginRequired &amp;&amp;</pre><pre>&lt;Form&gt;</pre><pre>&lt;Form.Group controlId=&quot;formBasicUrl&quot;&gt;</pre><pre>&lt;Form.Label&gt;Login url&lt;/Form.Label&gt;</pre><pre>&lt;Form.Control</pre><pre>type=&quot;url&quot;</pre><pre>name=&#39;loginUrl&#39;</pre><pre>value={userData.loginUrl}</pre><pre>onChange={onChangeHandler}</pre><pre>placeholder=&quot;Enter the login url&quot; /&gt;</pre><pre>&lt;Form.Text className=&quot;text-muted&quot;&gt;</pre><pre>&lt;/Form.Text&gt;</pre><pre>&lt;/Form.Group&gt;</pre><pre>&lt;Form.Group controlId=&quot;formBasicEmail&quot;&gt;</pre><pre>&lt;Form.Label&gt;Email address&lt;/Form.Label&gt;</pre><pre>&lt;Form.Control</pre><pre>type=&quot;email&quot;</pre><pre>name=&#39;email&#39;</pre><pre>value={userData.email}</pre><pre>onChange={onChangeHandler}</pre><pre>placeholder=&quot;Login email&quot; /&gt;</pre><pre>&lt;Form.Text className=&quot;text-muted&quot;&gt;</pre><pre>We&#39;ll never share your email with anyone else.</pre><pre>&lt;/Form.Text&gt;</pre><pre>&lt;/Form.Group&gt;</pre><pre>&lt;Form.Group controlId=&quot;formBasicUsername&quot;&gt;</pre><pre>&lt;Form.Label&gt;Username&lt;/Form.Label&gt;</pre><pre>&lt;Form.Control</pre><pre>type=&quot;text&quot;</pre><pre>name=&#39;username&#39;</pre><pre>value={userData.username}</pre><pre>onChange={onChangeHandler}</pre><pre>placeholder=&quot;Enter username if applicable&quot; /&gt;</pre><pre>&lt;Form.Text className=&quot;text-muted&quot;&gt;</pre><pre>We&#39;ll never share your email with anyone else.</pre><pre>&lt;/Form.Text&gt;</pre><pre>&lt;/Form.Group&gt;</pre><pre>&lt;Form.Group controlId=&quot;formBasicPassword&quot;&gt;</pre><pre>&lt;Form.Label&gt;Password&lt;/Form.Label&gt;</pre><pre>&lt;Form.Control</pre><pre>type=&quot;password&quot;</pre><pre>name=&#39;password&#39;</pre><pre>value={userData.password}</pre><pre>onChange={onChangeHandler}</pre><pre>placeholder=&quot;Password&quot; /&gt;</pre><pre>&lt;/Form.Group&gt;</pre><pre>&lt;/Form&gt;</pre><pre>}</pre><pre>&lt;/div&gt;</pre><pre>&lt;/li&gt;</pre><pre>&lt;/ul&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;/Col&gt;</pre><pre>&lt;/Row&gt;</pre><pre>)</pre><pre>}</pre><pre>export default FormComponent</pre><p>The result.component.jsx file would be used to display the result from our web scanning. It would take the value we pass through the history.push above with params and display them</p><pre>import React from &#39;react&#39;</pre><pre>import {</pre><pre>Row,</pre><pre>Accordion,</pre><pre>Card,</pre><pre>Badge,</pre><pre>Col,</pre><pre>Button,</pre><pre>Container</pre><pre>} from &#39;react-bootstrap&#39;;</pre><pre>import { NavLink } from &#39;react-router-dom&#39;;</pre><pre>function Result({location}) {</pre><pre>const privacyTest = location.state.detail</pre><pre>const url = privacyTest.url;</pre><pre>const responseHeader = privacyTest.responseHeader;</pre><pre>return (</pre><pre>&lt;Container&gt;</pre><pre>&lt;div class=&quot;col text-center mt-5 mb-5&quot;&gt;</pre><pre>&lt;NavLink to=&quot;/privacy/form&quot;</pre><pre>class=&quot;btn btn-success btn-lg active&quot; role=&quot;button&quot; aria-pressed=&quot;true&quot;&gt;Change Test Url</pre><pre>&lt;/NavLink&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;h1 className=&quot;text-center mt-2&quot;&gt;RESULT&lt;/h1&gt;</pre><pre>&lt;Row&gt;&lt;/Row&gt;</pre><pre>&lt;Row style={{flexDirection :&#39;column&#39;}}&gt;</pre><pre>&lt;Col&gt;</pre><pre>&lt;h2 &gt;Url result&lt;/h2&gt;</pre><pre>&lt;p &gt;No link contains sensitive information:</pre><pre>&lt;span style={{fontWeight: &#39;bold&#39;}}&gt;</pre><pre>{url.errorsInUrl.toString()}</pre><pre>&lt;/span&gt;</pre><pre>&lt;/p&gt;</pre><pre>{</pre><pre>url.errors.length &gt; 0 &amp;&amp; (</pre><pre>&lt;React.Fragment&gt;</pre><pre>&lt;Accordion</pre><pre>style={{</pre><pre>padding: 0,</pre><pre>margin: &#39;0rem&#39;</pre><pre>}}</pre><pre>&gt;</pre><pre>&lt;Card&gt;</pre><pre>&lt;Accordion.Toggle as={Card.Header} eventKey=&quot;1&quot;&gt;</pre><pre>View Error(s)</pre><pre>&lt;/Accordion.Toggle&gt;</pre><pre>&lt;Accordion.Collapse eventKey=&quot;1&quot;&gt;</pre><pre>&lt;Card.Body&gt;</pre><pre>{url.errors.map((error) =&gt;(</pre><pre>&lt;p class = &quot;list-group-item-text&quot;&gt;{error}&lt;/p&gt;</pre><pre>))}</pre><pre>&lt;/Card.Body&gt;</pre><pre>&lt;/Accordion.Collapse&gt;</pre><pre>&lt;/Card&gt;</pre><pre>&lt;/Accordion&gt;</pre><pre>&lt;/React.Fragment&gt;</pre><pre>)</pre><pre>}</pre><pre>&lt;/Col&gt;</pre><pre>&lt;/Row&gt;</pre><pre>&lt;Row style={{flexDirection :&#39;column&#39; , marginTop:&#39;4rem&#39;}}&gt;</pre><pre>&lt;Col&gt;</pre><pre>&lt;h2&gt;Headers result&lt;/h2&gt;</pre><pre>{</pre><pre>responseHeader.map(res =&gt;(</pre><pre>&lt;Accordion</pre><pre>style={{</pre><pre>padding: 0,</pre><pre>margin: &#39;0rem&#39;</pre><pre>}}</pre><pre>defaultActiveKey=&quot;0&quot;&gt;</pre><pre>&lt;Card&gt;</pre><pre>&lt;Card.Header</pre><pre>style={{</pre><pre>display: &#39;flex&#39;,</pre><pre>justifyContent: &#39;space-between&#39;,</pre><pre>alignItems: &#39;center&#39;</pre><pre>}}&gt;</pre><pre>&lt;Accordion.Toggle</pre><pre>as={Button}</pre><pre>id=&#39;header&#39;</pre><pre>style={{</pre><pre>padding: 0,</pre><pre>margin: &#39;0rem&#39;,</pre><pre>display: &#39;flex&#39;,</pre><pre>justifyContent: &#39;space-between&#39;,</pre><pre>textAlign: &#39;left&#39;,</pre><pre>}}  variant=&quot;link&quot; eventKey=&quot;1&quot;&gt;</pre><pre>{res.url.trim()}</pre><pre>&lt;/Accordion.Toggle&gt;</pre><pre>&lt;Badge variant=&quot;danger&quot;&gt;{ res.headerErrors.length}&lt;/Badge&gt;</pre><pre>&lt;/Card.Header&gt;</pre><pre>&lt;Accordion.Collapse eventKey=&quot;1&quot;&gt;</pre><pre>&lt;Card.Body&gt;</pre><pre>{</pre><pre>res.headerErrors.map((error) =&gt;(</pre><pre>&lt;li&gt;{error}&lt;/li&gt;</pre><pre>))</pre><pre>}</pre><pre>&lt;/Card.Body&gt;</pre><pre>&lt;/Accordion.Collapse&gt;</pre><pre>&lt;/Card&gt;</pre><pre>&lt;/Accordion&gt;</pre><pre>))</pre><pre>}</pre><pre>&lt;/Col&gt;</pre><pre>&lt;/Row&gt;</pre><pre>&lt;/Container&gt;</pre><pre>)</pre><pre>}</pre><pre>export default Result</pre><p>Then in the pages folder, create privacy.pages.jsx</p><pre>import React, { Component } from &quot;react&quot;;</pre><pre>import { Switch, Route, Redirect } from &quot;react-router-dom&quot;;</pre><pre>import Form from &quot;../component/privacy-component/form.component&quot;;</pre><pre>import Result from &quot;../component/privacy-component/result.component&quot;;</pre><pre>class PrivacyConfidentialityPage extends Component {</pre><pre>render() {</pre><pre>const {match} = this.props;</pre><pre>return (</pre><pre>&lt;Switch&gt;</pre><pre>&lt;Route exact path={`${match.path}/`} render={() =&gt; (</pre><pre>&lt;Redirect to={`${match.path}/form`}/&gt;</pre><pre>)}/&gt;</pre><pre>&lt;Route path={`${match.path}/form`} component={Form}/&gt;</pre><pre>&lt;Route path={`${match.path}/result`} component={Result}/&gt;</pre><pre>&lt;/Switch&gt;</pre><pre>);</pre><pre>}</pre><pre>}</pre><pre>export default PrivacyConfidentialityPage;</pre><p>Then in App.js we import the CSS</p><pre>import React from &#39;react&#39;;</pre><pre>import Navigation from &quot;./component/navigation.component&quot;;</pre><pre>import {BrowserRouter as Router, Route, Switch, Redirect} from &#39;react-router-dom&#39;;</pre><pre>import PrivacyConfidentialityPage from &#39;./pages/privacy.page&#39;;</pre><pre>import { ToastContainer, toast } from &#39;react-toastify&#39;;</pre><pre>import &#39;react-toastify/dist/ReactToastify.css&#39;;</pre><pre>import &#39;bootstrap/dist/css/bootstrap.min.css&#39;;</pre><pre>function App() {</pre><pre>return (</pre><pre>&lt;Router&gt;</pre><pre>&lt;Navigation/&gt;</pre><pre>&lt;ToastContainer</pre><pre>position=&quot;top-center&quot;</pre><pre>autoClose={5000}</pre><pre>hideProgressBar={false}</pre><pre>newestOnTop={false}</pre><pre>closeOnClick</pre><pre>rtl={false}</pre><pre>pauseOnFocusLoss</pre><pre>draggable</pre><pre>pauseOnHover</pre><pre>/&gt;</pre><pre>&lt;Switch&gt;</pre><pre>&lt;Route exact path=&quot;/&quot; render={() =&gt; (</pre><pre>&lt;Redirect to=&quot;/privacy&quot;/&gt;</pre><pre>)}/&gt;</pre><pre>&lt;Route path=&#39;/privacy&#39; component={PrivacyConfidentialityPage}/&gt;</pre><pre>&lt;/Switch&gt;</pre><pre>&lt;/Router&gt;</pre><pre>);</pre><pre>}</pre><pre>export default App;</pre><p>At this point, we can start testing by running yarn dev in the root package.json</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22b1ffd4aaf7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a web vulnerability scanner with React and Flask(part 1)]]></title>
            <link>https://udenduabasili.medium.com/build-a-web-vulnerability-scanner-with-react-and-flask-part-1-d9a3189dd8d3?source=rss-42f0a7ffd067------2</link>
            <guid isPermaLink="false">https://medium.com/p/d9a3189dd8d3</guid>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-security]]></category>
            <category><![CDATA[ethical-hacking]]></category>
            <dc:creator><![CDATA[Udendu Abasili]]></dc:creator>
            <pubDate>Mon, 15 Feb 2021 15:56:09 GMT</pubDate>
            <atom:updated>2021-02-18T16:22:36.020Z</atom:updated>
            <content:encoded><![CDATA[<p>This first part would focus on the setup of connecting react with flask</p><h4><a href="https://udenduabasili.medium.com/build-a-web-vulnerability-scanner-with-react-and-flask-part-2-22b1ffd4aaf7?postPublishedType=initial">Part 2</a></h4><p>As a Full Stack developer, I have been using MERN stack and also using Python for Pentesting and ethical hacking but I always wanted to find a way to combine the two worlds , and I did with the help of this web application that would be detecting different types of vulnerabilities in a website. This tutorial assumes you are familiar with both React and Flask.</p><p>First things first , create a folder called traffickshark(a play on wire shark and traffic) and initialize yarn inside</p><pre>mkdir traffickshark<br>cd trafficshark<br>yarn init -y</pre><p>once it is done , install concurrently which would be used to run both flask and react in one command</p><pre>yarn add concurrently</pre><h3>React</h3><p>Inside the traffickshark folder, create a react app called front-end</p><pre>npx create-react-app front-end</pre><p>Then install the following packages</p><pre>yarn add react-bootstrap bootstrap redux react-redux react-router-dom react-redux redux redux-logger axios redux-thunk redux-persist react-icons</pre><ul><li>Bootstrap — for using Bootstrap CSS framework</li><li>Redux — for managing application state</li><li>React-router-dom — for navigation</li><li>axios — for handling rest api</li><li>React-icons — to give you access to lots of free icons</li></ul><h3><strong>Python</strong></h3><p>Note: All python packages are folders with __init__.py files with them. I am using both Pycharm and vscode for this project, but with Pycharm the init files are added automatically when creating a new package</p><p>Inside the trafficshark folder create a python package called backend trafficshark and then make a virtual environment called trafficshark-backend</p><pre>mkdir backend<br>cd backend<br>python -m venv trafficshark-backend<br></pre><p>Once that is done we would activate it and install the python packages we need inside</p><pre>trafficshark-backend\Scripts\activate</pre><pre><em>pip install flask flask-cors flask-login flask-jwt-extended flask-sqlalchemy flask-bcrypt pyjwt flask-marshmallow marshmallow-sqlalchemy  python-dotenv</em></pre><ul><li>Flask-cors — used to allow the react app to communicate with our flask without generating <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS">cors </a>error</li><li>Flask-login — would be used to handle a lot of authentication actions as you would see</li><li>Flask-jwt-extended — would be used for handling tokens related to authentication verification among other things.</li><li>Flask-bcrypt — password encryption</li><li>Flask-sqlalchemy, flask-marshamallow and marshmallow-sqlalchemy would be used for storing data in sqlite database and serializing the data when passing it from the backed to the fronted</li><li>Python-dotenv — we would be using flask enviromental file .flaskenv and this library is required to read the file</li></ul><p>Once these libraries are done installing, create files called .flaskenv, main.py .</p><p>Then create a python package called app and with this, create multiple packages called routes, models, config and middleware. Your folder structure should look like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*ypCPI0jUBqS3YZS-GWbi8w.png" /><figcaption>Project Structure</figcaption></figure><p>Within the .flaskenv , add the following</p><pre>FLASK_ENV=development<br>FLASK_DEBUG=1<br>SECRET_KEY=changene</pre><ul><li>Flask_env and Flask_debug set the current flask environment to development and turns on the debugging mode</li><li>The secret key is just a random secret key we would be using for your app</li></ul><p>Then update package.json of our traffickshark root folder</p><pre>{<br>  &quot;name&quot;: &quot;trafficshark&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;This is a  web traffic monitor application built with Flask and React and also using nginx and docker&quot;,<br>  &quot;main&quot;: &quot;index.js&quot;,<br>  &quot;author&quot;: &quot;user&quot;,<br>  &quot;license&quot;: &quot;MIT&quot;,<br>   &quot;scripts&quot;: {<br>    &quot;client&quot;: &quot;cd front-end &amp;&amp; yarn run start&quot;,<br>    &quot;server&quot;: &quot;cd ./backend &amp;&amp; SET FLASK_APP=main.py  &amp;&amp; trafficshark-backend/Scripts/flask  run &quot;,<br>    &quot;dev&quot;: &quot;concurrently --kill-others-on-fail \&quot;yarn server\&quot; \&quot;yarn client\&quot;&quot;<br>  },<br>  &quot;dependencies&quot;: {<br>    &quot;concurrently&quot;: &quot;^5.3.0&quot;<br>  }<br>}</pre><p>The focus here are the client, server and dev script commands. The client points to the React app then runs yarn run start. The server goes to the backend folder, then sets our FLASK_APP as the main.py . Once this is set, we only need to run flask with the flask from our virtual environment to start flask, but obviously we have not added anything to main.py yet.</p><p>Now for the server set up.</p><p>First of we create the config file setup. The config file would hold the various setting we would use for the app for setting up database, jwt tokens amongst other things. We had set the flask environmental above so we use the condition below to set our database uri and other values which we would update in the future</p><pre>#config/__init__.py<br><em>import </em>os</pre><pre>basedir = os.path.abspath(os.path.dirname(__file__))<br><br><em>class </em>Config(<em>object</em>):<br>    <em>if </em>os.environ[&#39;FLASK_ENV&#39;] == &#39;development&#39;:<br>        SQLALCHEMY_DATABASE_URI = &#39;sqlite:///&#39; + os.path.join(basedir, &quot;project.db&quot;)</pre><pre><em># this is to disable the signal to our app everytime a change is made to the database</em>        <br>        SQLALCHEMY_TRACK_MODIFICATIONS = <em>False<br>       </em></pre><p>Go to __init__ file for app and import and initialize all the libraries we installed for python.</p><pre><em>#app/__init__.py<br>from </em>flask <em>import </em>Flask<br><em>from </em>flask_sqlalchemy <em>import </em>SQLAlchemy<br><em>from </em>flask_marshmallow <em>import </em>Marshmallow<br><em>from </em>flask_bcrypt <em>import </em>Bcrypt<br><em>from </em>flask_jwt_extended <em>import </em>JWTManager<br><em>from </em>flask_login <em>import </em>LoginManager<br><em>from </em>flask_cors <em>import </em>CORS<br><em>from </em>.config <em>import </em>Config<br><br>app = Flask(__name__)<br>#the config class with our settings would be added to our app to use here</pre><pre>app.config.from_object(Config)<br>jwt = JWTManager(app)<br>bcrypt = Bcrypt(app)<br>cors = CORS(app)<br>ma = Marshmallow(app)<br>login = LoginManager(app)</pre><pre>#we import our packages here from the app root to prevent circular import error since we would be using the app variable in thses packages<br><em>from </em>. <em>import </em>routes, models, middleware</pre><p>Go to the routes package and we would add a test route just make sure we can connect from react.</p><pre><em>from </em>.. <em>import </em>app<br><em>from </em>flask <em>import </em>jsonify<br><br>#create the api route we would access from react<br>@app.route(&#39;/api&#39;)<br><em>def </em>home():<br>    <em>try</em>:<br>        res = {&#39;name&#39;: &#39;john&#39;}<br>#send e response to the client with status code 200 if successfully and 500 if there is an error. Turn the error to </pre><pre>        <em>return </em>jsonify(e=200, text=res), 200<br>    <em>except Exception as </em>e:<br>        <em>return </em>jsonify(e=500, text=<em>str</em>(e)), 500</pre><p>Now in the main.py file, we add</p><pre><em>#import the app package and run below<br>from </em>.app <em>import </em>app</pre><pre><br><em>if </em>__name__ == &#39;__main__&#39;:<br>    app.run(debug=<em>True</em>)</pre><p>With all these settings we have now connected the server script we defined in the main package.json .</p><p>Next, we make a simple call from out front-end to the ‘/api’ path.</p><p>Add the url for the flask backend to the front-end package.json. The default flask url is <a href="http://127.0.0.1:5000/"><em>http://127.0.0.1:5000/,</em></a><em> </em>so we add it as a proxy to our front-end package.json</p><pre>  &quot;name&quot;: &quot;front-end&quot;,<br>  &quot;version&quot;: &quot;0.1.0&quot;,<br>  &quot;proxy&quot;: &quot;http://127.0.0.1:5000/&quot;,<br>  &quot;private&quot;: <em>true</em>,</pre><p>Then go to App.js file and make a REST API call to the backend.</p><pre><em>import </em>logo <em>from </em>&#39;./logo.svg&#39;;<br><em>import </em>React <em>from </em>&#39;react&#39;;<br><em>import </em>&#39;./App.css&#39;;<br><em>import </em>axios <em>from </em>&#39;axios&#39;;<br><em>function App</em>() {<br>    <em>const </em>[value , setData] = React.<em>useState</em>(&#39;&#39;)<br>    axios.get(&#39;/api&#39;).then((response) =&gt; setData(response.data.text.name))<br>        .catch(error =&gt; console.log(error.response))<br>  <em>return </em>(<br>    &lt;div <em>className</em>=&quot;App&quot;&gt;<br>        &lt;a<br>          <em>className</em>=&quot;App-link&quot;<br>          <em>href</em>=&quot;https://reactjs.org&quot;<br>          <em>target</em>=&quot;_blank&quot;<br>          <em>rel</em>=&quot;noopener noreferrer&quot;<br>        &gt;<br>          Learn React<br>            {value}<br>        &lt;/a&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>Now to run both the React app and Flask, go the root of our project and run</p><pre>yarn dev</pre><p>To access the React app if it does not automatically come up on its own, go to the link</p><pre>localhost:3000/</pre><p>Then you should see Learn react john, confirming the communication between react and flask.</p><p>This is end of part 1. For the rest of the project, I would be creating sections of the scanner using the guide from <a href="https://www.certifiedsecure.com/checklists/cs-web-application-security-test.pdf">Certified Secure</a>. Note though that i wont be performing all the test listed there.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9a3189dd8d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>