@@ -107,7 +107,9 @@ filter arguments: *classname, list or None, attributes*
107107
108108sample python client
109109====================
110- ::
110+
111+ This client will work if you turn off the x-requested-with header and
112+ the only CSRF header check you require is the HTTP host header::
111113
112114 >>> import xmlrpclib
113115 >>> roundup_server = xmlrpclib.ServerProxy('http://admin:admin@localhost:8917/demo/xmlrpc', allow_none=True)
@@ -136,3 +138,34 @@ sample python client
136138 []
137139 >>> roundup_server.lookup('user','admin')
138140 '1'
141+
142+ The one below adds Referer and X-Requested-With headers so it can pass
143+ stronger CSRF detection methods. Note if you are using http rather
144+ than https, replace xmlrpclib.SafeTransport with xmlrpclib.Transport::
145+
146+ import xmlrpclib
147+
148+ class SpecialTransport(xmlrpclib.SafeTransport):
149+
150+ def send_content(self, connection, request_body):
151+
152+ connection.putheader("Referer", "https://localhost/demo/")
153+ connection.putheader("Origin", "https://localhost")
154+ connection.putheader("X-Requested-With", "XMLHttpRequest")
155+
156+ connection.putheader("Content-Type", "text/xml")
157+ connection.putheader("Content-Length", str(len(request_body)))
158+ connection.endheaders()
159+ if request_body:
160+ connection.send(request_body)
161+
162+ roundup_server = xmlrpclib.ServerProxy(
163+ 'https://admin:admin@localhost/demo/xmlrpc',
164+ transport=SpecialTransport(),
165+ verbose=False,
166+ allow_none=True)
167+
168+ print roundup_server.schema()
169+ print roundup_server.display('user2', 'username')
170+ print roundup_server.display('issue1', 'status')
171+ print roundup_server.filter('user',['1','2','3'],{'username':'demo'})
0 commit comments