Length Extension attacks in SHA1 and MD5?
You forget one little step of how Merkle–Damgård construction works; the padding, here SHA-1 padding:


  append the bit $\texttt{1}$ to the message e.g. by adding $\texttt{0x80}$ if message length is a multiple of 8 bits.
  
  append $0 \leq k &lt; 512$ bits $\texttt{0}$, such that the resulting message length in bits is congruent to $$−64 \equiv 448 \pmod{512}$$
  
  append ml, the original message length, as a 64-bit big-endian integer. 
     Thus, the total length is a multiple of 512 bits.


Therefore the real input is

$$\text{SHA-1}(\text{secret_key}\mathbin\|\text{known_data}\mathbin\|pad1)$$ 

because the attackers only get the hashed value. And, you need

$$\text{SHA-1}(\text{secret_key}\mathbin\|\text{known_data}\mathbin\| \text{pad1}\mathbin\| 
 \text{appended_data} \mathbin\| \text{pad2})$$ 

for extension attack. This works similarly for any hash function that uses the same padding mechanism.

The attackers can access the hash of a padded message and they can extend it in this way. This is due to the artifact of Merkle–Damgård construction. SHA-3 is safe from this attack by design and later the new SHA2 modes SHA512/256 and SHA512/384 and other truncated versions of SHA2 also have resistance to length extension attack. 

SHA-1 or MD5 is not considered secure. Use modern Hash functions like SHA3 or Blake2 with good output sizes to prevent the generic collision attacks like at least 256-bit.