Skip to main content

SKY-D208 · Security in code

Weak SHA-1 hash

MediumCWE-328

Every SHA-1 finding is MEDIUM. In Python and TypeScript/JavaScript, a SHA-1 hash over data whose names do not look like a credential, identity or certificate stays MEDIUM but is marked low-risk and left out of the terminal list.

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
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

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

app/api_keys.py · PythonReported on line 7
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_key

What Skylos leaves alone

app/webhooks.py · Python
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

keys/fingerprint.go · GoReported on line 9
package keys import (	"crypto/sha1"	"encoding/hex") func Fingerprint(apiKey string) string {	sum := sha1.Sum([]byte(apiKey))	return hex.EncodeToString(sum[:])}
go.mod · Text
module example.com/keys go 1.22

Not flagged

keys/fingerprint.go · Go
package keys import (	"crypto/sha256"	"encoding/hex") func Fingerprint(apiKey string) string {	sum := sha256.Sum256([]byte(apiKey))	return hex.EncodeToString(sum[:])}

go.mod: same as in the flagged example.

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

  1. In Rust the input must be exposed SecretString contents or its bytes. Skylos resolves SHA-1 digest calls from sha1 or OpenSSL.
  2. Runs with --danger. In Python it finds calls to hashlib.sha1(), including import aliases such as from hashlib import sha1, and hashlib.new("sha1", …) with a literal algorithm name. A reference that is not called, such as hmac.new(key, msg, hashlib.sha1), is not a call and is not reported.
  3. Skips a Python call that passes usedforsecurity=False as a literal. Test files are not skipped.
  4. 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, cert and 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.
  5. 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.
  6. In Go every call to sha1.New or sha1.Sum from crypto/sha1 is reported (by the Go engine as SKY-G208, shown as SKY-D208).
  7. In Java it reports getInstance("SHA1"), getInstance("SHA-1") and getInstance("sha1") with a literal string, and MessageDigest.getInstance(name) when name is 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).

app/api_keys.py · Python · the fix, against the flagged file
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_key

When 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.Sum call, 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 ID
  • Accept the findings you already have with skylos baseline ., then scan with --baseline so only new ones are listed.

  • [tool.skylos] ignore = ["SKY-D208"] turns the rule off for the whole project.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.