SlideShare a Scribd company logo
開發人員該知道?	 
·•資訊安全觀念	 CIA	 
·•資訊安全策略	 3A	 
·•環境設定與工具	 
·•資安程式開發
Confidentiality	

!

Integrity	

!

Availability
Authentication	

!

Authorization	

!

Accounting
Secure Coding
Guidelines
• Avoid duplication	

• Restrict privileges	

• Establish trust boundaries	

• Minimize the number of permission checks	

• Encapsulate
Denial of Service
• Release resources in all cases	

• "Zip bombs"	

• "Billion laughs attack"	

• "Log bombs"	

• Infinite loops: "Messages poison”	

• Resource limit checks should not suffer from
integer overflow
Confidential Information
• Purge sensitive information from
exceptions	


• Do not log highly sensitive information	

• Consider purging highly sensitive from
memory after use
Injection & Inclusion
• Avoid dynamic SQL	

• SQL Injection	

• XML and HTML generation requires care	

• Cross Site Scripting(XSS)	

• Restrict XML inclusion	

• XML External Entity (XXE)
Accessibility & Extensibility
• Limit the accessibility of classes, interfaces,
methods, and fields.	


• Limit the accessibility of namespace.	

• Isolate unrelated code.	

• Limit the extensibility of classes and methods.	

• Understand how a superclass can affect
subclass behavior.
Accessibility & Extensibility

Reducing the "attack surface" of the code
Input Validation
• Validate inputs	

• 有效值	

• 特殊字元:URL / HTML / XML
Mutability
• Prefer immutability for value types	

• Create copies of mutable output values	

• Make public static fields as constants	

• Do not expose mutable statics
Object Construction
• Avoid exposing constructors of sensitive
classes	


• Prevent the unauthorized construction of
sensitive classes	


• Prevent constructors from calling methods
that can be overridden
Serialization & Deserialization

• Avoid serialization for security-sensitive
classes	


• Guard sensitive data during serialization	

• View deserialization the same as object
construction
Access Control
• Understand how permissions are checked	

• Beware of callback (Lifecycle) methods	

•

Callback methods are generally invoked from the system
with FULL permissions	


• Be careful caching results of potentially
privileged operations
Security	 Coding	 涵蓋了?
·•Authentication	 &	 Authorization	 
·•Session	 &	 State	 management	 
·•Input	 &	 Output	 
·•File	 Handling	 
·•Error	 Handling	 
·•Auditing	 &	 Logging	 
·•Cryptography	 
·•Configuration
Application Logging Tips
使⽤用適當⼯工具
資訊分級
• ERROR 	

• WARN 	

• INFO 	

• DEBUG 	

