File tree Expand file tree Collapse file tree 2 files changed +19
-6
lines changed
Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ receivers:
4040 - url : ' https://my-matrix-alertmanager.tld/alerts'
4141 http_config :
4242 authorization :
43+ type : Bearer
4344 credentials : ' veryverysecretkeyhere'
4445` ` `
4546
Original file line number Diff line number Diff line change 11const client = require ( './client' )
22const utils = require ( './utils' )
33
4+ const crypto = require ( 'crypto' )
5+
6+ const passwordsEqual = ( a , b ) => {
7+ return a && b && a . length === b . length && crypto . timingSafeEqual ( Buffer . from ( a ) , Buffer . from ( b ) )
8+ }
9+
410const routes = {
511 getRoot : ( req , res ) => {
612 res . send ( 'Hey 👋' )
713 } ,
814 postAlerts : async ( req , res ) => {
9- let authorized = false ;
10- let expectedSecret = process . env . APP_ALERTMANAGER_SECRET ;
15+ let authorized = false
16+ let expectedSecret = process . env . APP_ALERTMANAGER_SECRET
17+
18+ if ( ! expectedSecret ) {
19+ console . error ( "APP_ALERTMANAGER_SECRET is not configured, unable to authenticate requests" )
20+ res . status ( 500 ) . end ( )
21+ return
22+ }
1123
12- if ( req . query . secret === expectedSecret ) {
13- authorized = true ;
24+ if ( passwordsEqual ( req . query . secret , expectedSecret ) ) {
25+ authorized = true
1426 }
1527
16- if ( req . get ( 'authorization' ) === `Bearer ${ expectedSecret } ` ) {
17- authorized = true ;
28+ if ( passwordsEqual ( req . get ( 'authorization' ) , `Bearer ${ expectedSecret } ` ) ) {
29+ authorized = true
1830 }
1931
2032 if ( ! authorized ) {
You can’t perform that action at this time.
0 commit comments