- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- Administrator's Guide
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
ID: ruby-security/no-sha1-digest
Language: Ruby
Severity: Warning
Category: Security
CWE: 328
The rule “Avoid SHA1 to generate hashes” is important as it helps to maintain the integrity and security of your data. SHA1 is a widely used cryptographic hash function that produces a 160-bit hash value, however, it is no longer considered secure against well-funded attackers. In 2005, cryptanalysts found attacks on SHA1 suggesting that the algorithm might not be secure enough for ongoing use.
The weakness of SHA1 lies in its inability to avoid hash collisions, which occur when two different inputs produce the same hash output. This can be exploited by attackers to mimic a data piece without having its actual content, leading to potential security risks and data integrity issues.
To avoid violating this rule, use more secure hash functions such as SHA256 or SHA3. In Ruby, you can use Digest::SHA256.hexdigest 'foo'
or OpenSSL::Digest::SHA256.new
to generate a SHA256 hash. Similarly, for HMAC, use OpenSSL::HMAC.hexdigest("SHA256", key, data)
. By using these more secure hash functions, you can ensure the integrity and security of your data.
require 'digest'
class Bad_md5
def bad_md5_code()
sha = Digest::SHA1.hexdigest 'foo'
sha = Digest::SHA1.new
sha = Digest::SHA1.base64digest 'foo'
sha = Digest::SHA1.digest 'foo'
digest = OpenSSL::Digest::SHA1.new
digest = OpenSSL::Digest::SHA1.hexdigest 'foo'
digest = OpenSSL::Digest::SHA1.new
digest = OpenSSL::Digest::SHA1.base64digest 'foo'
digest = OpenSSL::Digest::SHA1.digest 'foo'
OpenSSL::HMAC.hexdigest("sha1", key, data)
OpenSSL::HMAC.hexdigest("SHA256", key, data)
digest = OpenSSL::Digest::SHA256.new
digest = OpenSSL::Digest::SHA256.hexdigest 'foo'
end
end