Snyk 웹훅 연결 테스트

Snyk 웹훅은 새로운 취약점이 발견될 때만 업데이트되지만, Postman을 사용하여 구현 내용을 테스트할 수 있습니다.

Postman이 없는 경우 여기arrow-up-right에서 무료로 설치할 수 있습니다.

테스트를 위해, API 토큰으로 보안 처리된 샘플 페이로드가 포함된 POST 요청을 AWS API Gateway로 보낼 것입니다.

연결을 테스트하려면 다음 단계를 따르십시오.

  1. Postman을 설치합니다.

  2. Collection을 생성합니다.

    새로운 Postman Collection 생성
  3. 컬렉션의 환경 변수로 API 토큰(secret-string)을 추가합니다. 변수 이름을 x-hub-signature로 지정하여 페이로드의 무결성을 검증하는 데 사용할 수 있도록 합니다. API 토큰을 찾는 방법은 Snyk 웹훅 설정을 참조하십시오.

    새로운 Postman Collection 생성
  4. 컬렉션 내에 새로운 HTTP Request를 생성합니다.

    Postman API Request 생성
  5. 메서드를 POST로 변경하고 AWS API Gateway URL 또는 Function URL을 추가합니다. URL을 찾는 방법은 AWS API Gateway: Snyk을 Slack에 연결하는 POST 메서드 추가를 참조하십시오.

    Postman POST 메서드에 AWS API Gateway URL 추가
  6. 사전 요청 스크립트(Pre-request Script)를 다음 코드와 같이 구성합니다. 이 스크립트는 API 토큰을 가져와 보안 처리를 함으로써 Snyk이 페이로드와 함께 전송할 때 Lambda 함수가 페이로드를 복호화할 수 있도록 합니다. 코드는 다음과 같습니다. 'your-secret-string-here' 부분을 본인의 API 토큰으로 변경해야 합니다. postman.setEnvironmentVariable('x-hub-signature', CryptoJS.HmacSHA256(request.data, 'your-secret-string-here').toString(CryptoJS.digest)); postman.setEnvironmentVariable('x-hub-signature', 'sha256='+ postman.getEnvironmentVariable('x-hub-signature'));\

    Postman 사전 요청 스크립트
  7. Headers를 추가합니다. Content-Type: application/json x-hub-signature {{x-hub-signature}}: (3단계에서 생성한 API 토큰(secret-string) 환경 변수)

    Postman POST 요청 헤더
  8. Body에 유효한 페이로드를 추가합니다. 예를 들어 아래의 내용을 사용하되, 가독성을 위해 형식을 정리(Beautify)하지 마십시오. 읽기 좋게 바뀌면 작동하지 않습니다. {"project":{"id":"bc75a806-0893-4ccf-84c5-8fde48a88df8","name":"snyk/juice-shop:frontend/package.json","created":"2022-06-17T06:54:21.326Z","origin":"github","type":"npm","readOnly":false,"testFrequency":"daily","totalDependencies":1216,"issueCountsBySeverity":{"low":2,"high":16,"medium":17,"critical":0},"imageTag":"12.3.0","imagePlatform":"","lastTestedDate":"2022-06-29T05:45:12.569Z","browseUrl":"https://app.snyk.io/org/api-test/project/bc75a806-0893-4ccf-84c5-8fde48a88df7","importingUser":null,"owner":null,"tags":[],"isMonitored":true,"attributes":{"criticality":[],"lifecycle":[],"environment":[]},"branch":"master"},"org":{"id":"570a1e02-8774-4697-80fc-129f5c5195a1","name":"API","slug":"api-quc","url":"https://app.snyk.io/org/api-test","group":null,"created":"2022-05-25T06:29:29.833Z"},"newIssues":[{"id":"SNYK-JS-SCSSTOKENIZER-2339884","issueType":"vuln","pkgName":"scss-tokenizer","pkgVersions":["0.2.3"],"priorityScore":336,"priority":{"score":336,"factors":[{"name":"isFresh","description":"Recently disclosed"},{"name":"cvssScore","description":"CVSS 5.3"}]},"issueData":{"id":"SNYK-JS-SCSSTOKENIZER-2339884","title":"Regular Expression Denial of Service (ReDoS)","severity":"high","url":"https://snyk.io/vuln/SNYK-JS-SCSSTOKENIZER-2339884","description":"Long description","identifiers":{"CWE":["CWE-1333"],"CVE":["CVE-2022-25758"]},"credit":["Paul Bastide"],"exploitMaturity":"no-known-exploit","semver":{"vulnerable":["*"]},"publicationTime":"2022-06-29T10:29:38Z","disclosureTime":"2022-01-13T16:29:34Z","CVSSv3":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L","cvssScore":5.3,"functions":[],"language":"js","patches":[],"nearestFixedInVersion":"","isMaliciousPackage":false},"isPatched":false,"isIgnored":false,"fixInfo":{"isUpgradable":false,"isPinnable":false,"isPatchable":false,"isFixable":false,"isPartiallyFixable":false,"nearestFixedInVersion":"","fixedIn":[]}}],"removedIssues":[]}

    유효한 페이로드가 포함된 Postman POST 요청 본문
  9. URL 옆의 Send 버튼을 클릭합니다.

  10. Postman 하단에 성공 메시지(statusCode 200)가 표시되는지 확인합니다.

    Postman 성공 메시지
  11. Slack에서 새로운 알림이 표시되는지 확인합니다: 경로, Package name(패키지 이름), scss-tokenizer, Severity level(심각도 수준), Vulnerability name(취약점 이름), 그리고 Priority Score(우선순위 점수)가 포함된 New Snyk Vulnerability 알림입니다.

    새로운 취약점 Slack 알림

    다음에 Snyk이 새로운 취약점을 발견하면 Slack에서 Snyk의 알림을 보게 될 것입니다.

Last updated