<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Developervisits - Medium]]></title>
        <description><![CDATA[Online free blogging site for mainly java domain - Medium]]></description>
        <link>https://medium.com/developervisits?source=rss----5e148d708cd9---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Developervisits - Medium</title>
            <link>https://medium.com/developervisits?source=rss----5e148d708cd9---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 18:54:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/developervisits" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Basic Spring Security tips before going into production]]></title>
            <link>https://medium.com/developervisits/basic-spring-security-tips-before-going-into-production-89d6bbca9eb3?source=rss----5e148d708cd9---4</link>
            <guid isPermaLink="false">https://medium.com/p/89d6bbca9eb3</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[spring-security]]></category>
            <dc:creator><![CDATA[Rajeev Shukla]]></dc:creator>
            <pubDate>Sat, 19 Feb 2022 04:04:34 GMT</pubDate>
            <atom:updated>2022-02-19T20:46:15.453Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yc7OxJyx7VWruXIEdK__og.png" /></figure><h3><strong>Introduction</strong></h3><p>In general, web APIs are exposed to the Internet, so they need security mechanisms to prevent abuse, protect sensitive data, and ensure that only authenticated and authorized users can access them. Thus, web API security is crucial.</p><p>Below are some of the basic points that would help you to start the basic security checks —</p><h4>1. Url protection</h4><ul><li>Allow access to everyone to a given URL</li><li>Secure URL based on roles.</li><li>Secure URL based on multiple roles.</li></ul><p>.antMatchers(“/register”,”/login”,”/user”,”/admin”)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/18629116a524c8cf66b1ab4ad127495d/href">https://medium.com/media/18629116a524c8cf66b1ab4ad127495d/href</a></iframe><p>access(“hasRole(‘ADMIN’) and hasIpAddress(‘123.123.123.123’)”)</p><p>Use the access method to use SPEL for more complicated security.</p><h4>2. CSRF Token</h4><p>A CSRF attack occurs when a website uses cookies for any reason and a malicious script is executed on the client/user side to perform any task such as fund transfer or password change without the user’s knowledge.</p><p>REST applications are immune to CSRF attacks if they do not use cookies. So, <strong>no cookies = no CSRF</strong>.</p><p>Usually, most of the people disable(in demo code) because they won’t be able to call /logout URL with the GET method as it requires you to submit it via POST with _csrf token. Check more details about CSRF <a href="https://owasp.org/www-community/attacks/csrf">here</a></p><h4><strong>3. Session Fixation Attack</strong></h4><p>This is the type of attack where one can steal your current session by offering their URL of the same website and append JSESSIONID it into the URL, with the URL rewrite approach. Spring Security Framework has taken care of this by default and it migrates the session once the user logs in. The corresponding configuration would be -</p><pre>http.sessionManagement()<br>  .sessionFixation().migrateSession()</pre><blockquote>You should use above only when you are using session based application. For REST based application this might not be needed.</blockquote><h4><strong>4. Securing session cookie</strong>:</h4><p>The malicious script can read your cookie information from the browser end so you need to make sure that your cookie is secured and accessible by server-side code by making them HttpOnly. For that, you can add the below config in your application.properties -</p><pre>server.servlet.session.cookie.http-only=true</pre><h4>5. <strong>Running your app on Https:</strong></h4><p>Make sure that you use HTTPS in production and in that case you can force your cookies to travel over HTTPS protocol only by adding the below config in your application.properties .</p><pre>server.servlet.session.cookie.secure=true</pre><p>and to force HTTPS connection add below lines in configure() method (this won’t be enough though because you have to get your public/private key setup also using the key tool)</p><pre>http.requiresChannel().requiresSecure();</pre><h4>6. <strong>Applying CSP:</strong></h4><p>User Content security policy to avoid any <a href="https://owasp.org/www-community/attacks/xss/">XSS attacks.</a> Spring security by default provides various security headers. But it does not add Content security policy headers you can add them in your security config file like below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f9aca8dfafb239d4a6a5df70bae020f/href">https://medium.com/media/8f9aca8dfafb239d4a6a5df70bae020f/href</a></iframe><h4><strong>7. Password hashing</strong>:</h4><p>Password hashing is a one-way function that is impossible to decrypt. Keeping the password in open plain text is open for anyone to read. This can pose a great security threat as anyone in your organization or outside who can gain the access to DB can read the password. It is a must-have thing that everyone should follow.</p><p>Spring security provides various algorithms to support password hashing.</p><p>bcrypt password encoder by default.</p><pre>PasswordEncoderFactories.createDelegatingPasswordEncoder()</pre><p>Or use other also supported</p><pre>@Bean<br>public PasswordEncoder <strong>encoder</strong>() {<br>    return new BCryptPasswordEncoder();<br>}</pre><p><a href="https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/crypto/factory/PasswordEncoderFactories.html">Check here</a> for more sets of algorithms supported by this factory class.</p><h4>8. Enabling method level security</h4><p>Spring Security supports <strong>“Method Level Security”</strong> by using AOP. @PreAuthorized can be used to secure methods at the controller layer. This is similar to URL protection but the difference is that @PreAuthorized triggers when your controller code is about to execute. Also, you can use the SPEL expression to allow or deny requests based on security attributes such as, if the request is read_only and then update or delete operations should be rejected.</p><p>Also, it can help you to organize the security-related definitions within the code adjacent to the controller definitions.</p><h4><strong>9. Securing your application.properties</strong></h4><p>Security should be applied not only from outside but should also be protected from inside as well. Like encryption and decryption of database passwords or any other config passwords. Please check my other post on how you can secure the application.properties in spring boot.</p><p><a href="https://medium.com/@mail2rajeevshukla/hiding-encrypting-database-password-in-the-application-properties-34d59fe104eb">Hiding/Encrypting database password in the application.properties</a></p><h4>10. Prevent DDOS attack</h4><p>This should be addressed by adjusting several security parameters such as session timeouts, security header checks, memory leak handling, and POST request timeouts to ensure that no one posts a large request payload, among others. To counteract such security threats, you’ll need to put in some effort. There are cloud providers which prevent such type attacks such as AWS <a href="https://aws.amazon.com/shield/">Shield</a> or <a href="https://cloud.google.com/armor">Google Cloud armor</a></p><h4>11. What else we can do ??</h4><p>Security isn’t restricted to the topics we’ve discussed thus far. These considerations may not be sufficient when working with mission-critical systems, such as those in the finance industry, where security is paramount. However, these ideas might serve as a good starting point for addressing some of the more fundamental and sophisticated issues.</p><p>Occasionally, addressing a CVE (Common Vulnerability and Exposure) error may pose a security risk. You may need to upgrade the underlining library in this situation, as the library has security vulnerabilities that you may or may not be aware of. Do you remember the <a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-45105">log4j </a>security crisis? 😊</p><p>Thank you for your time. Follow me for more such updates.😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89d6bbca9eb3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/developervisits/basic-spring-security-tips-before-going-into-production-89d6bbca9eb3">Basic Spring Security tips before going into production</a> was originally published in <a href="https://medium.com/developervisits">Developervisits</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hiding/Encrypting database password in the application.properties]]></title>
            <link>https://medium.com/developervisits/hiding-encrypting-database-password-in-the-application-properties-34d59fe104eb?source=rss----5e148d708cd9---4</link>
            <guid isPermaLink="false">https://medium.com/p/34d59fe104eb</guid>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[secure]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[jasypt]]></category>
            <dc:creator><![CDATA[Rajeev Shukla]]></dc:creator>
            <pubDate>Fri, 14 May 2021 17:59:07 GMT</pubDate>
            <atom:updated>2020-07-26T21:27:44.529Z</atom:updated>
            <content:encoded><![CDATA[<h3>Hiding/Encrypting database password in the application.properties file in a simple and secure way using spring-boot-jasypt</h3><figure><img alt="Image result for spring boot image" src="https://cdn-images-1.medium.com/proxy/1*jMQ9lkY5SBnbcOlJB4aizg.png" /></figure><h3><strong>1.Introduction</strong></h3><p>Java Simplified Encryption also knows as J<a href="http://www.jasypt.org/">asypt</a> is a java library which allows the developer to add basic encryption capabilities to his/her projects with minimum effort, and without the need of having deep knowledge on how cryptography works.</p><p>It provides integration into <strong>Spring</strong>-based applications and also transparently integrable with <strong>Spring Security </strong>and many other frameworks.</p><p><strong>2. Adding Jasypt dependency</strong></p><p>Now when it comes to adding Jasypt dependency there are multiple ways to do. It is totally up to you which way you want to go.</p><p><strong>2.1</strong> Remove Spring boot’s core dependency and add Jasypt enabled spring boot core dependency.</p><p>Remove below from your project which is only deal with spring boot core</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cfde9c73cab62909c3fb01c33a3be34c/href">https://medium.com/media/cfde9c73cab62909c3fb01c33a3be34c/href</a></iframe><blockquote>Add below Jasypt enabled spring core which includes spring boot + jayspt enabled with this you don’t need to do anything in your project. @EnableAutoConfiguration annotation is enough to get going.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c9881088cf2fc773f0d0573f5b97b863/href">https://medium.com/media/c9881088cf2fc773f0d0573f5b97b863/href</a></iframe><p><strong>2.2</strong> if you don’t use jasypt spring starter dependency then you can go with alternate just add below dependency</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5288a8b7049fec7cef02b23727b32045/href">https://medium.com/media/5288a8b7049fec7cef02b23727b32045/href</a></iframe><p>And annotation your main configuration class with <strong>@EnableEncryptableProperties</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8870658fd4e1c9e5f991027042b7eb0/href">https://medium.com/media/a8870658fd4e1c9e5f991027042b7eb0/href</a></iframe><p>That is it. Now spring boot will enable encryptable properties across the entire Spring Environment.</p><h3><strong>3. Creating an encrypted key-</strong></h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e8fb5bb790c717b698958f60752a2230/href">https://medium.com/media/e8fb5bb790c717b698958f60752a2230/href</a></iframe><p><strong>input:</strong> It is the actual password that you want to hide.</p><p><strong>password:</strong> A secret key that is used to encrypt the actual input which will later be used to decrypt the password. So you need to note down this key for future decryption.</p><p><strong>PBEWithMD5AndDES: </strong>A password-based version of the DES algorithm which uses an MD5 hash of the specified password as the encryption key</p><p><strong>Update-</strong></p><blockquote>In version 3.0.0+ jasypt started using PBEWITHHMACSHA512ANDAES_256 algorithm as default encryption algo so you may face error if you see use same algorithm what we are using here PBEWithMD5AndDES<strong> </strong>So either use <em>PBEWITHHMACSHA512ANDAES_256 algo as default or add below properties to fix the issue.</em></blockquote><p>The error would be something like —</p><pre>Unable to decrypt: ENC(MyEncryptedPass). The decryption of Properties failed, make sure encryption/decryption passwords match</pre><p>To fix this problem you will have to add two properties in your application.properties file.</p><pre>jasypt.encryptor.algorithm=PBEWithMD5AndDES<br>jasypt.encryptor.iv-generator-classname=org.jasypt.iv.NoIvGenerator</pre><p>For more details <a href="https://github.com/ulisesbocchio/jasypt-spring-boot#update-11242019-version-300-release-includes">see here</a></p><p><strong>4. Adding encrypted key into application.properties</strong></p><p>Now whatever output you get in step #3 in the output section, is your actual property value which is going to be used in application.poperties.</p><p>Now before adding that encrypted value, Firstly, you need to know how would Jasypt know that it should be decrypted or not? To distinguish that Jasypt uses a default convention to add that encrypted key inside ENC(&lt;encrypted keys here&gt;)</p><p><strong>Example:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8eacb65ae285b56c2058e0d97aa57c0/href">https://medium.com/media/a8eacb65ae285b56c2058e0d97aa57c0/href</a></iframe><p>Jasypt reads all the properties from application.properties or any classpath properties that you passed. It is not necessary you can only secure only the DB password. In fact, you can secure anything you want You just need to use the prefix ENC( and suffix ) and pass the encrypted key.</p><p>We can change the prefix ENC() to a custom name like SEC() or anything that you want but that would lead to the separate topic of discussion.</p><p><strong>5. Passing Jasypt secret key in command line argument</strong></p><p>Now we need to tell the program to decrypt the encrypted key at run time when needed. To do that we need to pass that secret key into our application. There as various way we can do that —</p><p><strong>5.1</strong> $mvn -Djasypt.encryptor.password=secretkey spring-boot:run</p><p><strong>5.2</strong> export JASYPT_ENCRYPTOR_PASSWORD=secretkey and then run your application a simple java application.</p><p><strong>5.3</strong> <strong><em>(Using STS/Eclipse)Right click on main class &gt; Run as &gt; Run configuration </em></strong>and pass secret key in VM argument like below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BZg-1osZo2fPWj7X4FXjEQ.png" /></figure><p><strong><em>5.4 Using spring cloud vault: </em></strong>This is the most secure way to do that. Please follow given the link to read how to secure it using spring cloud vault.</p><p><a href="https://medium.com/@mail2rajeevshukla/securing-passwords-using-hashicorp-vault-in-spring-6c18da62a42e">Securing passwords using HashiCorp Vault and Spring-cloud</a></p><p><strong>6. Summary</strong></p><p>So far we have seen how easy it is to encrypt passwords or any text that we want to hide. But this is the most simple form of implementation which is enough to get going. But sometimes we come across a situation where we need to customize some of its functionality as per the application needs. So, In that case, I would like to refer you to go through the document and you will get so much information which I have not mentioned <a href="https://github.com/ulisesbocchio/jasypt-spring-boot">here</a>.</p><p>Likes/comments are appreciated.</p><p>👉🏼 <strong>Check out my next post on how to Integrate Spring Security OAuth2 with Facebook along with Form-based login</strong></p><p><a href="https://medium.com/@mail2rajeevshukla/spring-security-5-3-oauth2-integration-with-facebook-along-with-form-based-login-767e10b02dbc">Spring Security 5.3 OAuth2 integration with Facebook along with Form-Based login</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34d59fe104eb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/developervisits/hiding-encrypting-database-password-in-the-application-properties-34d59fe104eb">Hiding/Encrypting database password in the application.properties</a> was originally published in <a href="https://medium.com/developervisits">Developervisits</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>