Level: AdvancedDevOps and Packaging

AppExchange Security Review and Managed Packages

Updated 9 min read
AppExchange Security Review featured image showing a package being checked before listing

The AppExchange Security Review is the check every package passes before it can be listed for other companies to install. It is not a formality. Reviewers run a scan, read your answers about how the app handles data, and fail submissions that leave a real hole open.

Most first submissions to the AppExchange Security Review fail on something small. A single unescaped merge field in a Visualforce page, a query without sharing, or a secret left in a class. All of them are cheap to fix before you submit and expensive to discover after.

AppExchange Security Review diagram showing build, test, submit and listing steps

Caption: The review comes after the package already installs cleanly in a fresh org, not before.

Managed, Unlocked and Unmanaged Packages

TypeWhat it is for
ManagedA commercial app, with hidden code and enforced upgrades
UnlockedYour own org or a client project, with visible code
UnmanagedA one time template, with no upgrade path at all

Only a managed package can be listed on the AppExchange, and only a managed package goes through the AppExchange Security Review. The others are deployment tools rather than products.

A managed package needs a namespace, registered once in a Developer Edition org, and that namespace prefixes every component you build.

sf package create --name CoursePro --package-type Managed --path force-app
sf package version create --package CoursePro --installation-key-bypass --wait 20
sf package install --package 04t... --target-org testOrg --wait 20
sf package version promote --package CoursePro@1.0.0-1
StepWhy it exists
Create the packageRegisters the package in your Dev Hub
Create a versionBuilds a beta you can install
Install in a clean orgProves it works from nothing
PromoteMarks the version as released, which is what you submit

That clean org step is not optional in practice, and it comes before the AppExchange Security Review. A package that works in the org it was built in can still fail on install, because that org has fields and permissions the package does not carry.

What the AppExchange Security Review Checks

The AppExchange Security Review scan looks for a short list of real problems, and almost every failure is one of these.

FindingWhat it means
SOQL injectionA query built from user input without escaping
Cross site scriptingOutput rendered without escaping
Missing CRUD and FLS checksReading or writing fields the user cannot access
Sharing not enforcedA class without the sharing keyword
Hard coded secretsA key, token or password in code or metadata
Insecure calloutsHTTP rather than HTTPS, or an unverified endpoint
Unescaped merge fieldsA Visualforce expression without escaping

The Three Fixes That Clear Most Findings

// Sharing enforced at the class level
public with sharing class CourseService {

    // Field and object access enforced by user mode
    public List<Course__c> search(String term) {
        String like = '%' + String.escapeSingleQuotes(term) + '%';
        return [
            SELECT Id, Name, Fee__c
            FROM Course__c
            WHERE Name LIKE :like
            WITH USER_MODE
            LIMIT 50
        ];
    }
}

Three things in that short class answer most of the AppExchange Security Review scan. The sharing keyword, the bind variable rather than string concatenation, and user mode on the query. The posts on secure coding and CRUD and FLS cover each in depth.

Preparing a Submission

Running the AppExchange Security Review scan yourself first is the single biggest time saver. Salesforce provides a scanner, and Code Analyzer catches a similar set of issues locally.

  1. Run Code Analyzer over the whole package and fix everything it reports
  2. Submit the code to the Salesforce scanner and read the full report
  3. Fix every finding, and write a short note for anything you believe is a false positive
  4. Install the promoted version in a brand new org and run through the app
  5. Complete the security questionnaires honestly, including outside services you call
  6. Submit, and expect questions
Document asked forWhat it covers
Security questionnaireHow the app handles data and authentication
Architecture descriptionWhat runs where, and which services are involved
Test credentialsA working login so reviewers can use the app
Scan resultsThe report, with your notes on anything disputed

Test credentials catch people out in the AppExchange Security Review. Reviewers need a way into your app with sample data in place, and a submission without a working path through the app comes straight back.

Managed or Unlocked

AppExchange Security Review comparison of managed and unlocked packages

Caption: The listing is the deciding factor, since only a managed package can be sold on the AppExchange.

SituationPick
An app you will list and sellManaged
Your own org, split into packagesUnlocked
A consulting deliverable for one clientUnlocked
Code you must keep hiddenManaged
Something you may need to patch in a customer orgUnlocked
A sample app or templateUnmanaged

The hidden code row matters commercially. In a managed package, customers cannot read your Apex, and upgrades are controlled by you. With an unlocked package, customers can see everything and change it, which is fine for internal work and rarely acceptable for a product.

A Real AppExchange Security Review Example

The AppExchange Security Review failed us once. Bright Path Tutors built a course catalogue app and submitted it for listing. The first submission failed.

FindingWhere it came from
Unescaped merge fieldOne old Visualforce page kept for printing
Missing FLS on two fieldsA method written before user mode existed
A test API key in a classLeft over from development
No sharing keyword on a utility classNobody had noticed it
ActionResult
Ran Code Analyzer over the packageFound three of the four issues locally
Moved the key to a protected custom settingFinding cleared
Rewrote the two methods with user modeFinding cleared
Replaced the Visualforce page with an LWCFinding cleared
MeasureFirst attemptSecond attempt
Findings returned by the review40
Weeks from submission to listingFailed, restarted3
Time spent fixing2 days

