Code Migration

2 posts

meta2 min readCurated summary

Patch Me If You Can: AI Codemods for Secure-by-Default Android Apps

Updating security-sensitive APIs across a massive mobile codebase is difficult because vulnerable patterns may appear across hundreds of call sites and millions of lines of code. Meta’s Product Security team addresses this through secure-by-default Android frameworks and generative AI that automates migrations to those frameworks. The approach enables security patches to be proposed, validated, and submitted with minimal effort from code owners. ## Secure-by-Default Mobile Frameworks - Meta wraps potentially unsafe Android OS APIs in frameworks designed to make secure implementations the easiest option. - Developers are guided toward safer behavior by default rather than being expected to recognize and avoid every security risk manually. - This strategy helps prevent a single vulnerability class from recurring across Meta’s many mobile applications. ## AI-Assisted Code Migration - Generative AI is used to migrate existing code from unsafe APIs to the new secure frameworks. - The system operates across millions of lines of code and numerous call sites. - It can propose security changes, validate them, and submit patches for review. - This reduces the manual work required from the engineers responsible for each application or codebase. ## Security at Massive Scale - Meta’s scale—thousands of engineers, multiple apps, and billions of users—makes conventional security updates difficult to coordinate. - The initiative combines framework design, automation, and engineering ownership to reduce friction while maintaining validation. - The accompanying Meta Tech Podcast episode features Product Security engineers Alex and Tanu discussing the challenges and lessons from this effort. Meta’s approach demonstrates that large-scale mobile security improvements are most practical when safer APIs and automated migration tools work together, allowing secure changes to spread broadly without requiring every engineer to perform the migration manually.

Read original(opens in new tab)
figma3 min readCurated summary

Inside Figma: a case study on strict null checks | Figma Blog

Figma enabled TypeScript’s `strictNullChecks` incrementally to eliminate null-related bugs without halting product development. The migration addressed more than 4,000 compiler errors across roughly 1,162 files and helped prevent a class of production incidents. Figma concluded that a progressive, allowlist-based rollout was more practical than either stopping all development or fixing errors indefinitely without enforcing the setting. ## What Strict Null Checks Provide - Without `strictNullChecks`, ordinary types such as `Vector` may also contain `null`, making unsafe property access possible. - With the option enabled: - Non-nullable types cannot be assigned `null`. - Nullable values must be explicitly declared, such as `Vector | null`. - TypeScript uses control-flow analysis to narrow types after null checks. - This prevents errors such as accessing `.name` on `undefined`. - The type system also documents important assumptions, such as whether data has been loaded, making code easier to maintain. - Figma’s historical incident data showed that strict null checks could have caught several high-severity production issues before release. ## Why the Migration Was Difficult - Figma adopted TypeScript before strict null checks existed and had accumulated code that did not satisfy the newer rules. - Enabling the option immediately produced more than 4,000 errors across approximately 1,162 frontend TypeScript files. - Fixing one error could expose additional errors. - Meanwhile, the codebase continued growing—from 376,000 to 464,000 lines during the migration—making a strategy that allowed progress to reverse particularly risky. ## Alternatives Figma Rejected ### Stop-the-World Migration - All engineers could have paused product work to fix the type errors. - Figma rejected this because: - The work was only partly parallelizable. - Product development was strategically important. - Coordinating a company-wide effort becomes increasingly difficult as organizations grow. ### Whack-a-Mole Error Fixing - Teams could fix strict-null errors over time while enforcing the checks only in CI. - This minimizes disruption but permits new code to introduce additional errors. - The approach is viable only if errors are fixed faster than they are added. - Figma found a continually moving progress target unattractive, especially given rapid codebase growth. ## Progressive Allowlisting - Figma chose to strict-null-check one file at a time by adding successfully migrated files to an allowlist. - The approach was inspired by the VS Code team’s strict-null migration. - The build compiles the codebase twice: - Once with strict null checks disabled for the general codebase. - Once with strict null checks enabled for files on the allowlist. - This allowed teams to migrate files incrementally while continuing normal development elsewhere. Figma’s experience recommends progressive enforcement for large, actively developed TypeScript codebases: isolate compliant files, enforce the stricter rules there, and expand the allowlist until the entire codebase is migrated.

Read original(opens in new tab)