<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Manuela Redinciuc</title>
    <description>The latest articles on DEV Community by Manuela Redinciuc (@manuelare).</description>
    <link>https://dev.to/manuelare</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F581760%2F1d4628d6-0acf-422f-a7fb-97ad95bd27d6.jpg</url>
      <title>DEV Community: Manuela Redinciuc</title>
      <link>https://dev.to/manuelare</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/manuelare"/>
    <language>en</language>
    <item>
      <title>CSP - Content Security Policy basics</title>
      <dc:creator>Manuela Redinciuc</dc:creator>
      <pubDate>Wed, 19 Jan 2022 21:20:04 +0000</pubDate>
      <link>https://dev.to/manuelare/csp-content-security-policy-basics-4pf6</link>
      <guid>https://dev.to/manuelare/csp-content-security-policy-basics-4pf6</guid>
      <description>&lt;p&gt;I am fast approaching my first year working as a Software Engineer and as I contemplate the challenges I faced and my progress so far I thought I'd write about a topic I knew nothing about a year ago.&lt;br&gt;
As the team grows at Brickvest, we've introduced Friday Tech talks were we each take turns and talk about topics we find interesting.&lt;br&gt;
My first presentation was about Content Security Policies and I thought I'd write a blog post about it as well.&lt;/p&gt;

&lt;p&gt;Let's start from the beginning...&lt;/p&gt;
&lt;h2&gt;
  
  
  1. What is CSP?
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Content Security Policy (CSP) is an added layer of security that helps to detect and mitigate certain types of attacks, including Cross-Site Scripting (XSS) and data injection attacks. These attacks are used for everything from data theft to site defacement to distribute malware. - &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP"&gt;MDN Web Docs&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you are a novice like myself the definition above might be a bit unclear so I will take a step back and explain what happens during an XSS attack using the diagram below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6wegijPK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/ManuelaRE/images/main/Picture%25201.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6wegijPK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/ManuelaRE/images/main/Picture%25201.png" alt="XSS attack" width="880" height="488"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  2. Why do we need CSP?
&lt;/h2&gt;

&lt;p&gt;Web security is rooted in the same-origin policy. What that means is that code from myapp.com should only have access to myapp.com's data and other applications should never be allowed access. &lt;/p&gt;

&lt;p&gt;This is an ideal case but in reality we need to use third party apps that can potentially leave us vulnerable and attackers have found ways to break the system and exploit those vulnerabilities.&lt;/p&gt;

&lt;p&gt;In our case we have Content-Security Policies in place for third parties like Zoho and Sentry.&lt;/p&gt;

&lt;p&gt;The main reason we need a CSP is to protect our visitors from malicious code being executed on our website.&lt;/p&gt;
&lt;h2&gt;
  
  
  3. How CSP works
&lt;/h2&gt;

&lt;p&gt;This is a short example explaining how CSP works:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A user visits your website. When loading, the browser fetches the websites headers (where the CSP is specified)&lt;/li&gt;
&lt;li&gt;The browser parses the CSP and remembers which sources are allowed to be loaded.&lt;/li&gt;
&lt;li&gt;The browser now starts to load additional resources defined in your source code, like a Zoho chat, fonts, images, CSS, inline scripts, etc.&lt;/li&gt;
&lt;li&gt;Each resource is cross-referenced to the page’s CSP, and if a source is not specified, the resource is blocked.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  4. How do I implement a CSP?
&lt;/h2&gt;

&lt;p&gt;As mentioned earlier, CSP is a response header that instructs the web browser from what sources it is allowed to include and execute resources from.&lt;br&gt;
All modern browser (except IE) support Content-Security-Policy HTTP headers.&lt;/p&gt;

&lt;p&gt;The below is a very basic example of a CSP written in Python's  Quart framework that uses Sentry, Zoho and Hotjar as examples. It's important to mention that each third party you want to use will have documentation mentioning what needs to be included in order to be correctly set. &lt;a href="https://help.hotjar.com/hc/en-us/articles/115011640307-Content-Security-Policies"&gt;Here&lt;/a&gt; is an example from Hotjar.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Going through the above example you can notice that the CSP is split by type of resource. I'll go through the ones I included but you can find more examples and explanations &lt;a href="https://content-security-policy.com/"&gt;here&lt;/a&gt;. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;self&lt;/code&gt; means sources that have the same protocol as the file the content policy is defined in (our own scripts). Everything else after self represents other sources that we allow content from e.g Zoho.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;default-src&lt;/code&gt; the default policy for loading javascript, images, CSS, fonts&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;script-src&lt;/code&gt; defines valid sources for javascript files&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;style-src&lt;/code&gt; defines valid sources for css files&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;img-src&lt;/code&gt; defines valid sources for images&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;connect-src&lt;/code&gt; provides control over fetch requests&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;report_uri&lt;/code&gt; keep track of the violation reports. In our case we do that via Sentry.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5. What to avoid with CSP?
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;unsafe-inline&lt;/code&gt; keyword cancels most of the security benefits that Content-Security-Policy provides as it allows the use of inline resources, such as inline elements.&lt;/p&gt;

