Loading...
Loading...
Compare original and translation side by side
undefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedquality-gate--rules=security--rules=memory-safety--rules=concurrencyubs scan <changed-files> --rules=<risk-based> --format=jsonquality-gate--rules=security--rules=memory-safety--rules=concurrencyubs scan <changed-files> --rules=<risk-based> --format=jsonundefinedundefined{file}:{line}{file}:{line}ubs scan ./src --severity=high,criticalubs-report.sarifundefined{file}:{line}{file}:{line}ubs scan ./src --severity=high,criticalubs-report.sarifundefined**UBS Finding**: [{severity}] {rule-id}
**Location**: `{file}:{line}`
**Issue**: {description}
**Impact**: {what could go wrong}
**Fix**: {how to remediate}
```{language}
// Before (vulnerable)
{problematic code}
// After (fixed)
{corrected code}undefined**UBS检测结果**: [{severity}] {rule-id}
**位置**: `{file}:{line}`
**问题**: {description}
**影响**: {可能导致的问题}
**修复方案**: {如何修复}
```{language}
// 修复前(存在漏洞)
{problematic code}
// 修复后(已修复)
{corrected code}undefined// UBS-JS-001: Unguarded property access
// Before
const name = user.profile.name;
// After
const name = user?.profile?.name ?? 'Unknown';// UBS-JS-001: 未受保护的属性访问
// 修复前
const name = user.profile.name;
// 修复后
const name = user?.profile?.name ?? 'Unknown';// UBS-JS-042: Missing await on async function
// Before
function process() {
fetchData(); // Silent failure if this rejects
}
// After
async function process() {
await fetchData();
}// UBS-JS-042: 异步函数缺失await
// 修复前
function process() {
fetchData(); // 若拒绝则静默失败
}
// 修复后
async function process() {
await fetchData();
}// UBS-RUST-017: Unbounded Vec from untrusted input
// Before
fn parse(count: usize) -> Vec<Item> {
Vec::with_capacity(count) // DoS vector
}
// After
const MAX_ITEMS: usize = 10_000;
fn parse(count: usize) -> Result<Vec<Item>, Error> {
if count > MAX_ITEMS {
return Err(Error::TooManyItems);
}
Ok(Vec::with_capacity(count))
}// UBS-RUST-017: 来自不可信输入的无界Vec分配
// 修复前
fn parse(count: usize) -> Vec<Item> {
Vec::with_capacity(count) // 拒绝服务攻击向量
}
// 修复后
const MAX_ITEMS: usize = 10_000;
fn parse(count: usize) -> Result<Vec<Item>, Error> {
if count > MAX_ITEMS {
return Err(Error::TooManyItems);
}
Ok(Vec::with_capacity(count))
}undefinedundefinedundefinedundefined// UBS-GO-012: Unclosed file handle
// Before
func read(path string) []byte {
f, _ := os.Open(path)
data, _ := io.ReadAll(f)
return data // f never closed
}
// After
func read(path string) ([]byte, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
return io.ReadAll(f)
}// UBS-GO-012: 未关闭的文件句柄
// 修复前
func read(path string) []byte {
f, _ := os.Open(path)
data, _ := io.ReadAll(f)
return data // f从未关闭
}
// 修复后
func read(path string) ([]byte, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
return io.ReadAll(f)
}undefinedundefinedundefinedundefined