Zum Hauptinhalt springen
LIVE
CVSS 7.0CVE-2026-138158 | libgphoto2 through 2.5.34 contains a stack buffer overflow in sierra_get_string_register() that lets a malicious sierra-protocol camera or USB device overwrite stack memory. When files are listed, the device can answer the file-name register with an oversized packet, writing up to 32 KB past small stack buffers to cause crashes or possible code execution.CVSS 7.7CVE-2026-138159 | edbrowse through 3.8.19 contains an integer overflow in stringAndBytes() that allows malicious servers to write past a heap buffer by sending response bodies larger than 2 GB. When a user browses to an attacker-controlled HTTP, FTP, or gopher server, the oversized body skips reallocation and corrupts the heap, causing crashes or potentially code execution.CVSS 8.5CVE-2026-138160 | Gammu before 1.45.2 contains a stack-based buffer overflow vulnerability in ReadBackupTextLen() that allows attackers to overwrite stack memory via crafted backup files. Attackers can supply overlong quoted text values decoded into a 10,000-byte stack array during convertbackup, restore, or GSM_ReadBackupFile calls, causing crashes or potential code execution.CVSS 8.5CVE-2026-138161 | Gammu before 1.45.2 contains a buffer overflow vulnerability in LoadBackup() that allows attackers to corrupt memory by supplying an overlong MD5 value in a crafted backup file. Attackers can overwrite adjacent phonebook and calendar entry pointers via strcpy() into MD5Original when files are loaded with convertbackup or restore, causing crashes or potential code execution.CVSS 7.3CVE-2026-138162 | Gammu before 1.45.2 contains a stack-based buffer overflow vulnerability in ALCATEL_EncodeString() that allows attackers to overwrite stack memory via oversized encoded phonebook text. Attackers can supply a crafted backup restored with gammu restore or addnew to an attached Alcatel phone, using GSM extension characters to crash Gammu or potentially execute code.CVSS 8.5CVE-2026-138163 | Gammu before 1.45.2 contains a heap-based buffer overflow in ReadWAPSettingsEntry() that allows attackers to corrupt heap memory via crafted backup files with excess WAP or MMS settings entries. Attackers can supply a backup with more than four TitleNN keys in a [WAPSettings] or [MMSSettings] section, loaded via convertbackup, restore, or GSM_ReadBackupFile, causing crashes or potential code execution.CVSS 4.8CVE-2026-138164 | Gammu before 1.45.2 contains a stack-based buffer overflow vulnerability in SaveBackupText() in backtext.c that allows attackers to corrupt stack memory by supplying long text fields. Attackers can craft a backup with long calendar or note fields that, when converted with gammu convertbackup, writes hex digits past the 10,000-byte stack buffer.CVSS 9.3CVE-2026-138154 | POSTAL 2 before build 26810491 contains a sandbox escape vulnerability that allows malicious Steam Workshop mods to execute code by calling ConsoleCommand with a start file URI. Attackers can ship a batch file in a mod at the predictable workshop install path and launch it via ShellExecuteW, executing commands as the player on Windows.
Alle im Drawer
Intelligence View
⚡ tsecurity.de Intelligence

Type-Safe Env Vars Without Zod

Most TypeScript projects treat environment variables like second-class citizens. They're string | undefined everywhere, asserted with ! and parsed with…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Quelle & Fakten · 3 Min. Lesezeit
Quelle: dev.to
Rubrik: Sichere Programmierung

Most TypeScript projects treat environment variables like second-class citizens. They're string | undefined everywhere, asserted with ! and parsed with parseInt(). TypeScript can't help because process.env is typed as Record<string, string | undefined>.



Schema-based validation fixes this. But most solutions bring zod, which adds 50 KB to your bundle. CtroEnv does it with zero dependencies and 6.5 KB gzipped.






How Inference Works



The type system reads each validator's configuration at compile time:




type InferredValue<V> =
V extends Validator<infer T>
? V["metadata"] extends { hasDefault: true }
? T // .default() → non-nullable
: V["metadata"] extends { optional: true }
? T | undefined // .optional() → nullable
: T // required → guaranteed present
: never






This means the schema defines the type:




const env = defineEnv({
PORT: number().port().default(3000),
// ^? number — default makes it always present

DB_URL: string().url(),
// ^? string — required

DEBUG: boolean().optional(),
// ^? boolean | undefined — optional

NODE_ENV: pick(["dev", "prod", "staging"] as const),
// ^? "dev" | "prod" | "staging" — exact union
})






No interface Env { ... }. No z.infer<typeof Schema>. Add a new validator, and the type updates automatically.






Default vs Optional vs Required



The three states and their types:

