&lt;p&gt;Inline scripts look like this: &lt;br&gt;
&lt;code&gt;&amp;lt;script&amp;gt;alert()&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;br&gt;
compared to:&lt;br&gt;
 &lt;code&gt;&amp;lt;script src=”main.js”&amp;gt;&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Allowing this gives the CSP a much weaker protection against XSS-attacks, and it’s the reason why it's prefixed by unsafe. Having to type unsafe should be a reminder that we are doing something potentially dangerous.&lt;/p&gt;

&lt;p&gt;Unfortunately &lt;code&gt;unsafe-inline&lt;/code&gt; is still used today (Hotjar is an example) so it's important to weigh the benefits compared with the risks before using unsafe policies.&lt;/p&gt;

&lt;p&gt;Lastly, to end my article, &lt;a href="https://csp-evaluator.withgoogle.com/"&gt;here&lt;/a&gt; is a little tool to evaluate the Content Security Policy of your app with notes on vulnerabilities and tips on things you can improve. &lt;/p&gt;

&lt;p&gt;Thanks you!&lt;/p&gt;

</description>
      <category>security</category>
      <category>beginners</category>
      <category>csp</category>
      <category>programming</category>
    </item>
    <item>
      <title>5 scenarios where git commands will help you keep your commits Atomic.</title>
      <dc:creator>Manuela Redinciuc</dc:creator>
      <pubDate>Fri, 19 Feb 2021 17:48:02 +0000</pubDate>
      <link>https://dev.to/manuelare/5-scenarios-where-git-commands-will-help-you-keep-your-commits-atomic-495p</link>
      <guid>https://dev.to/manuelare/5-scenarios-where-git-commands-will-help-you-keep-your-commits-atomic-495p</guid>
      <description>&lt;p&gt;I recently graduated from a bootcamp and started my first Developer job.&lt;br&gt;
Just like many before me, the first week was a bit overwhelming with what seemed like an avalanche of information.&lt;br&gt;
This article is a reflection on my first week as a Junior Software Developer and a few new Git commands I learned in order to make Atomic commits easier to manage.&lt;/p&gt;

&lt;p&gt;If you haven't heard before about &lt;strong&gt;Atomic commits&lt;/strong&gt; you can do more reading &lt;a href="https://www.freshconsulting.com/atomic-commits/"&gt;here&lt;/a&gt; and &lt;a href="https://dev.to/cbillowes/why-i-create-atomic-commits-in-git-kfi"&gt;here&lt;/a&gt;. In essence Atomic commits revolve around one independent task or one fix.&lt;/p&gt;

&lt;p&gt;Some of the main benefits of saving your work this way are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;track your history&lt;/strong&gt;. With git log you can easily see the history of your commits. I would also add here that it is important to document each change with a commit message that tells what you've done and why.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;easy to review&lt;/strong&gt;. If your code is focused on only one atomic change then your reviewer should be able to follow and understand your code more easily.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;easy to revert&lt;/strong&gt;. If you've introduced a new bug in your code it's easy to revert your change and fix the issue.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In order to keep a clean working tree and adhere to the Atomic principles here are 5 scenarios that can happen on everyday basis and how you can easily get passed them.&lt;/p&gt;
&lt;h2&gt;
  
  
  1. You've just committed your work and realised you forgot to add something
&lt;/h2&gt;

&lt;p&gt;Start with a &lt;code&gt;git log&lt;/code&gt; to check it's indeed the last commit you want to change.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;commit 2df06c898ba035a0c0878e4f78032b0bd676f3ad (HEAD -&amp;gt; master)
Date:   Sat Feb 13 14:50:27 2021 +0000

    Frontend: Created layout for homepage

    This is a base on which we will develop the homepage and add
    new content.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make your changes, add them to the staging area with &lt;code&gt;git add.&lt;/code&gt; and them commit using &lt;code&gt;git commit --amend&lt;/code&gt;.&lt;br&gt;
