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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="dimitarvp" data-post="10" data-topic="49702">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/dimitarvp/48/38664_2.png" class="avatar"> dimitarvp:</div>
<blockquote>
<p>What’s a good way to secure API access these days? (I guess the same question can be asked for e.g. keeping game sessions alive as well.)</p>
</blockquote>
</aside>
<p>Regular, stateful, sessions. Just have table with fields <code>session_id</code>, <code>data</code>, and <code>expire_at</code>. Generate session ID via <code>:crypto.secure_random_bytes(32)</code> encode however you want and call it a day. It will be the most secure, most obvious, and easiest to manage approach.</p>
<p>cc <a class="mention" href="/u/pistrie" rel="nofollow">@Pistrie</a></p>
<p>If you want a one-time-token then <code>Phoenix.Token</code> will be much better choice than JWT. It is simple, versioned, signed token. The lack of configurability is enormous gain there as you cannot accidentally use incorrect set of keys/features and make it much harder to fallback to insecure algos. If you want something cross-platform then PASETO or similar would be probably best choice (I am working on BASETO which will use BARE instead of JSON to encode the data, but that is irrelevant there, the idea is the same).</p>
<p>For browsers sessions just use HTTP-Only cookies, for API you can use Cookies or <code>Authorisation</code> header, that doesn’t really change much. If you want to be ultra secure, then you can try mTLS for that, rarely used, but super powerful approach.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="259163" data-batch-url="/posts/batch_likers">
                        8
                      </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/do-refresh-tokens-provide-a-false-sense-of-security/49702/22">Post #21</a>
	                </div>
	            </div>
              <div id="likers-container-259163" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="259163"
                     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 #21"></div>
  </section>
</div>
    <div class="postbit" id="259169" data-post-id="259169">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Completely agree!</p>
<p>Unless you have a large microservice environment and you’ve measured that your authetication service is causing a problematic amount of latency then you don’t need any of the performance optimisations that JWT and other error prone tokens may give you.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="259169" 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/do-refresh-tokens-provide-a-false-sense-of-security/49702/23">Post #22</a>
	                </div>
	            </div>
              <div id="likers-container-259169" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="259169"
                     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 #22"></div>
  </section>
</div>
    <div class="postbit" id="259196" data-post-id="259196">
  <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">
								<aside class="quote no-group" data-username="hauleth" data-post="22" data-topic="49702">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/hauleth/48/18942_2.png" class="avatar"> hauleth:</div>
<blockquote>
<p>Just have table with fields <code>session_id</code>, <code>data</code>, and <code>expire_at</code>. Generate session ID via <code>:crypto.secure_random_bytes(32)</code> encode however you want and call it a day.</p>
</blockquote>
</aside>
<p>But… I’ve been doing that with PHP some 10+ years ago. Good to know it’s still a good practice! <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>
<p>Also somewhat disappointing. For all the talk of quantum-resistant encryption and perfect forward secrecy one would expect at least <em>some</em> of that to spill over to application development security…</p>
<p>Reading about <a href="https://www.cloudflare.com/learning/access-management/what-is-mutual-tls/" rel="noopener nofollow ugc">mTLS</a> has proven interesting, thank you.</p>
<p><code>Phoenix.Token</code> is now my new favorite thing.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="259196" 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/do-refresh-tokens-provide-a-false-sense-of-security/49702/24">Post #23</a>
	                </div>
	            </div>
              <div id="likers-container-259196" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="259196"
                     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 #23"></div>
  </section>
</div>
    <div class="postbit" id="259206" data-post-id="259206">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="dimitarvp" data-post="24" data-topic="49702">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/dimitarvp/48/38664_2.png" class="avatar"> dimitarvp:</div>
<blockquote>
<p>Also somewhat disappointing. For all the talk of quantum-resistant encryption and perfect forward secrecy one would expect at least <em>some</em> of that to spill over to application development security</p>
</blockquote>
</aside>
<p>It does, just when you want to have some way of authorisation and revocability then you still need to ping some centralised store. You cannot leap over physics.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="259206" 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/do-refresh-tokens-provide-a-false-sense-of-security/49702/25">Post #24</a>
	                </div>
	            </div>
              <div id="likers-container-259206" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="259206"
                     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 #24"></div>
  </section>
</div>
    <div class="postbit" id="259239" data-post-id="259239">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="hauleth" data-post="22" data-topic="49702">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/hauleth/48/18942_2.png" class="avatar"> hauleth:</div>