Declaration Type Runtime behavior
string() string Required — throws if missing
string().optional() `string \ undefined`
string().default("x") string Falls back to "x"
string().optional().default("x") string Default overrides optional


TypeScript reflects this exactly. Optional gives you | undefined. Default removes it.






The as const Requirement



pick() needs as const to preserve literal types:




pick(["dev", "prod"])           // type: string — widened
pick(["dev", "prod"] as const) // type: "dev" | "prod" — exact union






Without as const, TypeScript widens the array to string[] and you lose the union.






Exhaustive Checking



With exact literal types, you get exhaustive checking:




switch (env.NODE_ENV) {
case "dev": break
case "prod": break
case "staging": break
// TypeScript error if you forget a case — and you can't match "production"
// because it's not in the union
}









The Chain Order Gotcha



Type-specific methods (.url(), .email(), .min()) must come before chainable methods (.secret(), .optional(), .describe()):




string().url().secret()     // ✅ correct
string().secret().url() // ❌ — .url() doesn't exist after .secret()






Reason: .secret() returns a generic Validator & ChainableMethods wrapper. The type-specific methods like .url() only exist on StringValidator. Once you call a chainable method, those are gone.



Quick reference:




// ✅ Correct
string().min(1).max(255).url().secret()
number().int().positive().default(42)
pick(["a", "b"] as const).optional()
boolean().default(false)

// ❌ Wrong
string().secret().url() // .url() lost
number().optional().int() // .int() lost






pick(), boolean(), semver(), ip(), uuid() have no type-specific refinements, so chain order doesn't matter for them.






Composing Schemas



defineSchema() + extendSchema() preserve full types through composition:




import { defineSchema, extendSchema } from "@ctroenv/core"

const base = defineSchema({
NODE_ENV: pick(["dev", "prod"] as const).default("dev"),
})

const schema = extendSchema(base, {
PORT: number().port().default(3000),
})

const env = defineEnv(schema)
// env.NODE_ENV: "dev" | "prod"
// env.PORT: number






The composed type merges both schemas. Extension keys override base keys — with a dev-mode warning on conflicts.






Compared to Zod






// zod — 50 KB dependency
import { z } from "zod"
const Schema = z.object({
PORT: z.coerce.number().min(1).max(65535).default(3000),
DB_URL: z.string().url(),
})
type Env = z.infer<typeof Schema>

// CtroEnv — 6.5 KB, zero deps
import { defineEnv, string, number } from "@ctroenv/core"
const env = defineEnv({
PORT: number().port().default(3000),
DB_URL: string().url(),
})
// ^? { PORT: number; DB_URL: string } — inferred automatically






Same validation power. No manual type extraction. No extra dependency.




npm install @ctroenv/core






Links: GitHub · Docs · npm



Previous: Why Your .env File Is Lying to You

Next: Framework-Specific Env Patterns

Information ergänzen Fachhinweis, Update, Korrektur oder Quelle zur Meldung beitragen
Gäste-Hinweise werden kurz redaktionell geprüft und danach hier angezeigt.

Community-Hinweise zur Meldung

0 freigegeben
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!
Informations-Bewertung:

💬 Topluluk tartışması ve yorumlar

🌐 Ana sohbete katıl

Tartışmayı başlat: Social Chat yayın akışı veya yukarıdaki ekleme formuyla uzman katkısı gönder.

Community Rating &amp; Social Proof
⭐ Okuyucu Puanı
–
Ø / 5.0
Hiçbir okuyucu henüz yorum yok
Bu makale yararlı mıydı?
0
Değerlendirmenizi gönderin
Detaylı değerlendirme (isteğe bağlı)
İçerik ve Kalite
Kaynak ve Güvenilirlik
Güncellik
Security Briefing Ücretsiz · Tek tıkla abonelikten çıkma

Zeka Digest - ücretsiz

Günlük en önemli güvenlik haberi · herhangi bir zamanda alınabilir

İlgili Story Cluster & Kaynaklar (vector AI)

2 Cluster
2 Kaynaklar
N: Hyundai bringt Performance-Parts für Elektroautos nach Deutschland
tsecurity.de 3 saat önce
1 başka bir kaynak
Benzer katkılar
🔍 Verwandte News

Auch interessante Nachrichten Type-Safe Env Vars Without Zod

Thematisch verwandte Begriffe: TypeSafe, Vars, Without · 6 Treffer

Laden...

Videolar yükleniyor...

Laden...

Contributions yüklenir ...

Laden...

Videolar yükleniyor...

Laden...

Contributions yüklenir ...

Laden...

Videolar yükleniyor...

Laden...

Contributions yüklenir ...

Laden...

Videolar yükleniyor...

Yorumlar yüklenir..
Update to Update
Widgets & Topics
Loading widgets…
Nächster Beitrag