This will allow you to override your last commit with your new additions.&lt;br&gt;&lt;br&gt;
If you do a &lt;code&gt;git log&lt;/code&gt; now you can see you still have only on commit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;commit 5f7037f6e7e243e178a58b119e56c0b3337cd408 (HEAD -&amp;gt; master)
Date:   Sat Feb 13 14:50:27 2021 +0000

    Frontend: Created layout for homepage

    This is a base on which we will develop the homepage and add
    new content.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. You've worked on two things at the same time but you want to commit them separately.
&lt;/h2&gt;

&lt;p&gt;You could use &lt;code&gt;git add &amp;lt;file&amp;gt;&lt;/code&gt; but there is a more powerful option.&lt;br&gt;
Your key here is &lt;code&gt;git add --patch&lt;/code&gt; or simply &lt;code&gt;git add -p&lt;/code&gt;.&lt;br&gt;&lt;br&gt;
When you pass this option to add, instead of immediately adding all the changes in the file to the index, it goes through each change and asks you what you want to do, and looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;diff --git a/styles.css b/styles.css
index 23d8732..470d5dc 100644
--- a/styles.css
+++ b/styles.css
@@ -2,4 +2,5 @@
     margin: 0;
     padding: 0;
     box-sizing: border-box;
+    background-color: aquamarine;
 }
(1/1) Stage this hunk [y,n,q,a,d,e,?]? y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. You want to merge together two commits you realised are part of the same Atomic commit.
&lt;/h2&gt;

&lt;p&gt;Start by doing a &lt;code&gt;git log&lt;/code&gt;. &lt;br&gt;
In the example below we want to merge &lt;code&gt;f2662c5&lt;/code&gt; into &lt;code&gt;5f7037f&lt;/code&gt; (e.g the last commit into the first one).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;commit f2662c51cf2f14ccb33907267f1d823ff6b8a678 (HEAD -&amp;gt; master)
Date:   Sat Feb 13 16:36:03 2021 +0000

    Frontend: added style link to Index.html

    This is in order to be able to see the style changes.

commit f84f936e22a0028ad00d3c33771518f23ac192b2
Date:   Sat Feb 13 15:29:42 2021 +0000

    Frontend: Set up style sheet with default styling

    This is a base on which the rest of the homepage will be styled
    upon.

commit 5f7037f6e7e243e178a58b119e56c0b3337cd408
Date:   Sat Feb 13 14:50:27 2021 +0000

    Frontend: Created layout for homepage

    This is a base on which we will develop the homepage and add
    new content.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To achieve your rebase task start by typing: &lt;code&gt;git rebase -i Head~2&lt;/code&gt;.&lt;br&gt;&lt;br&gt;
What this means is: the last commit we want to retain as-is has an index position of 2 (Git uses zero-based indexing) so we can pass in HEAD~2 to our interactive rebase command.&lt;/p&gt;

&lt;p&gt;This will open an interactive panel where we look for our commit &lt;code&gt;f2662c5&lt;/code&gt; and change the word &lt;code&gt;pick&lt;/code&gt; to &lt;code&gt;f&lt;/code&gt; and move it right under the commit you want to merge into (e.g &lt;code&gt;5f7037f&lt;/code&gt;).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pick f84f936 Frontend: Set up style sheet with default styling
f f2662c5 Frontend: added style link to Index.html

# Rebase 5f7037f..f2662c5 onto 5f7037f (2 commands)
#
# Commands:
# p, pick &amp;lt;commit&amp;gt; = use commit
# r, reword &amp;lt;commit&amp;gt; = use commit, but edit the commit message
# e, edit &amp;lt;commit&amp;gt; = use commit, but stop for amending
# s, squash &amp;lt;commit&amp;gt; = use commit, but meld into previous commit
# f, fixup &amp;lt;commit&amp;gt; = like "squash", but discard this commit's log message
# x, exec &amp;lt;command&amp;gt; = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop &amp;lt;commit&amp;gt; = remove commit
# l, label &amp;lt;label&amp;gt; = label current HEAD with a name
# t, reset &amp;lt;label&amp;gt; = reset HEAD to a label
# m, merge [-C &amp;lt;commit&amp;gt; | -c &amp;lt;commit&amp;gt;] &amp;lt;label&amp;gt; [# &amp;lt;oneline&amp;gt;]
# .       create a merge commit using the original merge commit's
# .       message (or the oneline, if no original merge commit was
# .       specified). Use -c &amp;lt;commit&amp;gt; to reword the commit message.
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you check your &lt;code&gt;git log&lt;/code&gt; now you will see that commit &lt;code&gt;f2662c5&lt;/code&gt; is no longer there.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Your code has been reviewed and you need to make some changes to your commit.
&lt;/h2&gt;

