Introduction
SuiteScript gives developers immense power to automate and extend NetSuite—but with that power comes responsibility.
Poorly secured scripts can expose sensitive financial data, allow unintended record access, or create compliance risks.
In this post, we’ll cover the most important security techniques for any NetSuite developer or administrator.
🔐 1. Principle of Least Privilege
Always grant only the access necessary for a script to function.
- Assign dedicated script deployment roles (e.g., “Script Integration Role”).
- Avoid running under Administrator unless absolutely required.
- Use restrictions by subsidiary, department, or class where applicable.
✅ Tip: When using RESTlets or Suitelets, restrict role access to specific internal or external users only.
🧾 2. Validate All Inputs
Never trust user input—even if the source is an internal record.
Example: validating external parameters in a Suitelet or RESTlet
const invoiceId = parseInt(context.request.parameters.id);
if (isNaN(invoiceId)) {
throw Error('Invalid Invoice ID');
}
✅ Check for:
- Missing or null values.
- Incorrect data types.
- SQL or script injection attempts in text fields.
🌐 3. Secure External Integrations
When integrating with systems like Shopify, Salesforce, or PayPal:
- Use script parameters to store API credentials.
- Never hardcode tokens or passwords in code.
- Use NetSuite’s Secret Management or Credential fields (Setup > Company > Credentials > Manage Credentials).
- Use HTTPS and validate response signatures.
Example:
const headers = {
'Authorization': 'Bearer ' + runtime.getCurrentScript().getParameter({name:'custscript_paypal_token'}),
'Content-Type': 'application/json'
};
🔍 4. Restrict Script Deployments
Limit who can execute your scripts:
Script Type | Recommended Access Control |
---|---|
User Event | Deploy on specific forms or roles only |
Suitelet | Restrict by role or add token-based auth |
RESTlet | Require token-based or OAuth 2.0 authentication |
Map/Reduce | Internal use only; no external execution |
✅ Add condition checks like:
const user = runtime.getCurrentUser();
if (!user.role || user.role !== 3) throw 'Access Denied';
🧰 5. Sanitize Data Before Saving
If your script manipulates record data, ensure values are sanitized and validated before submit:
const email = newRec.getValue('email');
if (email && !email.match(/^[^\s@]+@[^\s@]+\.[^\s@]+$/)) {
throw Error('Invalid email format');
}
🧠 6. Avoid Exposing Sensitive Fields
When building RESTlets or Suitelets that return data:
❌ Don’t expose fields like:
creditcardnumber
,bankaccount
,ssn
,password
✅ Do return only necessary info:
return { id: inv.id, total: inv.total, date: inv.trandate };
⚙️ 7. Use Governance and Logging Wisely
Security also means resilience.
- Log only essential details—avoid storing personal or financial info in logs.
- Limit logs to
log.audit
orlog.debug
with sanitized values. - Handle exceptions gracefully using
try/catch
to avoid partial saves.
🔄 8. Implement Role-Based Conditions in Scripts
if (runtime.getCurrentUser().role !== 1004) {
throw Error('You are not authorized to update this record.');
}
✅ Create a custom “Integration Role” with minimal access and use it for APIs.
📊 9. Secure RESTlets with Token-Based Authentication (TBA)
Always use TBA instead of username/password integrations.
Steps:
- Enable Token-Based Authentication in Setup > Company > Enable Features.
- Create Integration Record for your script.
- Assign Access Tokens to the integration role.
- Use these tokens in API headers:
Authorization: NLAuth nlauth_account=XXXX,nlauth_consumer_key=XXXX,nlauth_token=XXXX
🧩 10. Keep Scripts Versioned and Reviewed
- Use SDF projects and Git version control.
- Perform code reviews to detect potential vulnerabilities.
- Maintain a changelog with who deployed what and when.
✅ Security Checklist
Category | Check |
---|---|
Access | Script role has only required permissions |
Data Validation | Inputs sanitized, required fields validated |
Credentials | Tokens stored securely, not in code |
Logging | No sensitive data in logs |
Authentication | TBA or OAuth 2.0 used |
Error Handling | Try/Catch applied to all record operations |
Conclusion
Security isn’t just an IT concern — it’s a core part of SuiteScript development.
By validating inputs, controlling roles, securing credentials, and monitoring governance, you can ensure your scripts are safe, compliant, and reliable.
Strong security means fewer breaches, better client trust, and smoother audits.
Discover more from The NetSuite Pro
Subscribe to get the latest posts sent to your email.
Leave a Reply