crossdomain.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package webapi
  2. import (
  3. "log/slog"
  4. "net/http"
  5. )
  6. // crossDomainPolicy grants any SWF access to this API.
  7. //
  8. // The permission is as broad as the CORS headers the same endpoints already
  9. // send, and every method still needs an aimsid the policy does not hand out.
  10. //
  11. // secure="false" is required because the client reaches these hosts over both
  12. // HTTP and HTTPS; a policy served over HTTPS otherwise permits HTTPS callers
  13. // only, which breaks the plaintext listener.
  14. const crossDomainPolicy = `<?xml version="1.0"?>
  15. <!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
  16. <cross-domain-policy>
  17. <site-control permitted-cross-domain-policies="master-only"/>
  18. <allow-access-from domain="*" secure="false"/>
  19. <allow-http-request-headers-from domain="*" headers="*" secure="false"/>
  20. </cross-domain-policy>
  21. `
  22. // CrossDomainPolicyHandler serves the Flash cross-domain policy.
  23. type CrossDomainPolicyHandler struct {
  24. Logger *slog.Logger
  25. }
  26. // ServeHTTP answers GET /crossdomain.xml.
  27. //
  28. // Flash Player fetches this from the root of every host a SWF loads from before
  29. // it will issue the request, and refuses the request outright when it is
  30. // missing. The Web API is reached cross-origin from the host serving the client,
  31. // so without this the whole API is unreachable to a real Flash Player. Ruffle
  32. // does not enforce the policy, which is why this only surfaces on the plugin.
  33. func (h *CrossDomainPolicyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
  34. // Flash rejects a master policy file that is not served as text or XML.
  35. w.Header().Set("Content-Type", "text/x-cross-domain-policy")
  36. w.Header().Set("Cache-Control", "public, max-age=3600")
  37. _, _ = w.Write([]byte(crossDomainPolicy))
  38. }