&lt;p&gt;To modify a commit that is farther back in your history your best bet is the the rebase again.&lt;br&gt;&lt;br&gt;
Let's say you need to change something on commit &lt;code&gt;ed57576&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;commit e7433f8b9ff28eb819b8740c6692ffb975b426d4 (HEAD -&amp;gt; feature-button, origin/feature-button)
Date:   Sun Feb 14 11:53:53 2021 +0000

    Frontend: changed border radius value for the button

commit ed57576bf379fd7132eb2338b0be34b71f4a94f2 (main)
Date:   Sun Feb 14 11:55:38 2021 +0000

    Frontend: added border specifications

commit a429de8e24c1a5a05c7c4b24c599b637a4fce715 (origin/main)
Date:   Sat Feb 13 17:15:56 2021 +0000

    Frontend: Added button on landing page
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case you can do a &lt;code&gt;rebase -i Head~1&lt;/code&gt; and in the interactive panel change &lt;code&gt;pick&lt;/code&gt; for &lt;code&gt;e&lt;/code&gt; to edit your commit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;e e7433f8 Frontend: changed border radius value for the button

# Rebase ed57576..e7433f8 onto ed57576 (1 command)
#
# Commands:
# p, pick &amp;lt;commit&amp;gt; = use commit
# r, reword &amp;lt;commit&amp;gt; = use commit, but edit the commit message
# e, edit &amp;lt;commit&amp;gt; = use commit, but stop for amending
# s, squash &amp;lt;commit&amp;gt; = use commit, but meld into previous commit
# f, fixup &amp;lt;commit&amp;gt; = like "squash", but discard this commit's log message
# x, exec &amp;lt;command&amp;gt; = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop &amp;lt;commit&amp;gt; = remove commit
# l, label &amp;lt;label&amp;gt; = label current HEAD with a name
# t, reset &amp;lt;label&amp;gt; = reset HEAD to a label
# m, merge [-C &amp;lt;commit&amp;gt; | -c &amp;lt;commit&amp;gt;] &amp;lt;label&amp;gt; [# &amp;lt;oneline&amp;gt;]
# .       create a merge commit using the original merge commit's
# .       message (or the oneline, if no original merge commit was
# .       specified). Use -c &amp;lt;commit&amp;gt; to reword the commit message.
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After you save you can go ahead and make your changes followed by:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git add .&lt;/code&gt;&lt;br&gt;
&lt;code&gt;git commit --amend&lt;/code&gt;&lt;br&gt;
&lt;code&gt;git rebase --continue&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you want to push the branch to the remote repository you now need to force it in order to replace the current version. &lt;br&gt;
 For that use: &lt;code&gt;git push -f origin &amp;lt;feature-name&amp;gt;&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  5. Master has changed and you now have conflicts.
&lt;/h2&gt;

&lt;p&gt;One way to integrate your branch updates into the master is through a merge. Another way is to perform a master to branch rebase. The benefit of the latter is the clean, linear, non-branched commit history that elutes.&lt;/p&gt;

&lt;p&gt;Start by getting the latest version of master:&lt;br&gt;
&lt;code&gt;git checkout master&lt;/code&gt;&lt;br&gt;
&lt;code&gt;git pull&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Checkout into your branch and perform the rebase&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git checkout &amp;lt;branch name&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;code&gt;git rebase master&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If there are any conflicts you a prompt will ask you to choose what version you would like to keep.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;button {
Accept Current Changes | Accept Incoming Change | Accept both Changes
&amp;lt;&amp;lt;&amp;lt; HEAD (Current Change)
    border-radius: 2%;
    border: 2px solid red;
    background-color: green;
=======
    border-radius: 5%;
    background-color:green;
&amp;gt;&amp;gt;&amp;gt; 376b235 (Frontend: changed border radius value for the button)(Incoming Change)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After solving all the merge conflicts you can add the amended files to the rebase and continue the process:&lt;br&gt;
&lt;code&gt;git add .&lt;/code&gt;&lt;br&gt;
&lt;code&gt;git rebase --continue&lt;/code&gt;&lt;br&gt;
&lt;code&gt;git commit&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Git is powerful! So much so that there are many commands you don't even know they exist.&lt;br&gt;&lt;br&gt;
I found that the scenario approach works best for me in learning how to harness the power of Git. I recommend &lt;a href="https://gitexercises.fracz.com/exercise/master"&gt;these&lt;/a&gt; exercises if you want practice and learn more.&lt;/p&gt;

</description>
      <category>git</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>atomic</category>
    </item>
  </channel>
</rss>