<blockquote>
<p>(I am working on BASETO which will use BARE instead of JSON to encode the data, but that is irrelevant there, the idea is the same).</p>
</blockquote>
</aside>
<p>PASETO is encoding agnostic.</p>
<p>From <a href="https://github.com/paseto-standard/paseto-spec/blob/8954f60314d813ea2cbcd2eac40f08bde4c1a6f9/docs/README.md#with-the-optional-footer" rel="noopener nofollow ugc">the specification</a>:</p>
<aside class="quote no-group">
<blockquote>
<p>PASETO serializes its payload as a JSON string. Future documents <strong>MAY</strong> specify using<br>
PASETO with non-JSON encoding. When this happens, a suffix will be appended to the version tag<br>
when a non-JSON encoding rule is used.</p>
<blockquote>
<p>For example, a future PASETO-CBOR proposal might define its versions as <code>v1c</code>, <code>v2c</code>, <code>v3c</code>,<br>
and <code>v4c</code>. The underlying cryptography will be the same as <code>v1</code>, <code>v2</code>, <code>v3</code>, and <code>v4</code><br>
respectively. Keys <strong>SHOULD</strong> be portable across different underlying encodings, but tokens<br>
<strong>MUST NOT</strong> be transmutable between encodings without access to the symmetric key (<code>local</code> tokens)<br>
or secret key (<code>public</code> tokens).</p>
</blockquote>
</blockquote>
</aside>
<p>If you want to propose a non-JSON encoding for PASETO, it might be worthwhile to register it as a suffix in the specification rather than fork as “BASETO”.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="259239" 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/do-refresh-tokens-provide-a-false-sense-of-security/49702/26">Post #25</a>
	                </div>
	            </div>
              <div id="likers-container-259239" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="259239"
                     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 #25"></div>
  </section>
</div>
    <div class="postbit" id="259276" data-post-id="259276">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>A bit off topic but what is BARE encoding? A quick search didn’t reveal much</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="259276" 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/do-refresh-tokens-provide-a-false-sense-of-security/49702/27">Post #26</a>
	                </div>
	            </div>
              <div id="likers-container-259276" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="259276"
                     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 #26"></div>
  </section>
</div>
    <div class="postbit" id="259277" data-post-id="259277">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="onebox allowlistedgeneric" data-onebox-src="https://baremessages.org/">
  <header class="source">

      <a href="https://baremessages.org/" target="_blank" rel="noopener nofollow ugc">baremessages.org</a>
  </header>

  <article class="onebox-body">
    

<h3><a href="https://baremessages.org/" target="_blank" rel="noopener nofollow ugc">BARE Message Encoding</a></h3>



  </article>

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

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

<p>Binary encoding, think protobuf, but way simpler and focused on tokens instead of RPC.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="259277" 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/do-refresh-tokens-provide-a-false-sense-of-security/49702/28">Post #27</a>
	                </div>
	            </div>
              <div id="likers-container-259277" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="259277"
                     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 #27"></div>
  </section>
</div>
    <div class="postbit" id="259325" data-post-id="259325">
  <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="dorgan" data-post="14" data-topic="49702">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/dorgan/48/22107_2.png" class="avatar"> dorgan:</div>
