데이터베이스 보안

Table of Contents

최근에, 데이터베이스는 웹사이트에 다양한 동적 내용을 제공하기 위한 모든 웹 기반 어플리케이션의 기본 구성 요소입니다. 매우 민감하거나 비밀스러운 정보가 데이터베이스에 저장될 수 있으므로, 데이터베이스의 보호에 대하여 심각하게 고려해야 합니다.

어떠한 정보를 가져오거나 넣으려면 데이터베이스에 접속하고, 적합한 질의를 전송하고, 결과를 가져오고, 접속을 닫습니다. 최근에, 이 작업에 가장 많이 사용하는 질의 언어는 구조적 질의 언어(SQL)입니다. 어떻게 공격자가 SQL 질의를 건들일 수 있는지 확인하십시오.

예측할 수 있듯이, PHP는 데이터베이스 자체를 보호할 수 없습니다. 다음 섹션은 PHP 스크립트에서 데이터베이스에 접근하고 조작하는 방법에 대한 매우 기초적인 설명입니다.

간단한 규칙을 명심하십시오: 철저하게 방어. 더 많은 위치에서 데이터베이스의 보호를 증가하기 위한 작업을 한다면, 공격자가 저장된 정보를 빼낼 수 있는 성공 가능성이 줄어듭니다. 데이터베이스 스키마와 어플리케이션 처리의 좋은 디자인은 최대한의 공포와 함께 하는 것입니다.

add a note add a note

User Contributed Notes 4 notes

up
-15
x12code at yahoo dot com
16 years ago
About offloading business logic to views and queries facilitated by the database engine, I seek to avoid this as much as possible, and only do so when such would drastically improve efficiency and user response time.

For instance, where I am there is database staff and application staff. Trying to do analysis on existent applications can easily become a snipe hunt.

The database should be kept discreet as much as possible from the application, such that any database or database provider can easily be substituted with a minimum of cognitive effort on the part of the one setting up a new database. If functionality has been offloaded to the database, additional testing is required to make sure triggers and views were done correctly, again, and that they work right.

Also, keeping all business logic with the application allows all functionality and documentation to be readable in one place, which is invaluable when doing subsequent analysis on an existing application. The worst thing is to have functionality scattered here and there.

Keeping everything with the application means one group of people is responsible, as in my case, application staff. Fewer requests go back and forth. Remember, anytime someone else is brought into the picture, such as asking a DBA to create a view or trigger for you, that DBA must take responsibility over his or her work, with whatever requirements, causing more bureaucracy and administrative complexity.
up
-20
Chris Travers
11 years ago
Regarding where to put logic, it's really best not to be dogmatic about this.  Putting logic in the db can have some security advantages but it has other security gotchas (for example, SQL injection inside a stored procedure may be possible in some environments).  Similarly it can have some portability advantages and disadvantages.

The real question is that you want to ask what you want to be portable.  If you put it in the db, it becomes easier to integrate programs written in different development environments with a minimum of security gotchas.  If you put it in the application, then you have to create the interfaces on that level in middleware.  Both approaches are doable.  On the other hand if you are writing software you want to be deployable in MS SQL shops and Oracle shops, then you have to write portable SQL (avoiding gotchas) and put the logic in the application.

When we started rewriting the LedgerSMB codebase, we decided to move logic into the db because this would make it easier to retrofit security onto a very insecure codebase (by not trusting the application), and because we wanted to support languages other than Perl.  A few years later this is bearing fruit and indeed I am reading the manual because I am writing integration libraries in PHP.  I am not much of a PHP guy (I haven't programmed PHP since PHP 4.x) but I can write modules that let folks write code to interface securely with LedgerSMB's database logic.  You can think of the stored procedures as being named queries which are shared between applications, or as API's to the database.  But again, this approach is not universally applicable.

If portability between db's is not a major requirement, then I think the best approach is to do as much as possible in SQL queries and put those in the database.  A couple hundred lines of SQL can replace a couple thousand lines in Perl or PHP, and is fundamentally easier to debug.  Of course that won't work for everyone.
up
-39
Anonymous
18 years ago
you can also chamge CHMOD for some file containing "user names" or "passwords"
up
-53
Dave Martin
16 years ago
The posting below is at the very best extremely POV.

There is no more reason to assume you would want to change database vendor than there is to assume you might want to port your php code to Java for example. In either case, its going to be a matter of luck where your business rules sit.

Even if your business rules sit in your application, SQL is NOT portable. Oracle outer joins and pivot queries for example, can look completely different to those in other vendors software (particularly from 8i or lower). This fact alone means that changing your DB vendor requires work on your business rules either in the database or in the application.

Having your rules in the database and keeping the sql in application simple, will at least keep the work in the database if you need to change DB vendor. If you have the rules in the PHP, you'll have to change both.
To Top