T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/batch_translate.py:5
- Finding
- Hardcoded paid third-party batch operations execute during module import<![CDATA[ ## Vulnerability Details **File Location**: `scripts/batch_translate.py:5-46` **Vulnerability Type**: Import-time network side effects and uncontrolled paid API consumption **Risk Level**: Medium ### Vulnerable Code ```python from translate_images import translate_image urls = [ 'https://cbu01.alicdn.com/img/ibank/O1CN0109gRVx1zPrBVAmA6p_!!1741586707-0-cib.jpg', 'https://cbu01.alicdn.com/img/ibank/O1CN01K6soO11zPrSIDwxDA_!!1741586707-0-cib.jpg', 'https://cbu01.alicdn.com/img/ibank/O1CN01FPl3Ww1zPrBZrq6Qt_!!1741586707-0-cib.jpg', 'https://cbu01.alicdn.com/img/ibank/O1CN01Fo2kfn1zPrSDKGyfp_!!1741586707-0-cib.jpg', 'https://cbu01.alicdn.com/img/ibank/O1CN01mn8R421zPrBZrpMgp_!!1741586707-0-cib.jpg', 'https://cbu01.alicdn.com/img/ibank/O1CN0128EvSg1zPrBTQA6h4_!!1741586707-0-cib.jpg', 'https://cbu01.alicdn.com/img/ibank/O1CN01rSlKS41zPrBOldjcv_!!1741586707-0-cib.jpg', 'https://cbu01.alicdn.com/img/ibank/O1CN01NtcwD91zPrBXrFHQA_!!1741586707-0-cib.jpg', 'https://cbu01.alicdn.com/img/ibank/O1CN01YDv2CS1zPrBR0gXFI_!!1741586707-0-cib.jpg', 'https://cbu01.alicdn.com/img/ibank/O1CN01FXDAa91zPrBTIuEYo_!!1741586707-0-cib.jpg', 'https://cbu01.alicdn.com/img/ibank/O1CN013hqQWq1zPrGIuflsk_!!1741586707-0-cib.jpg', 'https://cbu01.alicdn.com/img/ibank/O1CN01UNFELq1zPrBbtYLSc_!!1741586707-0-cib.jpg', 'https://cbu01.alicdn.com/img/ibank/O1CN01utZt1WPrRZQcrQH_!!1741586707-0-cib.jpg', 'https://cbu01.alicdn.com/img/ibank/O1CN01XT6mBF1EPbJJqGnya_!!2208893230344-0-cib.jpg', 'https://cbu01.alicdn.com/img/ibank/O1CN01yLeygD1EPbJOlW87Z_!!2208893230344-0-cib.jpg', 'https://cbu01.alicdn.com/img/ibank/O1CN0127eQmd1EPbJQWO5e4_!!2208893230344-0-cib.jpg', 'https://cbu01.alicdn.com/img/ibank/O1CN01pUTHHG1EPbJREDKSL_!!2208893230344-0-cib.jpg', 'https://cbu01.alicdn.com/img/ibank/O1CN01tCd6TV1EPbJJqLu8a_!!2208893230344-0-cib.jpg', 'https://cbu01.alicdn.com/img/ibank/O1CN01wEiMEP1EPbJPqhUSP_!!2208893230344-0-cib.j ...[truncated 3211 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Move all operational logic into an explicit `main()` function and protect it with: ```python if __name__ == "__main__": main() ``` 2. Remove hardcoded production image URLs. Accept URLs explicitly through validated command-line arguments, standard input, or a caller-provided product-data file. 3. Require explicit confirmation before initiating a large or paid translation batch, and display the number of requests that will be made. 4. Enforce a reasonable maximum batch size and provide rate limiting or quota controls. 5. Validate accepted URLs, require HTTPS, and consider an allowlist of expected image-host domains. 6. Write output under the documented `tmp/` directory using a caller-selected or collision-resistant filename. 7. Refuse to overwrite an existing output file unless the caller explicitly enables replacement. 8. Keep the module free of network and filesystem side effects during import so it can be safely inspected, tested, and reused. ]]>
