File tree Expand file tree Collapse file tree 2 files changed +23
-11
lines changed
Expand file tree Collapse file tree 2 files changed +23
-11
lines changed Original file line number Diff line number Diff line change 1414 " Retrieves the public key text from the github api for the key
1515 identifier, then converts the key text to a key object."
1616 [identifier]
17- (->> (client/get " https://api.github.com/meta/public_keys/token_scanning"
18- {:as :json })
19- :body
20- :public_keys
21- (some (fn [{:keys [key_identifier key]}]
22- (when (= identifier key_identifier)
23- key)))
24- (keys/str->public-key )))
17+ (when identifier
18+ (some->> (client/get " https://api.github.com/meta/public_keys/token_scanning"
19+ {:as :json })
20+ :body
21+ :public_keys
22+ (some (fn [{:keys [key_identifier key]}]
23+ (when (= identifier key_identifier)
24+ key)))
25+ (keys/str->public-key ))))
2526
2627(defn- valid-github-request?
2728 " Verifies the request was signed using GitHub's key.
2829 https://developer.github.com/partnerships/secret-scanning/"
2930 [headers body-str]
3031 (let [key-id (get headers " github-public-key-identifier" )
3132 key-sig (get headers " github-public-key-signature" )
32- key (get-github-key key-id)
33- sig (base64/decode key-sig)]
34- (dsa/verify body-str sig {:key key :alg :ecdsa+sha256 })))
33+ key (get-github-key key-id)]
34+ (when (and body-str key key-sig)
35+ (dsa/verify body-str
36+ (base64/decode key-sig)
37+ {:key key :alg :ecdsa+sha256 }))))
3538
3639; ; - make emails async
3740; ; - add timing logs
Original file line number Diff line number Diff line change 4343 (filter-some #(= token-name (:name %))
4444 (db/find-user-tokens-by-username help/*db* username)))
4545
46+ (deftest test-github-token-breach-request-with-invalid-identifier
47+ (help/with-test-system
48+ (with-redefs [client/get (constantly {:body github-response})]
49+ (let [app (help/app-from-system )
50+ request (-> (build-breach-request " whatever" )
51+ (header " GITHUB-PUBLIC-KEY-IDENTIFIER" " bad" ))
52+ res (app request)]
53+ (is (= 422 (:status res)))))))
54+
4655(deftest test-github-token-breach-reporting-works
4756 (help/with-test-system
4857 (let [_user (db/add-user help/*db* " ham@biscuit.co" " ham" " biscuit" )
You can’t perform that action at this time.
0 commit comments