Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
200 changes: 191 additions & 9 deletions ui-customizations/src/components/agentgateway-logo.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,192 @@
export function AgentgatewayLogo({ className }: { className?: string }) {
return (
<img
src="/ui/images/unitone-logo.png"
alt="UnitOne"
className={className}
style={{ objectFit: "contain" }}
/>
);
# Remediation Plan:

**Severity:** medium
**Category:** threat-model
**Estimated Effort:** 4-6 hours

## Summary
Implement threat modeling and security controls for the agentgateway-logo.tsx component to address potential UI-based security vulnerabilities including XSS, data exposure, and content security policy violations

## Affected Components
- ui-customizations/src/components/agentgateway-logo.tsx

## Implementation Steps
### Step 1: Analyze current component for security vulnerabilities
Review the agentgateway-logo.tsx component for potential security issues including unsafe prop handling, external resource loading, and DOM manipulation vulnerabilities

**Example code:**
```python
// Review for patterns like:
// - dangerouslySetInnerHTML usage
// - External image/resource URLs
// - User-controlled props
// - Event handlers with unsafe operations
```

_Note: Document all findings and potential attack vectors_

### Step 2: Implement input validation and sanitization
Add proper validation for all props and sanitize any user-controlled content to prevent XSS attacks

**Files to modify:**
- `ui-customizations/src/components/agentgateway-logo.tsx`

**Example code:**
```python
import DOMPurify from 'dompurify';
import { z } from 'zod';

const LogoPropsSchema = z.object({
src: z.string().url().optional(),
alt: z.string().max(100),
className: z.string().optional(),
onClick: z.function().optional()
});

interface LogoProps {
src?: string;
alt: string;
className?: string;
onClick?: () => void;
}

export const AgentGatewayLogo: React.FC<LogoProps> = (props) => {
const validatedProps = LogoPropsSchema.parse(props);
const sanitizedAlt = DOMPurify.sanitize(validatedProps.alt);
// ... rest of component
};
```

_Note: Use zod for runtime validation and DOMPurify for content sanitization_

### Step 3: Implement Content Security Policy compliance
Ensure the component complies with CSP by avoiding inline styles and using only trusted image sources

**Files to modify:**
- `ui-customizations/src/components/agentgateway-logo.tsx`

**Example code:**
```python
// Use CSS classes instead of inline styles
const logoClasses = {
container: 'logo-container',
image: 'logo-image',
fallback: 'logo-fallback'
};

// Whitelist allowed domains for logo sources
const ALLOWED_LOGO_DOMAINS = [
'https://trusted-cdn.example.com',
'https://assets.company.com'
];

const isValidLogoSource = (src: string): boolean => {
try {
const url = new URL(src);
return ALLOWED_LOGO_DOMAINS.some(domain => src.startsWith(domain));
} catch {
return false;
}
};
```

_Note: Define allowed domains in environment configuration_

### Step 4: Add error handling and fallback mechanisms
Implement secure error handling to prevent information disclosure and provide safe fallbacks

**Files to modify:**
- `ui-customizations/src/components/agentgateway-logo.tsx`

**Example code:**
```python
const [imageError, setImageError] = useState(false);
const [loading, setLoading] = useState(true);

const handleImageError = useCallback(() => {
setImageError(true);
setLoading(false);
// Log error securely without exposing sensitive info
console.warn('Logo failed to load, using fallback');
}, []);

const handleImageLoad = useCallback(() => {
setLoading(false);
}, []);

return (
<div className={logoClasses.container}>
{!imageError && validatedProps.src && isValidLogoSource(validatedProps.src) ? (
<img
src={validatedProps.src}
alt={sanitizedAlt}
onError={handleImageError}
onLoad={handleImageLoad}
className={logoClasses.image}
loading="lazy"
/>
) : (
<div className={logoClasses.fallback} aria-label={sanitizedAlt}>
{/* Safe fallback content */}
</div>
)}
</div>
);
```

_Note: Ensure error messages don't expose internal system information_

### Step 5: Add security-focused unit tests
Create comprehensive test cases that verify security controls and validate threat mitigation

**Files to modify:**
- `ui-customizations/src/components/__tests__/agentgateway-logo.test.tsx`

**Example code:**
```python
describe('AgentGatewayLogo Security Tests', () => {
test('rejects malicious XSS payloads in alt text', () => {
const maliciousAlt = '<script>alert("xss")</script>';
expect(() => render(<AgentGatewayLogo alt={maliciousAlt} />))
.toThrow();
});

test('rejects unauthorized image sources', () => {
const maliciousSource = 'https://evil.com/logo.png';
render(<AgentGatewayLogo src={maliciousSource} alt="test" />);
expect(screen.queryByRole('img')).not.toBeInTheDocument();
});

test('sanitizes user-controlled content', () => {
const userInput = 'Logo<img src=x onerror=alert(1)>';
render(<AgentGatewayLogo alt={userInput} />);
expect(screen.getByText(/Logo/)).not.toHaveTextContent('<img');
});
});
```

_Note: Include tests for all identified attack vectors and security controls_

## Security Considerations
- Validate and sanitize all user-controlled inputs to prevent XSS attacks
- Implement Content Security Policy compliance to prevent code injection
- Use allowlists for external resource domains to prevent data exfiltration
- Ensure error handling doesn't expose sensitive system information
- Implement proper access controls if logo customization is user-configurable

## Best Practices
- Use TypeScript strict mode and runtime validation with libraries like zod
- Implement defense-in-depth with multiple layers of input validation
- Use CSS classes instead of inline styles for CSP compliance
- Implement proper error boundaries and fallback mechanisms
- Follow React security best practices for component development
- Regular security testing and code review for UI components

## Acceptance Criteria
- [ ] All user inputs are validated and sanitized before rendering
- [ ] Component passes security-focused unit tests including XSS prevention
- [ ] External resource loading is restricted to allowlisted domains
- [ ] Error handling does not expose sensitive information
- [ ] Component complies with Content Security Policy requirements
- [ ] No use of dangerouslySetInnerHTML or other unsafe React patterns
- [ ] Proper TypeScript types and runtime validation are implemented
Loading