• TRACE
到底在Log啥?
Debug.WriteLine("Returning orders: {0}", orders);
if(MyLog.isDebugEnabled()){	

MyLog.Debug("It's a secret!”);	

}
避免副作⽤用!
try {	

	

 MyLog.Trace("Id=" + request.getUser().getId() );	

	

 MyLog.Trace("Accesses " + manager.getPage().getUrl().toString());	

} 	

catch(Exception e) {	

}
簡潔描述!
if(message is TextMessage)	

	

 //...	

else	

MyLog.Warn("Unknown message type");
精確調整輸出格式!

時戳
等級 程式名稱 訊息 	

{0:HH:mm:ss} {1}
{2}
{3}
記錄⽅方法參數與回傳值!
public String printDocument(Document doc, Mode mode) {	

MyLog.Debug("Entering printDocument(doc={0}, mode={1})", doc, mode);	

String id = //...	

MyLog.Debug("Leaving printDocument(): {0}", id);	

return id;	

}
記錄例外狀況資訊!
MyLog.Error("IO exception", e);	

throw new MyCustomException(e);
易於解讀!
MyLog.Debug("Request TTL set to: {0} ({1})", new DateTime(ttl), ttl);	

// Request TTL set to: Wed Apr 28 20:14:12 CEST 2010 (1272478452437)	

!

String duration =
DurationFormatUtils.formatDurationWords(durationMillis, true, true);	

MyLog.Info("Importing took: {0}ms ({1})", durationMillis, duration);	

// Importing took: 123456789ms (1 day 10 hours 17 minutes 36 seconds)
Summary

·•Use	 for	 daily	 log	 or	 tracing	 
·•Audience	 
·•Easy	 to	 read	 
·•Easy	 to	 analysis	 
·•Will	 it	 cause	 error?	 
·•System	 performance	 issue
Why Secure Coding Training is Important?

Cost%

Cost%of%fixing%security%flaws%during%different%development%phases%

Phases%
Fixing&bugs&by&releasing&a&patch&costs&60&6mes&more&than&fixing&the&same&bug&during&the&design&stage.&
Source:&h"p://www.auto.tuwien.ac.at0

More Related Content

PPTX
Mnescot controls monitoring
PDF
Secure JAX-RS
PPTX
Dmytro Kochergin - "The OWASP TOP 10 - Typical Attacks on Web Applications an...
PPTX
Hallwaze security snapshot
PDF
Devbeat Conference - Developer First Security
PPTX
Self Defending Applications
PPTX
HTML5 - The Promise & The Peril
PPTX
Security in an Interconnected and Complex World of Software
Mnescot controls monitoring
Secure JAX-RS
Dmytro Kochergin - "The OWASP TOP 10 - Typical Attacks on Web Applications an...
Hallwaze security snapshot
Devbeat Conference - Developer First Security
Self Defending Applications
HTML5 - The Promise & The Peril
Security in an Interconnected and Complex World of Software

Similar to Security coding (20)

PPTX
Code Review Cybersecurity: Comprehensive Guide to Secure Code Evaluation & B...
PPTX
Built-in Security Mindfulness for Software Developers
PDF
Unit2_Cyber Security updated.pdf
PDF
Agile Secure Development
PPTX
Secure practices with dot net services.pptx
PPTX
Week Topic Code Access vs Event Based.pptx
PDF
Dev(Sec)Ops - Architecture for Security and Compliance
PDF
Secure webdev 3.0
PDF
Agile Application Security Enabling Security in a Continuous Delivery Pipelin...
PDF
AppSec How-To: Achieving Security in DevOps
PDF
Building a Secure Software Application: Your Ultimate Guide
PDF
Rails Security
PPTX
PDF
Web application security (eng)
PDF
DevSecOps 實踐與 GitHub 進階安全: 建立安全的開發流程
PPTX
Securing Underprotected APIs - Deja vu Security
PDF
AppSec in an Agile World
PPTX
Unit-I PPT.pptx
PPT
Intro to-ssdl--lone-star-php-2013
PDF
Secure Coding Practices Every Developer Should Know.pdf
Code Review Cybersecurity: Comprehensive Guide to Secure Code Evaluation & B...
Built-in Security Mindfulness for Software Developers
Unit2_Cyber Security updated.pdf
Agile Secure Development
Secure practices with dot net services.pptx
Week Topic Code Access vs Event Based.pptx
Dev(Sec)Ops - Architecture for Security and Compliance
Secure webdev 3.0
Agile Application Security Enabling Security in a Continuous Delivery Pipelin...
AppSec How-To: Achieving Security in DevOps
Building a Secure Software Application: Your Ultimate Guide
Rails Security
Web application security (eng)
DevSecOps 實踐與 GitHub 進階安全: 建立安全的開發流程
Securing Underprotected APIs - Deja vu Security
AppSec in an Agile World
Unit-I PPT.pptx
Intro to-ssdl--lone-star-php-2013
Secure Coding Practices Every Developer Should Know.pdf
Ad

More from BITs Information Technology Consultants Co., Ltd. (10)

Ad

Recently uploaded (20)

PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Empathic Computing: Creating Shared Understanding
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPT
Teaching material agriculture food technology
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Encapsulation theory and applications.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Approach and Philosophy of On baking technology
PDF
Electronic commerce courselecture one. Pdf
PDF
Machine learning based COVID-19 study performance prediction
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Mobile App Security Testing_ A Comprehensive Guide.pdf
Big Data Technologies - Introduction.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Empathic Computing: Creating Shared Understanding
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Teaching material agriculture food technology
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
The Rise and Fall of 3GPP – Time for a Sabbatical?
Encapsulation theory and applications.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Approach and Philosophy of On baking technology
Electronic commerce courselecture one. Pdf
Machine learning based COVID-19 study performance prediction
The AUB Centre for AI in Media Proposal.docx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Encapsulation_ Review paper, used for researhc scholars
NewMind AI Weekly Chronicles - August'25 Week I
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...

Security coding