Security sandbox violation
Nhờ admin xem giùm:
- Upload ảnh xong không thấy hiện ra gì?
Khi viết flash application, bạn có thể gặp lỗi sau:
Error #2048: Security sandbox violation:…swf cannot load data from…
Với flash phiên bản mới hiện nay, lỗi trên có thể gặp ngay cả khi flash lấy dữ liệu từ cùng domain (vd: trường hợp flash lấy dữ liệu qua socket).
Định nghĩa file cross-domain policy file của adobe:
workflow
Như vậy flash từ domain a.com muốn lấy dữ liệu của b.com thì phải được b.com cho phép. Thông thường file cross-domain-policy.xml được đặt ở root của b.com.
Policy file xác định loại dữ liệu, xác định các domain được phép truy cập.
Trường hợp socket server hosts policy file: Trong trường hợp flash a.com lấy dữ liệu qua socket với server b.com, mỗi khi lấy dữ liệu, flash sẽ gửi một single node XML document chứa
Dưới đây là một mẫu code policy server nhặt được trong dự án game tá lả (có vấn đề đâu không chịu tránh nhiệm , có gì thì cứ đè đại ka ra ) )
Viết bằng perl:
#!/usr/bin/perl
#
# policyd.pl
# Simple socket policy file server
#
# Usage: policyd.pl [--port=N] –file=FILE
# Logs to stdout
#use strict;
use Socket;my $NULLBYTE = pack( ‘c’, 0 );
my $port = 843;
my $filePath;
my $content;### READ ARGS
while ( my $arg = shift @ARGV )
{
if ( $arg =~ m/^–port=(\d+)$/ )
{
$port = $1;
}
elsif ( $arg =~ m/^–file=(.*)/ )
{
$filePath = $1;
}
}unless ( $filePath )
{
die “Usage: policyd.pl [--port=N] –file=FILE\n”;
}### READ FILE
-f $filePath or die “No such file: ‘$filePath’\n”;
-s $filePath < 10_000 or die “File probably too large to be a policy file: ‘$filePath’\n”;local $/ = undef;
open POLICYFILE, “<$filePath” or die “Can’t open ‘$filePath’: $!\n”;
$content =;
close POLICYFILE;$content =~ m/cross-domain-policy/ or die “Not a valid policy file: ‘$filePath’\n”;
### BEGIN LISTENING
socket( LISTENSOCK, PF_INET, SOCK_STREAM, getprotobyname( ‘tcp’ ) ) or die “socket() error: $!”;
setsockopt( LISTENSOCK, SOL_SOCKET, SO_REUSEADDR, pack( ‘l’, 1 ) ) or die “setsockopt() error: $!”;
bind( LISTENSOCK, sockaddr_in( $port, INADDR_ANY ) ) or die “bind() error: $!”;
listen( LISTENSOCK, SOMAXCONN ) or die “listen() error: $!”;print STDOUT “\nListening on port $port\n\n”;
### HANDLE CONNECTIONS
while ( my $clientAddr = accept( CONNSOCK, LISTENSOCK ) )
{
my ( $clientPort, $clientIp ) = sockaddr_in( $clientAddr );
my $clientIpStr = inet_ntoa( $clientIp );
print STDOUT “Connection from $clientIpStr:$clientPort\n”;local $/ = $NULLBYTE;
my $request =;
chomp $request;if ( $request eq ‘
’ )
{
print STDOUT “Valid request received\n”;
}
else
{
print STDOUT “Unrecognized request: $request\n\n”;
close CONNSOCK;
next;
}print CONNSOCK $content;
print CONNSOCK $NULLBYTE;
close CONNSOCK;print STDOUT “Sent policy file\n\n”;
}# End of file.
Cái này bằng python:
#!/usr/bin/env python
#
# flashpolicyd.py
# Simple socket policy file server for Flash
#
# Usage: flashpolicyd.py [--port=N] –file=FILE
#
# Logs to stderr
# Requires Python 2.5 or laterfrom __future__ import with_statement
import sys
import optparse
import socket
import thread
import exceptions
import contextlibVERSION = 0.1
class policy_server(object):
def __init__(self, port, path):
self.port = port
self.path = path
self.policy = self.read_policy(path)
self.log(‘Listening on port %d\n’ % port)
try:
self.sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
except AttributeError:
# AttributeError catches Python built without IPv6
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error:
# socket.error catches OS with IPv6 disabled
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.sock.bind((”, port))
self.sock.listen(5)
def read_policy(self, path):
with file(path, ‘rb’) as f:
policy = f.read(10001)
if len(policy) > 10000:
raise exceptions.RuntimeError(‘File probably too large to be a policy file’,
path)
if ‘cross-domain-policy’ not in policy:
raise exceptions.RuntimeError(‘Not a valid policy file’,
path)
return policy
def run(self):
try:
while True:
thread.start_new_thread(self.handle, self.sock.accept())
except socket.error, e:
self.log(‘Error accepting connection: %s’ % (e[1],))
def handle(self, conn, addr):
addrstr = ‘%s:%s’ % (addr[0],addr[1])
try:
self.log(‘Connection from %s’ % (addrstr,))
with contextlib.closing(conn):
# It’s possible that we won’t get the entire request in
# a single recv, but very unlikely.
request = conn.recv(1024).strip()
if request != ‘\0′:
self.log(‘Unrecognized request from %s: %s’ % (addrstr, request))
return
self.log(‘Valid request received from %s’ % (addrstr,))
conn.sendall(self.policy)
self.log(‘Sent policy file to %s’ % (addrstr,))
except socket.error, e:
self.log(‘Error handling connection from %s: %s’ % (addrstr, e[1]))
except Exception, e:
self.log(‘Error handling connection from %s: %s’ % (addrstr, e[1]))
def log(self, str):
print >>sys.stderr, strdef main():
parser = optparse.OptionParser(usage = ‘%prog [--port=PORT] –file=FILE’,
version=’%prog ‘ + str(VERSION))
parser.add_option(‘-p’, ‘–port’, dest=’port’, type=int, default=843,
help=’listen on port PORT’, metavar=’PORT’)
parser.add_option(‘-f’, ‘–file’, dest=’path’,
help=’server policy file FILE’, metavar=’FILE’)
opts, args = parser.parse_args()
if args:
parser.error(‘No arguments are needed. See help.’)
if not opts.path:
parser.error(‘File must be specified. See help.’)try:
policy_server(opts.port, opts.path).run()
except Exception, e:
print >> sys.stderr, e
sys.exit(1)
except KeyboardInterrupt:
passif __name__ == ‘__main__’:
main()
Một ví dụ về policy file (không nên dùng )
(i-php.net)
Các tin khác cùng chuyên mục
- Kỹ thuật lập trình HTML/CSS mới nhất 2020 - 04
- Funny web2.0
- Giải thử vài câu đề thi tốt nghiệp ptth môn toán
- MỘT NGÀY PHẢI KHÁC MỌI NGÀY
- Level 1 - Lập trình hướng đối tượng (P2)
- Level 1 - Lập trình hướng đối tượng (P1)
- PHP 5.3, Phần 3: Không gian tên
- PHP 5.3, Phần 2: Bao đóng và các hàm lambda
- PHP 5.3, Phần 1: Các thay đổi về giao diện đối tượng
- Tăng tốc độ xử lý CSDL MySQL
Liên kết
Tin được quan tâm nhất
- Ant Group của Jack Ma hé lộ bước đi đầu tiên...
- Ô tô giao hàng tự lái sẽ bắt đầu hoạt...
- Clip cô giáo phạt học sinh tự ném vỡ...
- Tiền điện tử lớn thứ ba thế giới Ripple...
- Joe Biden kêu gọi hiện đại hóa hệ thống...
- Viettel khai trương nền tảng Hồ sơ sức khỏe...
- Các hãng di động nên ngừng cãi nhau về việc...
- Công nghệ AI của Alibaba và Tân Hoa Xã: Đối...
- Một năm đáng thất vọng của YouTube trên toàn...
- EVN lần đầu diễn tập an toàn thông tin mạng...
- Đây là chiếc iPhone được mua nhiều nhất...
- Bộ Tài chính ra quy chế mới về quản lý, sử...
- Cập nhật nhãn mới giúp người tiêu dùng...
- Kiếm tiền từ 5G: Thách thức lớn nhất của...
- "Hô biến" iPhone thành cục đá: Có thể bị...
- Phí trước bạ ô tô không gia hạn giảm, sẽ...
- Tại sao Apple chế tạo ô tô?
- Viettel cung cấp dịch vụ 5G tại thành phố...
- Đội KingTigerPrawn của Hàn Quốc giành giải...
- Thứ trưởng Phan Tâm: “Triển khai hạ tầng 5G...
- Nhiều mẫu iPhone chính hãng đang khan hàng tại...
- Mỹ quy định drone cần có ID, trang bị đèn ban...
- Trung Quốc điều tra Alibaba: Bài học cho Jack Ma...
- Chuyên gia dự báo 5 xu hướng tấn công mạng...
- Apple MagSafe vẫn còn rất nửa vời
- Các tỉnh cuối cùng đã ngừng phát sóng...
- 55/63 tỉnh thành sử dụng Zalo trong cải cách...
- Headline: CR7: “Mong muốn của tôi là luôn...
- Samsung dự kiến xuất xưởng dưới 300 triệu...
- Vì sao Trung Quốc ‘sờ gáy’ Alibaba?
- Những smartphone được người Việt mua nhiều...
- Vì sao mua hàng ở sàn TMĐT Mỹ không cần...
- Đằng sau bức ảnh động viên Đà Nẵng chiến...
- VNPT cung cấp MyTV Box 2020 - Tính năng nâng cấp...
- Clip hành động ghê tởm của shipper trước khi...
- Các đội thi chung kết WhiteHat Grand Prix 6 phát...