- 
                Notifications
    
You must be signed in to change notification settings  - Fork 82
 
fix: handle gcf, verify already provided request.body #936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Closed
      
      
    
  
     Closed
                    Changes from 2 commits
      Commits
    
    
            Show all changes
          
          
            13 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      99f265a
              
                fix: handle gcf, verify already provided request.body
              
              
                Uzlopak 030fdc1
              
                Merge branch 'main' into fix-gcf
              
              
                Uzlopak 2064845
              
                fix pr remark
              
              
                Uzlopak b268501
              
                Update src/verify-and-receive.ts
              
              
                Uzlopak 8fe7aa2
              
                use setImmediate to improve the throughput
              
              
                Uzlopak d214e24
              
                stabilize performance
              
              
                Uzlopak 13679ff
              
                lint
              
              
                Uzlopak e043dc3
              
                standardize
              
              
                Uzlopak 2fbd7a3
              
                Apply suggestions from code review
              
              
                Uzlopak ad1ed2d
              
                fix
              
              
                Uzlopak dd1d31f
              
                Update src/middleware/node/get-payload.ts
              
              
                Uzlopak d82fc69
              
                Update src/middleware/node/get-payload.ts
              
              
                Uzlopak a57434e
              
                fix
              
              
                Uzlopak File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -15,6 +15,7 @@ export async function verifyAndReceive( | |
| // verify will validate that the secret is not undefined | ||
| const matchesSignature = await verify( | ||
| state.secret, | ||
| // @ts-expect-error verify uses createHmac, which can take Strings and Buffers | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather not. It's better to fix this at the source There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.  | 
||
| event.payload, | ||
| event.signature, | ||
| ).catch(() => false); | ||
| 
        
          
        
         | 
    @@ -29,18 +30,29 @@ export async function verifyAndReceive( | |
| ); | ||
| } | ||
| 
     | 
||
| let payload: EmitterWebhookEvent["payload"]; | ||
| // The body is already an Object (e.g. GCF) and can be passed directly to the EventHandler | ||
| if (event.body) { | ||
| return state.eventHandler.receive({ | ||
| id: event.id, | ||
| name: event.name, | ||
| payload: event.body as EmitterWebhookEvent["payload"], | ||
| }); | ||
| } | ||
                
      
                  Uzlopak marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| 
     | 
||
| const payload = | ||
| typeof event.payload === "string" | ||
| ? event.payload | ||
| : event.payload.toString("utf8"); | ||
| 
     | 
||
| try { | ||
| payload = JSON.parse(event.payload); | ||
| return state.eventHandler.receive({ | ||
                
      
                  Uzlopak marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| id: event.id, | ||
| name: event.name, | ||
| payload: JSON.parse(payload) as EmitterWebhookEvent["payload"], | ||
| }); | ||
| } catch (error: any) { | ||
| error.message = "Invalid JSON"; | ||
| error.status = 400; | ||
| throw new AggregateError([error]); | ||
| } | ||
| 
     | 
||
| return state.eventHandler.receive({ | ||
| id: event.id, | ||
| name: event.name, | ||
| payload, | ||
| }); | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.