File tree Expand file tree Collapse file tree 1 file changed +26
-5
lines changed
crates/aptos-sdk-macros/src Expand file tree Collapse file tree 1 file changed +26
-5
lines changed Original file line number Diff line number Diff line change @@ -116,11 +116,32 @@ pub fn aptos_contract_file(input: TokenStream) -> TokenStream {
116116 let file_path = manifest_path. join ( & input. path ) ;
117117
118118 // SECURITY: Verify the resolved path is under CARGO_MANIFEST_DIR to prevent
119- // path traversal attacks (e.g., "../../../../etc/passwd")
120- if let ( Ok ( canonical_manifest) , Ok ( canonical_file) ) =
121- ( manifest_path. canonicalize ( ) , file_path. canonicalize ( ) )
122- && !canonical_file. starts_with ( & canonical_manifest)
123- {
119+ // path traversal attacks (e.g., "../../../../etc/passwd").
120+ // Canonicalization failures are treated as errors to ensure this check
121+ // is never silently skipped.
122+ let canonical_manifest = match manifest_path. canonicalize ( ) {
123+ Ok ( p) => p,
124+ Err ( e) => {
125+ return syn:: Error :: new (
126+ input. name . span ( ) ,
127+ format ! ( "Failed to resolve project directory: {e}" ) ,
128+ )
129+ . to_compile_error ( )
130+ . into ( ) ;
131+ }
132+ } ;
133+ let canonical_file = match file_path. canonicalize ( ) {
134+ Ok ( p) => p,
135+ Err ( e) => {
136+ return syn:: Error :: new (
137+ input. name . span ( ) ,
138+ format ! ( "Failed to resolve ABI file path '{}': {e}" , input. path) ,
139+ )
140+ . to_compile_error ( )
141+ . into ( ) ;
142+ }
143+ } ;
144+ if !canonical_file. starts_with ( & canonical_manifest) {
124145 return syn:: Error :: new (
125146 input. name . span ( ) ,
126147 format ! (
You can’t perform that action at this time.
0 commit comments