Mitigation Strategy: Disable Public Sharing
- Mitigation Strategy: Disable Public Sharing
- Description:
- Locate the
iface.launch()
call in your Gradio application code, or theInterface
orBlocks
initialization. - Explicitly set the
share
parameter toFalse
within thelaunch()
function or during interface/blocks creation. Example:iface.launch(share=False)
orgr.Interface(..., share=False)
. - Restart your Gradio application.
- Verify no public shareable link is generated when running the application. Access should be limited to
http://127.0.0.1:port
orhttp://localhost:port
.
- Locate the
- Threats Mitigated:
- Unauthorized Access (High Severity): Prevents public internet access via shareable link.
- Data Breaches (High Severity): Reduces risk by limiting public exposure.
- Denial of Service (DoS) (Medium Severity): Makes public DoS attacks harder.
- Impact: Significantly reduces unauthorized access and data breach risks by restricting access to the local network. Partially reduces DoS risk.
- Currently Implemented: Not Applicable (Example Project)
- Missing Implementation: Not Applicable (Example Project)
Mitigation Strategy: Strict Input Validation (in Gradio Functions)
- Mitigation Strategy: Strict Input Validation (in Gradio Functions)
- Description:
- For each input parameter in Gradio functions, define validation rules (data type, format, length, allowed values).
- Implement validation logic at the start of Gradio functions, before processing inputs.
- Use Python features/libraries for validation.
- Reject invalid inputs with informative error messages (avoiding sensitive details).
- Log invalid input attempts for monitoring.
- Crucially: Do not rely solely on Gradio's input component types for security validation. Always validate server-side within your functions.
- Threats Mitigated:
- Injection Attacks (High Severity): Prevents command, SQL, code injection by ensuring valid inputs.
- Data Integrity Issues (Medium Severity): Ensures data consistency and prevents errors.
- Application Logic Errors (Medium Severity): Reduces crashes from malformed inputs.
- Impact: Significantly reduces injection attack risk and improves data integrity/stability.
- Currently Implemented: Not Applicable (Example Project)
- Missing Implementation: Not Applicable (Example Project)
Mitigation Strategy: Input Size Limits (in Gradio Components)
- Mitigation Strategy: Input Size Limits (in Gradio Components)
- Description:
- Enforce size limits for all Gradio input components (text, file uploads, etc.).
- Limit text input length.
- Limit file upload size.
- Implement limits on both client-side (Gradio component configuration) and server-side (backend functions). Server-side is critical for security.
- Reject oversized inputs with error messages.
- Threats Mitigated:
- Denial of Service (DoS) (Medium Severity): Prevents DoS via large inputs consuming resources.
- Resource Exhaustion (Medium Severity): Prevents resource exhaustion from processing huge inputs.
- Impact: Partially reduces DoS and resource exhaustion risks by limiting input sizes.
- Currently Implemented: Not Applicable (Example Project)
- Missing Implementation: Not Applicable (Example Project)
Mitigation Strategy: Gradio Demo Awareness
- Mitigation Strategy: Gradio Demo Awareness
- Description:
- Recognize that Gradio examples/demos are for demonstration, not production security.
- Review and adapt example code before production deployment.
- Focus on security configurations, input handling, error handling in examples.
- Avoid direct copy-pasting of demo code into production.
- Understand default configurations of examples and adjust for security (e.g.,
share=False
).
- Threats Mitigated:
- Security Misconfiguration (Medium Severity): Prevents insecure configurations from demo code.
- Vulnerabilities from Example Code (Medium Severity): Reduces risk from vulnerabilities in simplified demo code.
- Impact: Partially reduces security misconfiguration and vulnerability risks from using demo code directly.
- Currently Implemented: Not Applicable (Example Project)
- Missing Implementation: Not Applicable (Example Project)
Mitigation Strategy: Custom Component Security
- Mitigation Strategy: Custom Component Security
- Description:
- If developing custom Gradio components, follow secure coding practices.
- Prioritize input handling: validate and sanitize user data within components.
- For HTML rendering in components, use robust HTML escaping/sanitization to prevent XSS.
- Thoroughly test custom components for security vulnerabilities (input validation, XSS, etc.).
- Keep custom components updated and patched.
- Threats Mitigated:
- Cross-Site Scripting (XSS) (Medium to High Severity): Prevents XSS in custom components rendering user HTML.
- Injection Attacks (Medium Severity): Prevents injection vulnerabilities in custom component input processing.
- Component-Specific Vulnerabilities (Variable Severity): Reduces risks from various vulnerabilities in custom code.
- Impact: Reduces XSS, injection, and other vulnerability risks in custom Gradio components.
- Currently Implemented: Not Applicable (Example Project)
- Missing Implementation: Not Applicable (Example Project)