@@ -250,6 +250,7 @@ func (r *Reader) include(ctx context.Context, node Node) error {
250250 AdvancedImport : include .AdvancedImport ,
251251 Excludes : include .Excludes ,
252252 Vars : include .Vars ,
253+ Checksum : include .Checksum ,
253254 }
254255 if err := cache .Err (); err != nil {
255256 return err
@@ -267,6 +268,7 @@ func (r *Reader) include(ctx context.Context, node Node) error {
267268
268269 includeNode , err := NewNode (entrypoint , include .Dir , r .insecure ,
269270 WithParent (node ),
271+ WithChecksum (include .Checksum ),
270272 )
271273 if err != nil {
272274 if include .Optional {
@@ -362,7 +364,24 @@ func (r *Reader) readNodeContent(ctx context.Context, node Node) ([]byte, error)
362364 if node , isRemote := node .(RemoteNode ); isRemote {
363365 return r .readRemoteNodeContent (ctx , node )
364366 }
365- return node .Read ()
367+
368+ // Read the Taskfile
369+ b , err := node .Read ()
370+ if err != nil {
371+ return nil , err
372+ }
373+
374+ // If the given checksum doesn't match the sum pinned in the Taskfile
375+ checksum := checksum (b )
376+ if ! node .Verify (checksum ) {
377+ return nil , & errors.TaskfileDoesNotMatchChecksum {
378+ URI : node .Location (),
379+ ExpectedChecksum : node .Checksum (),
380+ ActualChecksum : checksum ,
381+ }
382+ }
383+
384+ return b , nil
366385}
367386
368387func (r * Reader ) readRemoteNodeContent (ctx context.Context , node RemoteNode ) ([]byte , error ) {
@@ -427,17 +446,29 @@ func (r *Reader) readRemoteNodeContent(ctx context.Context, node RemoteNode) ([]
427446 }
428447
429448 r .debugf ("found remote file at %q\n " , node .Location ())
449+
450+ // If the given checksum doesn't match the sum pinned in the Taskfile
430451 checksum := checksum (downloadedBytes )
431- prompt := cache .ChecksumPrompt (checksum )
432-
433- // Prompt the user if required
434- if prompt != "" {
435- if err := func () error {
436- r .promptMutex .Lock ()
437- defer r .promptMutex .Unlock ()
438- return r .promptf (prompt , node .Location ())
439- }(); err != nil {
440- return nil , & errors.TaskfileNotTrustedError {URI : node .Location ()}
452+ if ! node .Verify (checksum ) {
453+ return nil , & errors.TaskfileDoesNotMatchChecksum {
454+ URI : node .Location (),
455+ ExpectedChecksum : node .Checksum (),
456+ ActualChecksum : checksum ,
457+ }
458+ }
459+
460+ // If there is no manual checksum pin, run the automatic checks
461+ if node .Checksum () == "" {
462+ // Prompt the user if required
463+ prompt := cache .ChecksumPrompt (checksum )
464+ if prompt != "" {
465+ if err := func () error {
466+ r .promptMutex .Lock ()
467+ defer r .promptMutex .Unlock ()
468+ return r .promptf (prompt , node .Location ())
469+ }(); err != nil {
470+ return nil , & errors.TaskfileNotTrustedError {URI : node .Location ()}
471+ }
441472 }
442473 }
443474
0 commit comments