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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Even if you were sure it couldn’t, you couldn’t guarantee that a future version of <code>identify</code> wouldn’t be able to do so, due to a bug.</p>
<p>Lot’s of big security breaches happen by combining several minor overlooked things in a code base, therefore a developer <strong>should</strong> always strive to write defensive code, therefore I would never ask an external command to verify an image file that I am not sure to be really an image. But that’s me <img src="https://forum.elixirforum.com/images/emoji/apple/wink.png?v=15" title=":wink:" class="emoji" alt=":wink:" 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="175180" 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/ive-forked-arc-to-waffle-and-merged-all-open-prs/25559/33">Post #32</a>
	                </div>
	            </div>
              <div id="likers-container-175180" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="175180"
                     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 #32"></div>
  </section>
</div>
    <div class="postbit" id="175181" data-post-id="175181">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="achempion" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/achempion/120/21179_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  achempion
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I’m working on the file validation for the library right now. Hope I would finish it soon.</p>
<p>You can use <code>System.cmd("file", ["--mime", "--brief", filepath])</code> call to get mime type for the file and include it inside the validation function.</p>
<p>We have the <a href="https://github.com/elixir-plug/mime" rel="noopener nofollow ugc">elixir-plug/mime</a> library if you want to refer to extension directly instead of mime type of the file (you can use it to get mime types by extension).</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="175181" 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/ive-forked-arc-to-waffle-and-merged-all-open-prs/25559/34">Post #33</a>
	                </div>
	            </div>
              <div id="likers-container-175181" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="175181"
                     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 #33"></div>
  </section>
</div>
    <div class="postbit" id="175186" data-post-id="175186">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="achempion" data-post="34" data-topic="25559">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/achempion/48/21179_2.png" class="avatar"> achempion:</div>
<blockquote>
<p>We have the <a href="https://github.com/elixir-plug/mime" rel="noopener nofollow ugc">elixir-plug/mime</a> library if you want to refer to extension directly instead of mime type of the file (you can use it to get mime types by extension).</p>
</blockquote>
</aside>
<p>This only maps mime type, doesn’t validate them, and using external tools from the OS to do validations always open my eyebrows… I really don’t like libraries that rely on it. But that’s me… maybe because I work in the security space.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="175186" 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/ive-forked-arc-to-waffle-and-merged-all-open-prs/25559/35">Post #34</a>
	                </div>
	            </div>
              <div id="likers-container-175186" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="175186"
                     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 #34"></div>
  </section>
</div>
    <div class="postbit" id="175188" data-post-id="175188">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="achempion" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/achempion/120/21179_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  achempion
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>What approach would you recommend to implement? Do you have any concerns about the <code>file</code> linux library?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="175188" 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/ive-forked-arc-to-waffle-and-merged-all-open-prs/25559/36">Post #35</a>
	                </div>
	            </div>
              <div id="likers-container-175188" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="175188"
                     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 #35"></div>
  </section>
</div>
    <div class="postbit" id="175189" data-post-id="175189">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>As I said I just have concerns about using calls to the OS, because this will open new scopes of vulnerabilities, like path expansion to undesired locations in the event of a bug.</p>
<p>So if things can be checked from within the programming language without using OS tooling then I will go with it, but If is not really possible to implement it in Elixir, then you really need to resort to external tools.</p>
<p>I am not at all an expert in images manipulation and verification, but I am almost sure to have seen in the past binary matches being used to check for the file mime type, but don’t recall where it was.</p>
<h1><a name="p-175189-edit-1" class="anchor" href="#p-175189-edit-1" aria-label="Heading link" rel="nofollow"></a>EDIT</h1>
<p>Found the library <a href="https://github.com/Group4Layers/ex_image_info" rel="noopener nofollow ugc">Group4Layers/ex_image_info</a></p>
<p>The code for <a href="https://github.com/Group4Layers/ex_image_info/blob/d1d7f5c7b7b46c4286c71c2bb419cac7dcf84082/lib/ex_image_info/types/png.ex#L1-L24" rel="noopener nofollow ugc">png</a>:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule ExImageInfo.Types.PNG do


  @moduledoc false


  @behaviour ExImageInfo.Detector


  @mime "image/png"
  @ftype "PNG"


  @signature &lt;&lt;"PNG\r\n", 0x1A, "\n"&gt;&gt;
  @signature_ihdr &lt;&lt;"IHDR"&gt;&gt;


  ## Public API


  def seems?(&lt;&lt; _::bytes-size(1), @signature, _rest::binary &gt;&gt;), do: true
  def seems?(_), do: false


  def info(&lt;&lt; _::bytes-size(1), @signature, _::size(32), @signature_ihdr, width::size(32), height::size(32), _rest::binary &gt;&gt;), do: {@mime, width, height, @ftype}
  def info(_), do: nil


  def type(&lt;&lt; _::size(8), @signature, _::size(32), @signature_ihdr, _rest::binary &gt;&gt;), do: {@mime, @ftype}
  def type(_), do: nil