<blockquote>
<p>Maybe <a class="mention" href="/u/exadra37" rel="nofollow">@Exadra37</a> has some insights on this, if he doesn’t mind the ping <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>
</blockquote>
</aside>
<p>I don’t mind at all.</p>
<aside class="quote no-group" data-username="Pistrie" data-post="1" data-topic="49702">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/pistrie/48/32067_2.png" class="avatar"> Pistrie:</div>
<blockquote>
<p>Why bother with refresh tokens if they can regenerate access tokens? It seems like misleading security. It’s just an extra step for the attacker. Instead of using the access token directly, he uses the stolen refresh token to generate a new access token.</p>
</blockquote>
</aside>
<p>If you are keeping the refresh token in the client then it will be available to be stolen. Refresh tokens must be kept on the server side. When using tokens I personally prefer to refresh them on each API request. In other words an issued token last as long its used for the first time, but this isn’t enough to prevent an attacker from exploiting and abuse your backend, no matter if using cookies or token based authentication/authorization.</p>
<aside class="quote no-group" data-username="dorgan" data-post="14" data-topic="49702">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/dorgan/48/22107_2.png" class="avatar"> dorgan:</div>
<blockquote>
<p>Now if the API is either:<br>
A- Intended to be consumed by a first-party client like a mobile app<br>
B- Intended to be consumed by third parties</p>
</blockquote>
</aside>
<p>For a traditional web app requests (no Javascript) I prefer to use cookies with the <code>HttpOnly</code> flag set to not allow  Javascript to access them and the <code>Secure</code> flag set.for them to only be sent in HTTPS connections. I also harden its usage with other flags, that you can read more about in the Mozilla docs at  <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#restrict_access_to_cookies" rel="noopener nofollow ugc">Restrict access to cookies</a>.</p>
<p>For mobile apps you are better to use some secret, be it in whatever form you choose, like a JWT or an hashed string. Cookies on mobile apps can be used but they will not give the same guarantees of a browser.</p>
<p>Keeping a secret private in the client is where things become very tricky, because in a web app you just hit F12 to open the developer console and then you search and extract it. On a mobile app you have a lot of open source tools and methodologies to help you to extract secrets used to access backends.</p>
<p>This morning I replied to a question in Stackoverflow where I go in more detail on the steps to secure a secret in the mobile app:</p>
<aside class="onebox stackexchange" data-onebox-src="https://stackoverflow.com/questions/73464722/storing-api-keys-securely-in-flutter-or-sending-payment-details-to-my-server/73472087#73472087">
  <header class="source">

      <a href="https://stackoverflow.com/questions/73464722/storing-api-keys-securely-in-flutter-or-sending-payment-details-to-my-server/73472087#73472087" target="_blank" rel="noopener nofollow ugc">stackoverflow.com</a>
  </header>

  <article class="onebox-body">
      <a href="https://stackoverflow.com/users/6454622/exadra37" target="_blank" rel="noopener nofollow ugc">
    <img alt="Exadra37" src="https://i.sstatic.net/I8rOa.jpg?s=256" class="thumbnail onebox-avatar" width="256" height="256">
  </a>

<h4>
  <a href="https://stackoverflow.com/questions/73464722/storing-api-keys-securely-in-flutter-or-sending-payment-details-to-my-server/73472087#73472087" target="_blank" rel="noopener nofollow ugc">Storing Api Keys Securely in Flutter or Sending Payment Details to my Server?</a>
</h4>

<div class="tags">
  <strong>flutter, rest, security, api-key</strong>
</div>

<div class="date">
  
  answered by
  <a href="https://stackoverflow.com/users/6454622/exadra37" target="_blank" rel="noopener nofollow ugc">
    Exadra37
  </a>
  on <a href="https://stackoverflow.com/questions/73464722/storing-api-keys-securely-in-flutter-or-sending-payment-details-to-my-server/73472087#73472087" target="_blank" rel="noopener nofollow ugc">11:10AM - 24 Aug 22 UTC</a>
</div>

  </article>

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

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

