Bezpieczne kodowanie
- Walidacja wejścia
- Kodowanie wyjścia
- Najlepsze praktyki uwierzytelniania
- Zarządzanie sesjami
Używanie narzędzi programistycznych opartych na AI w środowiskach korporacyjnych wymaga starannej uwagi na bezpieczeństwo i prywatność. Ten przewodnik obejmuje kompleksowe strategie wdrażania Cursor przy zachowaniu najwyższych standardów bezpieczeństwa.
{ "cursor.privacy.mode": "standard", "cursor.privacy.telemetry": "anonymized", "cursor.privacy.codeSharing": "snippets", "cursor.privacy.retention": "30days"}
{ "cursor.privacy.mode": "enhanced", "cursor.privacy.telemetry": "essential", "cursor.privacy.codeSharing": "none", "cursor.privacy.retention": "7days"}
{ "cursor.privacy.mode": "zero-trust", "cursor.privacy.telemetry": "disabled", "cursor.privacy.codeSharing": "disabled", "cursor.privacy.retention": "none", "cursor.privacy.localProcessing": true}
Skonfiguruj SAML 2.0
# Konfiguracja SAMLsaml: idp: entityId: "https://idp.company.com" ssoUrl: "https://idp.company.com/sso" x509cert: "MIIDpDCCAoygAwIBAgIGAV..." sp: entityId: "cursor-enterprise" assertionConsumerService: "https://cursor.com/saml/acs" attributes: email: "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" name: "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name" groups: "http://schemas.xmlsoap.org/claims/Group"
Włącz prowizjonowanie SCIM
{ "scim": { "enabled": true, "endpoint": "https://api.cursor.com/scim/v2", "bearerToken": "${SCIM_TOKEN}", "userFilter": "department eq 'Engineering'", "groupSync": true }}
Skonfiguruj wymagania MFA
{ "security.mfa": { "required": true, "methods": ["totp", "webauthn", "sms"], "gracePeriod": "0", "rememberDevice": false }}
// Zdefiniuj role bezpieczeństwainterface SecurityRoles { admin: { canManageUsers: true; canViewAllCode: true; canModifySettings: true; canAccessAuditLogs: true; }; developer: { canUseAI: true; canAccessOwnCode: true; canShareContext: false; modelAccess: ['sonnet', 'opus']; }; contractor: { canUseAI: true; canAccessAssignedRepos: true; restrictedFeatures: ['sharing', 'export']; modelAccess: ['sonnet']; }; auditor: { canViewAuditLogs: true; canExportReports: true; canUseAI: false; };}
// Implementuj filtrowanie treściclass SecurityFilter { private patterns = { secrets: [ /api[_-]?key\s*[:=]\s*['"][^'"]+['"]/gi, /password\s*[:=]\s*['"][^'"]+['"]/gi, /AWS[A-Z0-9]{16,}/g, /ghp_[a-zA-Z0-9]{36}/g, /sk-[a-zA-Z0-9]{48}/g ], pii: [ /\b\d{3}-\d{2}-\d{4}\b/g, // SSN /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/gi, // Email /\b(?:\d{4}[-\s]?){3}\d{4}\b/g // Karty kredytowe ], internal: [ /internal\.company\.com/g, /CONFIDENTIAL|SECRET|RESTRICTED/g, /Copyright.*Company Name/g ] };
async filterContent(content: string): Promise<FilterResult> { const violations = [];
for (const [category, patterns] of Object.entries(this.patterns)) { for (const pattern of patterns) { const matches = content.match(pattern); if (matches) { violations.push({ category, pattern: pattern.source, matches: matches.length }); } } }
return { safe: violations.length === 0, violations, sanitized: this.sanitize(content, violations) }; }}
// Bezpieczna konfiguracja serwera MCP{ "mcpServers": { "internal-api": { "command": "node", "args": ["/opt/mcp/internal-api-server.js"], "env": { "API_ENDPOINT": "https://api.internal.company.com", "AUTH_METHOD": "oauth2", "TLS_VERIFY": "true", "ALLOWED_OPERATIONS": "read" }, "security": { "sandbox": true, "networkAccess": "restricted", "allowedHosts": ["*.internal.company.com"], "timeout": 30000 } } }}
{ "http.proxy": "http://proxy.company.com:8080", "https.proxy": "http://proxy.company.com:8080", "http.proxyStrictSSL": true, "http.proxyAuthorization": "Basic ${PROXY_AUTH}", "cursor.proxy.bypass": [ "localhost", "127.0.0.1", "*.internal.company.com" ]}
{ "cursor.network.security": { "tlsVerification": true, "certificatePinning": true, "allowedCertificates": [ "SHA256:XXXXXXXXXX" ], "http2": false, "proxy": { "type": "zscaler", "autoDetect": true } }}
# Zainstaluj certyfikat CA korporacyjnyexport NODE_EXTRA_CA_CERTS=/path/to/company-ca.crt
# Skonfiguruj Cursor{ "http.systemCertificates": true, "http.proxyCA": "/path/to/company-ca.crt", "cursor.network.customCA": { "enabled": true, "path": "/path/to/company-ca.crt" }}
# Wymagane połączenia wychodzącefirewall_rules: - name: "Cursor API" destination: "api.cursor.com" port: 443 protocol: "HTTPS"
- name: "Modele AI" destinations: - "api.anthropic.com" - "api.openai.com" - "generativelanguage.googleapis.com" port: 443 protocol: "HTTPS"
- name: "MCP lokalne" destination: "localhost" ports: [3000-3100] protocol: "TCP"
# Blokuj wszystkie inne wychodzące - name: "Domyślne odrzuć" destination: "*" action: "DENY"
// Implementacja logowania audytuclass AuditLogger { private readonly requiredFields = [ 'timestamp', 'userId', 'action', 'resource', 'result', 'ipAddress', 'sessionId' ];
async logAction(event: AuditEvent): Promise<void> { const entry: AuditEntry = { id: generateUUID(), timestamp: new Date().toISOString(), userId: event.userId, userName: event.userName, action: event.action, resource: event.resource, resourceType: event.resourceType, result: event.result, errorMessage: event.error?.message, ipAddress: event.ipAddress, userAgent: event.userAgent, sessionId: event.sessionId, organizationId: event.orgId, metadata: this.sanitizeMetadata(event.metadata) };
// Loguj do wielu miejsc docelowych await Promise.all([ this.logToSIEM(entry), this.logToDatabase(entry), this.logToFile(entry) ]);
// Alertowanie w czasie rzeczywistym dla wrażliwych działań if (this.isSensitiveAction(event.action)) { await this.alertSecurityTeam(entry); } }}
// Kontroler zgodnościclass ComplianceMonitor { async runComplianceCheck(): Promise<ComplianceReport> { const checks = { gdpr: await this.checkGDPR(), sox: await this.checkSOX(), hipaa: await this.checkHIPAA(), pci: await this.checkPCI() };
return { timestamp: new Date(), checks, violations: this.aggregateViolations(checks), recommendations: this.generateRecommendations(checks) }; }
private async checkGDPR(): Promise<ComplianceResult> { // Sprawdź polityki przechowywania danych // Zweryfikuj implementację prawa do usunięcia // Audytuj działania przetwarzania danych // Waliduj mechanizmy zgody }}
{ "dlp.rules": [ { "name": "Ochrona kodu źródłowego", "patterns": [ "PROPRIETARY", "CONFIDENTIAL", "Trade Secret" ], "action": "block", "severity": "high" }, { "name": "Dane klientów", "patterns": [ "customer_id", "account_number", "billing_address" ], "action": "redact", "severity": "medium" }, { "name": "Klucze API", "regex": "(?:api[_-]?key|token)\\s*[:=]\\s*['\"][^'\"]+['\"]", "action": "block", "alert": true, "severity": "critical" } ]}
// System monitorowania DLPclass DLPMonitor { private violations = new Map<string, Violation[]>();
async monitorContent(content: ContentEvent): Promise<void> { const scan = await this.scanContent(content);
if (scan.violations.length > 0) { // Loguj naruszenie await this.logViolation(scan);
// Podejmij działanie na podstawie ważności switch (scan.highestSeverity) { case 'critical': await this.blockAction(content); await this.alertSecurityTeam(scan); break;
case 'high': await this.requireApproval(content); break;
case 'medium': await this.redactContent(content, scan.violations); break; } } }}
Nigdy nie przechowuj sekretów w kodzie
// ❌ Źleconst apiKey = "sk-1234567890abcdef";
// ✅ Dobrzeconst apiKey = process.env.API_KEY;
Używaj skanowania sekretów
name: Skanowanie sekretówon: [push, pull_request]
jobs: scan: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Uruchom Trufflehog uses: trufflesecurity/trufflehog@main with: path: ./ base: ${{ github.ref }}
Zaimplementuj rotację sekretów
class SecretRotation { async rotateSecrets(): Promise<void> { const secrets = await this.getExpiringSecrets();
for (const secret of secrets) { const newSecret = await this.generateNewSecret(secret); await this.updateSecret(secret.id, newSecret); await this.notifyApplications(secret.id); await this.scheduleOldSecretDeletion(secret); } }}
// Automatyczna reakcja na incydentyclass IncidentResponder { async handleSecurityEvent(event: SecurityEvent): Promise<void> { const severity = this.assessSeverity(event);
// Natychmiastowe działania const response = { id: generateIncidentId(), timestamp: new Date(), event, severity, actions: [] };
// Zawrzyj zagrożenie if (severity >= Severity.HIGH) { await this.containThreat(event); response.actions.push('threat_contained'); }
// Zachowaj dowody await this.preserveEvidence(event); response.actions.push('evidence_preserved');
// Powiadom interesariuszy await this.notifyStakeholders(event, severity); response.actions.push('stakeholders_notified');
// Rozpocznij dochodzenie const investigation = await this.initiateInvestigation(event); response.investigationId = investigation.id;
return response; }}
Bezpieczne kodowanie
Bezpieczeństwo AI
Obsługa danych
Reakcja na incydenty
Standard | Wymagania | Konfiguracja Cursor |
---|---|---|
SOC 2 | Kontrole dostępu, szyfrowanie, monitorowanie | Tryb prywatności, logi audytu, SSO |
ISO 27001 | Zarządzanie ryzykiem, reakcja na incydenty | Reguły DLP, polityki bezpieczeństwa |
GDPR | Ochrona danych, prawa użytkownika | Przechowywanie danych, anonimizacja |
HIPAA | Ochrona PHI, logi dostępu | Wzmocniona prywatność, szyfrowanie |
PCI-DSS | Ochrona danych posiadacza karty | Segmentacja sieci, monitorowanie |
Konfiguracja początkowa
Bezpieczeństwo sieci
Kontrola dostępu
Monitorowanie
Reakcja na incydenty
Bezpieczeństwo i prywatność są fundamentalne dla adopcji AI w przedsiębiorstwach. Opanuj te koncepty, aby umożliwić swojemu zespołowi wykorzystanie mocy AI przy zachowaniu najwyższych standardów bezpieczeństwa.