end
</code></pre>
<p>Not sure if this is the most secure way of validating them or not… As I said I am not an expert on the matter.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="175189" 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/ive-forked-arc-to-waffle-and-merged-all-open-prs/25559/37">Post #36</a>
	                </div>
	            </div>
              <div id="likers-container-175189" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="175189"
                     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 #36"></div>
  </section>
</div>
    <div class="postbit" id="175197" data-post-id="175197">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>You can always integrate with an Erlang NIF to a C library that uses ImageMagick’s code (I believe in Linux it’s called <code>libmagick</code>?) or a Elixir&lt;=&gt;Rust bridge (namely <code>rustler</code>) to a Rust library that does [almost] the same. It’s more complex and you’re still at the mercy of native code’s capriciousness but it’s less brittle than calling external programs at least (although that can also be debatable depending on OS and library versions).</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="175197" 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/ive-forked-arc-to-waffle-and-merged-all-open-prs/25559/38">Post #37</a>
	                </div>
	            </div>
              <div id="likers-container-175197" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="175197"
                     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 #37"></div>
  </section>
</div>
    <div class="postbit" id="175217" data-post-id="175217">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="josevalim" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/120/1787_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  josevalim
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Creator of Elixir</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="Exadra37" data-post="33" data-topic="25559">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/exadra37/48/9183_2.png" class="avatar"> Exadra37:</div>
<blockquote>
<p>Even if you were sure it couldn’t, you couldn’t guarantee that a future version of <code>identify</code> wouldn’t be able to do so, due to a bug.</p>
</blockquote>
</aside>
<p>If your assumption is that the software that verifies that file format can be buggy, then there is no software that verifies the file format that would be surely bug free, therefore there is no way to verify the file format itself.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="175217" 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/ive-forked-arc-to-waffle-and-merged-all-open-prs/25559/39">Post #38</a>
	                </div>
	            </div>
              <div id="likers-container-175217" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="175217"
                     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 #38"></div>
  </section>
</div>
    <div class="postbit" id="175228" data-post-id="175228">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>This is an external software, thus opens a new scope of vulnerabilities. As a developer you may not be familiar with all the ways hackers find to chain the most innocent approaches developers use for convenience when solving their  problems, but anyone in the infosec community can tell you a lot of stories around chaining mistakes and assumptions made by developers. I am in the security space only for 2 years as a developer advocate, not as a security researcher, and I already seen enough to realise how our software industry is broken for how they approach software development… Bear in mind that I am not accusing anyone in specific here, it’s just the reality where we leave, and that unfortunately isn’t changing quickly enough, as per data-breaches growing month by month indicate.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="175228" 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/ive-forked-arc-to-waffle-and-merged-all-open-prs/25559/40">Post #39</a>
	                </div>
	            </div>
              <div id="likers-container-175228" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="175228"
                     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 #39"></div>
  </section>
</div>
    <div class="postbit" id="175230" data-post-id="175230">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="josevalim" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/120/1787_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  josevalim
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Creator of Elixir</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I am aware of the issues by invoking a third party tool but what are the alternatives? Implementing your own solution in Erlang/Elixir may actually be less secure, as you can make mistakes and introduce bugs that have been addressed in more battle-tested solutions. Integrating a C-library brings other concerns. They all have trade-offs.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="175230" 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/ive-forked-arc-to-waffle-and-merged-all-open-prs/25559/41">Post #40</a>
	                </div>
	            </div>
              <div id="likers-container-175230" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="175230"
                     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 #40"></div>
  </section>
</div>
    <div class="postbit" id="175231" data-post-id="175231">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Not necessarily less secure if done by a subject matter expert that does his own research and see how that OS libraries have implemented the check and port it then to Elixir.</p>
<p>Calling OS software should be the last resort in my opinion.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="175231" 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/ive-forked-arc-to-waffle-and-merged-all-open-prs/25559/42">Post #41</a>
	                </div>
	            </div>
              <div id="likers-container-175231" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="175231"
                     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 #41"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <a class="load-more-button" data-turbo-stream="true" href="/topics/25559/load_more?page=5">Load more posts (8 remaining)</a>
</div></template></turbo-stream>