<p>On my reply I address to the following topics:</p>
<blockquote>
<blockquote>
<p><a href="https://blog.approov.io/how-to-extract-an-api-key-from-a-mobile-app-with-static-binary-analysis" rel="noopener nofollow ugc">How to Extract an API key from a Mobile App with Static Binary Analysis</a>:</p>
<p>The range of open source tools available for reverse engineering is huge, and we really can’t scratch the surface of this topic in this article, but instead we will focus in using the <a href="https://github.com/MobSF/Mobile-Security-Framework-MobSF" rel="noopener nofollow ugc">Mobile Security Framework(MobSF)</a> to demonstrate how to reverse engineer the APK of our mobile app. MobSF is a collection of open source tools that present their results in an attractive dashboard, but the same tools used under the hood within MobSF and elsewhere can be used individually to achieve the same results.</p>
<p>During this article we will use the <a href="https://github.com/MobSF/Mobile-Security-Framework-MobSF" rel="noopener nofollow ugc">Android Hide Secrets</a> research repository that is a dummy mobile app with API keys hidden using several different techniques.</p>
</blockquote>
<blockquote>
<p><a href="https://blog.approov.io/securing-https-with-certificate-pinning-on-android" rel="noopener nofollow ugc">Securing HTTPS with Certificate Pinning</a>:</p>
<p>In order to demonstrate how to use certificate pinning for protecting the https traffic between your mobile app and your API server, we will use the same <a href="https://github.com/approov/currency-converter-demo/tree/0.2.0" rel="noopener nofollow ugc">Currency Converter Demo</a> mobile app that I used in the previous article.</p>
<p>In this article we will learn what certificate pinning is, when to use it, how to implement it in an Android app, and how it can prevent a MitM attack.</p>
</blockquote>
<p>On this article you will learn how to use the <a href="https://approov.io/tools/static-pinning/" rel="noopener nofollow ugc">Mobile Certificate Pinning Generator</a> free tool to easily generate your Android and iOS configurations.</p>
<blockquote>
<p><a href="https://blog.approov.io/how-to-bypass-certificate-pinning-with-frida-on-an-android-app" rel="noopener nofollow ugc">How to Bypass Certificate Pinning with Frida on an Android App</a>:</p>
<p>Today I will show how to use the Frida instrumentation framework to hook into the mobile app at runtime and instrument the code in order to perform a successful MitM attack even when the mobile app has implemented certificate pinning.</p>
<p>Bypassing certificate pinning is not too hard, just a little laborious, and allows an attacker to understand in detail how a mobile app communicates with its API, and then use that same knowledge to automate attacks or build other services around it.</p>
</blockquote>
<p>Frida is a very powerful tool and when used by a skilled attacker it will allow him to even hook to your app code to extract any secret from it without the need to disable pinning to perform the MitM attack. The attacker only needs to figure out the name of the function that uses or retrieves the secret in order to hook on it at runtime and extract such secret. To find the name of the function the attacker will statically reverse the mobile app binary and read your source code, even if the code is obfuscated.</p>
<blockquote>
<p><a href="https://approov.io/blog/hands-on-mobile-app-and-api-security-runtime-secrets-protection" rel="noopener nofollow ugc">Hands-on Mobile App and API Security - Runtime Secrets Protection</a></p>
<p>In a previous article we saw how to protect API keys by using Mobile App Attestation and delegating the API requests to a Proxy. This blog post will cover the situation where you can’t delegate the API requests to the Proxy, but where you want to remove the API keys (secrets) from being hard-coded in your mobile app to mitigate against the use of static binary analysis and/or runtime instrumentation techniques to extract those secrets.</p>
<p>We will show how to have your secrets dynamically delivered to genuine and unmodified versions of your mobile app, that are not under attack, by using Mobile App Attestation to secure the just-in-time runtime secret delivery. We will demonstrate how to achieve this with the same Astropiks mobile app from the previous article. The app uses NASA’s picture of the day API to retrieve images and descriptions, which requires a registered API key that will be initially hard-coded into the app.</p>
</blockquote>
</blockquote>
<p>At the end of the day your backend needs to know with a very high degree of confidence <strong>WHAT</strong> is doing the the request, not only <strong>WHO</strong> is in the request. Think of the <strong>who</strong> as the user on which the request is being done and think on the <strong>what</strong> as the thing issuing the request. is it a genuine and unmodifeied version of your app or it’s the request being made by a bot, a tool in the likes of Postman , a cURL request, etc.. For your backend to be protected against being abused and exploited it needs to have a very high degree of confidence that the requests are only from trusted clients, aka you app, not any other origin, otherwise is like closing you home doors and leaving the windows open.</p>
<p>If you want to learn more about API and Mobile security I invite you to read some of my answers on Stackoverflow:</p>
<p><a href="https://stackoverflow.com/users/6454622/exadra37?tab=answers&amp;sort=newest" class="onebox" target="_blank" rel="noopener nofollow ugc">https://stackoverflow.com/users/6454622/exadra37?tab=answers&amp;sort=newest</a></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="259325" data-batch-url="/posts/batch_likers">
                        7
                      </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/do-refresh-tokens-provide-a-false-sense-of-security/49702/29">Post #28</a>
	                </div>
	            </div>
              <div id="likers-container-259325" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="259325"
                     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 #28"></div>
  </section>
</div>
    <div class="postbit" id="259326" data-post-id="259326">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="Exadra37" data-post="29" data-topic="49702">
<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>Cookies on mobile apps can be used but they will not give the same guarantees of a browser.</p>
</blockquote>
</aside>
<p>can you expand briefly on that one? I’m curious</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="259326" 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/do-refresh-tokens-provide-a-false-sense-of-security/49702/30">Post #29</a>
	                </div>
	            </div>
              <div id="likers-container-259326" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="259326"
                     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 #29"></div>
  </section>
</div>
    <div class="postbit" id="259340" data-post-id="259340">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>So in the case where you want some API to be used by legit mobile clients only, this is a problem. But if the API is open to web requests (like a react or vue app) then what would you use?</p>
<p>For such web apps I generally use cookies. I don’t understand why some people bother with tokens and al’ since having a traditional session is so easy anyway.  (yes it will not be “pure” REST but who cares, it’s an app, not just an API, and it’s been a long time, but IIRC there are options to let fetch/xhr request to send session cookies when they are http only). In that case, would you use the cookie in the mobile app as well?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="259340" 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/do-refresh-tokens-provide-a-false-sense-of-security/49702/31">Post #30</a>
	                </div>
	            </div>
              <div id="likers-container-259340" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="259340"
                     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 #30"></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/49702/load_more?page=4">Load more posts (18 remaining)</a>
</div></template></turbo-stream>