<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="262529" data-post-id="262529">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="c4710n" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/c4710n/120/30931_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  c4710n
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Also, <a href="https://github.com/mirego/mix_audit" class="inline-onebox" rel="noopener nofollow ugc">GitHub - mirego/mix_audit: 🕵️‍♀️ MixAudit provides a mix deps.audit task to scan a project Mix dependencies for known Elixir security vulnerabilities · GitHub</a> can provide some help.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="262529" data-batch-url="/posts/batch_likers">
                        4
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-secure-a-phoenix-app/14614/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-262529" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="262529"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="264046" data-post-id="264046">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="realcorvus" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/realcorvus/120/25597_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  realcorvus
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Using <a href="https://github.com/nccgroup/sobelow" rel="noopener nofollow ugc">Sobelow</a> and <a href="https://github.com/mirego/mix_audit" rel="noopener nofollow ugc">mix_audit</a> were already mentioned, both are great tools.</p>
<p>If your app takes URLs as user input, then does some HTTP request based on them, you should check for <a href="https://portswigger.net/web-security/ssrf" rel="noopener nofollow ugc">server side request forgery (SSRF)</a> It can lead to very bad security incidents, for example it <a href="https://krebsonsecurity.com/2019/08/what-we-can-learn-from-the-capital-one-hack" rel="noopener nofollow ugc">caused the Capitol One breach.</a> There is an open source Elixir library, <a href="https://github.com/slab/safeurl-elixir" rel="noopener nofollow ugc">SafeURL, to help prevent it.</a></p>
<p>The EEF publishes <a href="https://erlef.github.io/security-wg/secure_coding_and_deployment_hardening/." rel="noopener nofollow ugc">secure coding and deployment hardening guidelines.</a> Recently Podium released the <a href="https://github.com/podium/elixir-secure-coding" rel="noopener nofollow ugc">Elixir Secure Coding Training</a> as a series of LiveBooks as well.</p>
<p>In my experience, Phoenix discourages you from writing code with common web app vulnerabilities (SQL injection, XSS, CSRF). Security incidents still happen, often due to someone attacking the site with a bot:</p>
<ul>
<li>Performing thousands of automated login attempts, using a leaked credential database, to compromise user accounts. This is called credential stuffing, and can be mitigated with 2FA (see <a href="https://github.com/dashbitco/nimble_totp/" rel="noopener nofollow ugc">NibleTOTP from Dashbit</a>), ensuring password are not being re-used with an Elixir library like <a href="https://github.com/techgaun/ex_pwned" rel="noopener nofollow ugc">ex_pwned</a>, or bot detection.</li>
<li>Uses a bot to automate new account creation, then attempts hundreds of purchases using stolen credit cards. The goal of the attacker is to figure out which cards work, it’s called a <a href="https://www.candyjapan.com/behind-the-scenes/candy-japan-hit-with-credit-card-fraud" rel="noopener nofollow ugc">carding attack.</a></li>
<li>If your app allows users to send emails through a form, for example a project management tool where you can invite people to a project with a brief message, spammers will use this function to send out scam emails. In addition to your users being upset about the spam, your backend email provider may ban your account over this.</li>
</ul>
<p>Disclosure, I run <a href="http://paraxial.io" rel="noopener nofollow ugc">Paraxial.io</a>, which is a company that blocks attacks like this. Big companies have anti-bot products as well (Google reCaptcha, Cloudflare bot defense), however I would not recommend them.</p>
<p>There’s a number of open source Elixir libraries that can help as well:</p>
<ul>
<li>
<p><a href="https://github.com/michalmuskala/plug_attack" rel="noopener nofollow ugc">PlugAttack</a>, I wrote a <a href="https://paraxial.io/blog/throttle-requests" rel="noopener nofollow ugc">blog post</a> on it, great library.</p>
</li>
<li>
<p><a href="https://github.com/ExHammer/hammer" rel="noopener nofollow ugc">hammer</a></p>
</li>
<li>
<p><a href="https://github.com/grempe/ex_rated" rel="noopener nofollow ugc">ex_rated</a></p>
</li>
</ul>
<p>I also publish some security related Phoenix posts on the <a href="http://paraxial.io" rel="noopener nofollow ugc">Paraxial.io</a> blog, for example <a href="https://paraxial.io/blog/sql-injection" rel="noopener nofollow ugc">Detecting SQL Injection in Phoenix with Sobelow</a>. If you have questions about this stuff, but don’t want to reply here, feel free to dm me.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="264046" data-batch-url="/posts/batch_likers">
                        12
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-secure-a-phoenix-app/14614/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-264046" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="264046"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="315465" data-post-id="315465">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="jaimeiniesta" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jaimeiniesta/120/1063_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  jaimeiniesta
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hey there, I use Paraxial and it’s great!</p>
<p>I recently looked at 404s in my logs and found a lot of suspicious requests like these:</p>
<aside class="onebox githubgist" data-onebox-src="https://gist.github.com/jaimeiniesta/30113255dc706bbb60b5f9b644d19c59">
  <header class="source">

      <a href="https://gist.github.com/jaimeiniesta/30113255dc706bbb60b5f9b644d19c59" target="_blank" rel="noopener nofollow ugc">gist.github.com</a>
  </header>

  <article class="onebox-body">
    <h4><a href="https://gist.github.com/jaimeiniesta/30113255dc706bbb60b5f9b644d19c59" target="_blank" rel="noopener nofollow ugc">https://gist.github.com/jaimeiniesta/30113255dc706bbb60b5f9b644d19c59</a></h4>



  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>Where can I find a more complete list of typical URLs used in exploit scans?</p>
