TypeScript Unsafe Type Guard
Description
Type guards that always return true or use assertions without validation create type confusion, allowing untrusted data to bypass security checks.
What Shoulder detects
How to fix
Implement proper runtime validation in type guards.
```typescript
function isUser(obj: unknown): obj is User {
if (typeof obj !== 'object' || obj === null) {
return false;
}
const u = obj as Record<string, unknown>;
return (
typeof u.id === 'number' &&
typeof u.email === 'string'
);
}
```
Learn more: https://shoulder.dev/learn/typescript/cwe-704/unsafe-type-guard
Applies to
Languages
Frameworks
typescript
References
Scan for this issue
Detect with Shoulder CLI
npx @shoulderdev/cli trust --rule=typescript-unsafe-type-guard .