SKY-D208 · Security in code
Weak SHA-1 hash
SHA-1 is a hash function that is no longer collision-resistant: two different inputs with the same SHA-1 hash have been produced in practice. SKY-D208 reports code that computes a SHA-1 hash.
- Languages
- Python, TypeScript/JavaScript, Go, Java, Rust
- Quality gate
- counted toward the gate limits (full and diff scans). Low-risk SHA-1 findings that the terminal list leaves out are still in the JSON output and still count toward
max_security. - Finding type
- review
- Catalog name
- Weak SHA1 hash
- Go engine ID
- SKY-G208, reported as SKY-D208
Why it matters
A SHA-1 fingerprint or signature can be matched by a forged document or certificate, and SHA-1 is fast enough that hashed passwords or short keys are cheap to brute-force if the table leaks.
What Skylos flags
import hashlibimport secrets def issue_api_key(db, account_id: int) -> str: api_key = secrets.token_urlsafe(32) key_hash = hashlib.sha1(api_key.encode()).hexdigest() db.execute( "INSERT INTO api_keys (account_id, key_hash) VALUES (?, ?)", (account_id, key_hash), ) return api_keyWhat Skylos leaves alone
import hashlibimport hmac def legacy_signature_matches(secret: bytes, body: bytes, header: str) -> bool: expected = "sha1=" + hmac.new(secret, body, hashlib.sha1).hexdigest() return hmac.compare_digest(expected, header)Why Skylos leaves it alone
hashlib.sha1 is passed to hmac.new() as a reference, not called, so there is no SHA-1 call to report. HMAC-SHA1 does not rely on collision resistance and is still accepted for message authentication, for example to check the X-Hub-Signature header older webhook senders use.
More languages
Go
Flagged
package keys import ( "crypto/sha1" "encoding/hex") func Fingerprint(apiKey string) string { sum := sha1.Sum([]byte(apiKey)) return hex.EncodeToString(sum[:])}module example.com/keys go 1.22Not flagged
package keys import ( "crypto/sha256" "encoding/hex") func Fingerprint(apiKey string) string { sum := sha256.Sum256([]byte(apiKey)) return hex.EncodeToString(sum[:])}Why Skylos leaves it alone
The Go engine reports only calls to New and Sum in crypto/sha1 (and crypto/md5 for SKY-D207). sha256.Sum256 is not one of them.
How Skylos decides
- In Rust the input must be exposed SecretString contents or its bytes. Skylos resolves SHA-1 digest calls from sha1 or OpenSSL.
- Runs with
--danger. In Python it finds calls tohashlib.sha1(), including import aliases such asfrom hashlib import sha1, andhashlib.new("sha1", …)with a literal algorithm name. A reference that is not called, such ashmac.new(key, msg, hashlib.sha1), is not a call and is not reported. - Skips a Python call that passes
usedforsecurity=Falseas a literal. Test files are not skipped. - Looks at what is hashed: the data argument, values assigned to those names earlier in the same function, and
.update()arguments on the hash object. When none of these names looks like a credential, identity or certificate (password,token,secret,api_key,user_id,session_id,certand similar), the finding is marked low-risk: left out of the terminal list unless you pass--all-advice, but kept in JSON and counted by the gate. - In TypeScript and JavaScript it reports
<object>.createHash("sha1")with a literal string, with the same low-risk mark for a chained.update(x)whose names are not sensitive. - In Go every call to
sha1.Neworsha1.Sumfromcrypto/sha1is reported (by the Go engine as SKY-G208, shown as SKY-D208). - In Java it reports
getInstance("SHA1"),getInstance("SHA-1")andgetInstance("sha1")with a literal string, andMessageDigest.getInstance(name)whennameis a constant holding one of those.
How to fix it
Use SHA-256 or stronger for fingerprints of random keys and for signatures, a password hash (scrypt, argon2, bcrypt) for passwords, and keep SHA-1 only where a protocol requires it, such as HMAC-SHA1 or Git object IDs (with usedforsecurity=False in Python).
import hashlibimport secrets def issue_api_key(db, account_id: int) -> str: api_key = secrets.token_urlsafe(32)Removed: key_hash = hashlib.sha1(api_key.encode()).hexdigest()Added: key_hash = hashlib.sha256(api_key.encode()).hexdigest() db.execute( "INSERT INTO api_keys (account_id, key_hash) VALUES (?, ?)", (account_id, key_hash), ) return api_keyWhen it can be wrong
- SHA-1 required by an outside format, such as Git object IDs, BitTorrent info hashes or a partner API, is reported. In Python and TypeScript it is only hidden from the terminal list when the hashed names are not sensitive; it still counts for the gate.
- Go reports every
sha1.New/sha1.Sumcall, whatever is hashed. - Missed: in TypeScript,
createHash("sha1")imported by name (not called on an object), and an algorithm name held in a variable.
Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.
How to silence it
Mark a reviewed line, or in Python pass
usedforsecurity=False, which also documents the intent.Python oid = hashlib.sha1(header + blob).hexdigest() # skylos: ignore[SKY-D208] Git object IDAccept the findings you already have with
skylos baseline ., then scan with--baselineso only new ones are listed.[tool.skylos] ignore = ["SKY-D208"]turns the rule off for the whole project.