<p>I’m thinking of adding a plug in my app so I can block IPs performing these requests. The idea would be to remember the IP and block it from the plug, and maybe also submit it to a Paraxial’s honeypot. For that, if would be useful to only block them for 24 hours or so, because attackers may be using temporary IPs and I don’t want to ban them forever.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="315465" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-secure-a-phoenix-app/14614/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-315465" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="315465"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="315475" data-post-id="315475">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="arcanemachine" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/arcanemachine/120/29109_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  arcanemachine
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<blockquote>
<p>Where can I find a more complete list of typical URLs used in exploit scans?</p>
</blockquote>
<p>Just run <code>fail2ban</code> on your server for a couple weeks and check the logs. <img src="https://forum.elixirforum.com/images/emoji/apple/smiley.png?v=15" title=":smiley:" class="emoji" alt=":smiley:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="315475" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-secure-a-phoenix-app/14614/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-315475" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="315475"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #14"></div>
  </section>
</div>
    <div class="postbit" id="315592" data-post-id="315592">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="krasenyp" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/krasenyp/120/39733_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  krasenyp
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>You can make use of tools included in your default OS installation. For example, on FreeBSD there’s <em>PF</em>, a firewall, which can easily be integrated with <em>fail2ban</em>, or <em>blacklistd</em>. Not everything should be built into your service.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="315592" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-secure-a-phoenix-app/14614/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-315592" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="315592"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #15"></div>
  </section>
</div>
    <div class="postbit" id="315630" data-post-id="315630">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Rob1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Rob1/120/33329_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Rob1
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I noticed Phoenix project files have database credentials, for example if you Google</p>
<blockquote>
<p>phoenix config.exs example</p>
</blockquote>
<p>the top result shows putting in a username and password. (It doesn’t actually include one, just a placeholder, but the risk is there of sharing it when sharing a Phoenix project with the world.)</p>
<p>This could possibly be fine for a local application where no one can connect to the database remotely but if you are going to check your Phoenix application into source control, for example to share it with other developers as the example shows, it could make sense to put those values in environmental variables to reduce the risk of sharing your database password, especially for a hosted database solution that isn’t on localhost.</p>
<p>For example I plan to share a complete phoenix app here, my postgresql database will be hosted, so if I shared the app including config file I would end up sharing the admin password to my database.</p>
<p>Instead ChatGPT suggests replacing the lines in config.exs with these lines, I hope it would work:</p>
<blockquote>
<p>config :real_world, RealWorld.Repo,<br>
adapter: Ecto.Adapters.Postgres,<br>
username: System.get_env(“DB_USERNAME”),<br>
password: System.get_env(“DB_PASSWORD”),<br>
database: “real_world_dev”,<br>
hostname: “localhost”,<br>
pool_size: 10</p>
</blockquote>
<p>Is this correct?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="315630" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-secure-a-phoenix-app/14614/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-315630" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="315630"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #16"></div>
  </section>
</div>
    <div class="postbit" id="315635" data-post-id="315635">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Aadmaa" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Aadmaa/120/32693_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Aadmaa
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Yes, you would not usually hardcode those values except for in the dev and test environments and that example does show how to get them from Environment Vars. You can also use Dotenvy to use a local .env file, which you can add to .gitignore so it does not get committed. I don’t think you need chatgpt for this one though <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<p>If you make a new app with “mix phx.new,” take a look at runtime.exs. You will see the database URL gets set up with “System.get_env(“DATABASE_URL”)”  n the :prod environment, and you’d have to set that environment value for the app to run.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="315635" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-secure-a-phoenix-app/14614/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-315635" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="315635"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #17"></div>
  </section>
</div>
    <div class="postbit" id="315645" data-post-id="315645">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="al2o3cr" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/al2o3cr/120/3457_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  al2o3cr
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group quote-modified" data-username="Rob1" data-post="17" data-topic="14614">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/rob1/48/33329_2.png" class="avatar"> Rob1:</div>
<blockquote>
<p>Instead ChatGPT suggests replacing the lines in config.exs with these lines, I hope it would work:</p>
<blockquote>
<p>config :real_world, RealWorld.Repo,<br>
adapter: Ecto.Adapters.Postgres,<br>
username: System.get_env(“DB_USERNAME”),<br>
password: System.get_env(“DB_PASSWORD”),<br>
database: “real_world_dev”,<br>
hostname: “localhost”,<br>
pool_size: 10</p>
</blockquote>
<p>Is this correct?</p>
</blockquote>
</aside>
<p>Probably not - using <code>System.get_env</code> in <code>config.exs</code> means that the configuration is read at <em>compile time</em>, not when the system actually starts.</p>
<p>As <a class="mention" href="/u/aadmaa" rel="nofollow">@Aadmaa</a> points out, the Phoenix generators already output a configuration in <code>config/runtime.exs</code> that uses a <code>DATABASE_URL</code> environment variable to encapsulate user/pass/host/options. That gets loaded at system-start time.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="315645" data-batch-url="/posts/batch_likers">
                        4
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-secure-a-phoenix-app/14614/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-315645" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="315645"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #18"></div>
  </section>
</div>
    <div class="postbit" id="315649" data-post-id="315649">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Rob1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Rob1/120/33329_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Rob1
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group quote-modified" data-username="al2o3cr" data-post="19" data-topic="14614">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/al2o3cr/48/3457_2.png" class="avatar"> al2o3cr:</div>
<blockquote>
<p>As <span class="mention">@aAadmaa</span> points out, the Phoenix generators already output a configuration in <code>config/runtime.exs</code> that uses a <code>DATABASE_URL</code> environment variable to encapsulate user/pass/host/options. That gets loaded at system-start time.</p>
</blockquote>
</aside>
<p>Thanks, both. It’s helpful to know this.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="315649" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-secure-a-phoenix-app/14614/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-315649" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="315649"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>