Running the analyser locally would have found three of the four before the first submission. That is the whole lesson of the exercise.

Keeping a Package Reviewable

  • Register the namespace early, since it cannot be changed
  • Never put a secret in code, a static resource or a custom label
  • Use protected custom settings or custom metadata for configuration
  • Add the sharing keyword to every class as you write it
  • Query in user mode by default and justify any exception in a comment
  • Run Code Analyzer in your pipeline so findings appear on every pull request
  • Install each promoted version in a fresh org before you submit anything

The pipeline step is what keeps a package ready for the AppExchange Security Review over years. A finding caught on a pull request costs ten minutes, and the same finding caught at review costs a submission cycle. The post on CI and CD covers wiring it in.

Common Mistakes with the AppExchange Security Review

MistakeWhat happensFix
Submitting without running the scan firstA failed cycle on findings you could have fixedRun Code Analyzer and the scanner first
A secret left in codeAn automatic failureMove it to a protected setting
Classes without the sharing keywordMultiple findingsAdd it as you write each class
Old Visualforce pages left in the packageEscaping findingsRemove or rewrite them
No working test credentialsThe submission is returnedProvide a login with sample data
Testing only in the development orgInstall failuresInstall in a fresh org every time
Disputing findings with no explanationDelays and more questionsWrite a short note per disputed item

Best Practices for the AppExchange Security Review

  • Treat the scan as a build step rather than a gate at the end
  • Write every class with the sharing keyword and user mode queries from the start
  • Keep configuration in protected custom settings or custom metadata
  • Remove code you no longer ship, since it is still reviewed
  • Document every outside service the app calls before you are asked
  • Give reviewers a working login and data they can act on
  • Promote a version and install it clean before submitting
  • Budget time for a round of questions, because it is normal

Most Asked AppExchange Security Review Interview Questions

Q1: Which package type can be listed on the AppExchange?

A managed package.

Q2: What is an unlocked package for?

Your own org or a client project, where the code can be visible and changed.

Q3: What is an unmanaged package for?

A one time template, with no upgrade path.

Q4: Does a managed package need a namespace?

Yes, registered once, and it cannot be changed afterwards.

Q5: Can customers read Apex in a managed package?

No, which is one of the main commercial reasons to use one.

Q6: What does the review consist of?

An automated scan, questionnaires about data handling, and a hands on check by reviewers.

Q7: Name four findings the scan commonly reports.

SOQL injection, cross site scripting, missing CRUD and FLS checks, and sharing not enforced.

Q8: Which three code habits clear most findings?

The sharing keyword on classes, bind variables instead of concatenation, and user mode queries.

Q9: How do you avoid a SOQL injection finding?

Use bind variables, and escape single quotes when dynamic SOQL is unavoidable.

Q10: Where should an API key live?

In a protected custom setting, a named credential or custom metadata, never in code.

Q11: Why do old Visualforce pages cause problems?

Unescaped merge fields are a common escaping finding, and the pages are still reviewed.

Q12: What should you run before submitting?

Code Analyzer locally, then the Salesforce scanner, fixing everything both report.

Q13: What do you do about a false positive?

Keep it, and write a short note explaining why it is not an issue.

Q14: Why install in a brand new org?

Because the development org has components the package does not carry, which hides install failures.

Q15: What does promoting a package version mean?

Marking it as released, which is the state a submitted version must be in.

Q16: What do reviewers need from you besides code?

Questionnaire answers, an architecture description and working test credentials with sample data.

Q17: Why are test credentials so important?

Without a usable path through the app, reviewers cannot assess it and the submission is returned.

Q18: Do you have to declare outside services the app calls?

Yes. Where data goes is one of the main things the review covers.

Q19: How long does a review take?

Expect weeks rather than days, plus time for a round of questions.

Q20: What happens if the review fails?

You fix the findings and resubmit, which costs a cycle, so prepare properly first.

Q21: Is there a review for every new version?

Significant changes are reviewed again, so keep the package clean rather than cleaning it once.

Q22: How do you keep a package clean over years?

Run the analyser on every pull request so findings appear while the code is being written.

Q23: Scenario: the app works in your org and fails on install elsewhere. Why?

A dependency that lives in your org and is not part of the package.

Q24: Scenario: the scan flags a utility class you believe is safe. What now?

Fix it if you can, and otherwise explain clearly why it is safe.

Q25: Scenario: a key is only used in a sandbox. Is it acceptable in code?

No. A secret in code fails regardless of which environment it points at.

Q26: Scenario: you need to patch a customer org urgently. Which package type helps?

An unlocked package is more flexible, though a product normally stays managed and ships a patch version.

Q27: Can an unlocked package be sold?

Not through the AppExchange, since listing requires a managed package.

Q28: What is the cheapest way to shorten the review?

Submit with zero findings and complete answers, so there is nothing to go back and forth about.

Q29: What single habit prevents most failures?

Write every class with sharing and user mode from the first line, rather than fixing it later.

Official Resources

What Is Next

Next, read Scratch Org Definition Files and Org Shape Explained.